StrataFrame Forum

Creating and Binding a BO to an XML file...

http://forum.strataframe.net/Topic3566.aspx

By StarkMike - 10/13/2006

I'm sorry I didnt see anything in the documentation that talks about how to create and ultimately bind a BO to an XML file. I looked at the XMLDataSourceSample and I saw that you did it, I just dont understand how to get to that point. I'm assuming you cant use the Business Object Mapper to map to the xml file and create the partial class.



Could you maybe help me get a jump start on how to do this?



Thanks
By StrataFrame Team - 10/13/2006

You have to use the DDT and create a "dummy" profile with a "dummy" database and a "dummy" tables that has the structure of the XML file.  That's how you get the BOMapper to create the partial class for you.
By StarkMike - 10/13/2006

We didnt purchase the DDT... does that mean we are out of luck? What if I initially create the table in SQL Server to get the BO Mapper to create the partial class and then some how redirect the BO to the xml file instead of SQL Server
By StrataFrame Team - 10/13/2006

Yes, that will work as well... you could even create the structure on a local instance of SQL Server express rather than on one of your dev servers... doesn't matter.
By StarkMike - 10/13/2006

Ok, now that I have my BO created what would I need to change to redirect it to look at the xml file instead of the SQL Server?
By StrataFrame Team - 10/13/2006

You will need to write Fill methods that end up calling Me.CurrentDataTable.ReadXml() to bring the xml file in and you will need to overwrite the Save() method to save the data to the XML file using Me.CurrentDataTable.WriteXml() and then Me.CurrentDataTable.AcceptChanges().
By StarkMike - 10/13/2006

Thanks. Me.CurrentDataTable.ReadXML() didnt work but I was able to take most of the code from the XMLDatasource example and make it work.



Another question...what if I wanted to create a FillByEmployeeID method? how would I query the XML document to only return the records I want?



Here's the code I used for my basic Fill method:





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))



lcFile &= "test.xml"



'-- Load the XML file

loDS.ReadXml(lcFile)



'-- Move the data into the business object

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



'-- Clean Up

loDS.Dispose()

End Sub

By StrataFrame Team - 10/13/2006

That is an excellent question, Mike...

I would venture to say that you would want to copy the data from the XML file into SQL Server and run the query BigGrin

No, really, you'll probably need to use some of the objects within the System.Xml.XPath namespace (in the System.Xml.dll assembly) or maybe figure out how to use XQuery... however I have never used either of those technologies, so I wouldn't know where to start, though you might Google XQuery or XPath and see what sort of info you can find on it.

The XPath namespace has some objects you can use to create an XML cursor, so if worst comes to worst, you could cursor through the records to find the one that you want, but I'm pretty sure XQuery supports XML indexes, so it should be lots faster.