Eng Posted May 18, 2004 Posted May 18, 2004 Has anyone worked with an XML Files that has the relations set-up between each elements within the file? I am curious as to, how the XML File and its schema look like for this type of XML. I have only seen the simple Hierarchial XML documents and I am wondering if anyone could shed lights on this. I need to experiment with reading the relational XML documents into the ADO Dataset and I don't have any good examples to based on. My curiousity is killing me. Thanks! Quote
*Experts* Nerseus Posted May 18, 2004 *Experts* Posted May 18, 2004 Do you mean you have an XML file that was created from a DataSet (the schema or data+schema)? If so, create a new DataSet then use the ReadXml method with XmlReadMode.ReadSchema. If this is custom XML that happens to have relations in it, we'll need a LOT more info. How did it get created? How do you know about relationships? -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Eng Posted May 18, 2004 Author Posted May 18, 2004 No...the plan is for the third party to sent us their data in the XML File Format. According to them, they will be able to set up the relations within their XML File (Elements/Tables) using the XREF(?) when they sent us the XML File and the schema. I was able to successfully read in the "simple" XML file with the mapping of the schema file into the Dataset, using the XMLDocument Object. Now, I am trying to see if I could read in the "realation" XML file with the mapping of the schema file into the Dataset. Basically, I am trying to answer my question of "Will the relations in the XML file that the client sent be able to read in correctly as DataRelations into the Dataset?" Since I have never seen the "relation" XML File (our client hasn't sent us one yet), I wanted to stay ahead of the game by finding the "How's". I couldn't find any examples or tutorials on doing such ...yet. Quote
*Experts* Nerseus Posted May 18, 2004 *Experts* Posted May 18, 2004 You can use use the DataSet's ReadXmlSchema method to read an XML schema file. If you create a DataSet in Visual Studio (an XSD file) you can view the resulting XML. A sample key and relationship looks like this: This assumes two tables, Customer (with CustomerID) and Order (with OrderID). The "xs:key" sets up a primary key on teh customer table on column CustomerID. They key is called PKCustomer but could be anything you want. The "xs:keyref" sets up the relationship. In this case, linking the previously defined key PKCustomer and the OrderID on the Order table. <xs:key name="PKCustomer" msdata:PrimaryKey="true"> <xs:selector xpath=".//Customer" /> <xs:field xpath="CustomerID" /> </xs:key> <xs:keyref name="CustomerOrder" refer="PKCustomer"> <xs:selector xpath=".//Order" /> <xs:field xpath="OrderID" /> </xs:keyref> -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Eng Posted May 18, 2004 Author Posted May 18, 2004 Ok...it sounds like you understood my question:-) Based on the snippet schema example you gave me, if I were to load the dataset with the ReadXmlSchema method, then the datset that I have loaded will already have the "Relation" called [CustomerOrder] as its RelationName...correct? From the schema, will it also know which is the Parent Table/Column and which is the Child Table/Column? Quote
*Experts* Nerseus Posted May 19, 2004 *Experts* Posted May 19, 2004 Will it have the relation named CustomerOrder? -Yes Will it know the parent and child? -Yes You can also specify non-default behavior for relationships (like non-cascading deletes and such). If you use Visual Studio's DataSet editor, you can "visually" change the relationship. It works much like a real database tool, such as Access or SQL Server Enterprise manager. As you make changes, you can look at the XML by switching tabs. -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.