XML files, how to create and maintain them?


Author
Message
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
I want to work with XML file for some forms, I know the BO support the XML file used, but is there any designer that will help me in the creation of the XML file and to maintain its structure?

Probably it could be an enhancement of the DDT to allow the creation and maintanance of XML files and use that metadata in the BOM, unless I am missing something here and there is something like that somewhere in the framework.

Edhy Rijo

Replies
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Ok, I am getting somewhere here Hehe I used the code in the XML Sample project and added to my BO, and in the BO.FillAll() method added code to add a new row to the new XML file so I can edit the data in the form as follow:

 

Public Sub FillAll()

     '-- Establish Locals

     Dim loDS As New DataSet

     Dim lcFile As String = MicroFour.StrataFrame.Strings.StringBasics.AddBS(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location))

     '-- Save the XML file to disk

     lcFile &= ConstantInformation.ServerSettingsXMLFileName

     If Not System.IO.File.Exists(lcFile) Then

          Me.CurrentDataTable.WriteXml(lcFile, XmlWriteMode.WriteSchema, True)

     End If

     '-- Load the XML file

     loDS.ReadXml(lcFile)

     '-- Move the data into the business object

     Me.CopyDataFrom(loDS.Tables(0), MicroFour.StrataFrame.Business.BusinessCloneDataType.ClearAndFillFromCompleteTable)

     *-- If there is no record, add one here.

     If Me.Count = 0 Then

          Me.Add()

          Me.CurrentDataTable.AcceptChanges()

     End If

     '-- Clean Up

     loDS.Dispose()

End Sub

In my form I am able to see the data bounded to the xml file and save it back to the xml using the methods in the Sample BO to overwrite the Save() methods.  I now need to add the logic to use the XmlBasics classes to take advantage of having the XML file encrypted and password protected. I am not so sure how to do this since the BO is getting the data via the loDS.ReadXml() method and that does not support the xmlBasics classes, so any help in this regard will be greatly appreciated.

Edhy Rijo

Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Well, I came up with solution that it is working eventhough I am not completed sure it is coded the right way:

     Public Sub FillAllWithXMLBasics(ByVal ValidationKey As String)

     '-- Establish Locals

     Dim lcFile As String = MicroFour.StrataFrame.Strings.StringBasics.AddBS(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location))

     '-- Save the XML file to disk

     lcFile &= ConstantInformation.ServerSettingsXMLFileName

     '-- Get all data columns from the TableSchema in the BO

     ' to pass it in the xmlBasics.OpenXmlFile

     Dim boTableColumnArray As New List(Of DataColumn)

     For Each I As DataColumn In Me.CreateTableSchema

          boTableColumnArray.Add(I)

     Next

     '-- Load the XML file and add one row

     _myXMLDS = XmlBasics.OpenXmlFile("ConsoleSettings", lcFile, boTableColumnArray)

     If _myXMLDS.Tables("ConsoleSettings").Rows.Count = 0 Then

          _myXMLDS.Tables("ConsoleSettings").Rows.Add()

     End If

     '-- Move the data into the business object

     Me.CopyDataFrom(_myXMLDS.Tables("ConsoleSettings"), MicroFour.StrataFrame.Business.BusinessCloneDataType.ClearAndFillFromCompleteTable)

     '-- In this case we need only one record so

     ' if there is no record, add one here.

     If Me.Count = 0 Then

          Me.Add()

          Me.CurrentDataTable.AcceptChanges()

     End If

End Sub

In the above code I am not sure if I neede to create the boTableColumnArray or there is an easy way to pass the BO columns to the OpenXmlFile() method.

And to save the file from the BO to the XML I am using this method:

Private Sub SaveToXML()

     '-- Establish Locals

     Dim lcFile As String = MicroFour.StrataFrame.Strings.StringBasics.AddBS(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location))

     '-- Save the XML file to disk

     lcFile &= ConstantInformation.ServerSettingsXMLFileName

     '-- I am not sure if the file needs to be deleted

     If System.IO.File.Exists(lcFile) Then

          System.IO.File.Delete(lcFile)

     End If

     '-- Remove the Row created in the FillAllWithXMLBasics and import the one from the BO.

     '-- I guess there is probably a better way to do this?

     _myXMLDS.Tables("ConsoleSettings").Rows.RemoveAt(0)

     _myXMLDS.Tables("ConsoleSettings").ImportRow(Me.CurrentRow)

     '-- Write the XML file back to disk. Notice that you DO NOT NEED the validation key

     ' to write back to disk. This is used only for opening (and the creation of) the XML table.

     XmlBasics.WriteXmlFile(_myXMLDS, lcFile, False)

     Me.CurrentDataTable.AcceptChanges()

End Sub

I appreciate if someone can review these code and confirm they are code appropriately.

Thanks!

Edhy Rijo

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search