How to read XML into a dataset?

I have a XML xsd defined. There are header, details, and EXTRINSIC  data element in the schema How do I read the XML data into a dataset? I can, of course, define different tables in the dataset to model the header and details.

Platform and Env: ASP.NET 2.0, C# and SQL 2005. VS.NET 2005
LVL 1
chuang4630Asked:
Who is Participating?
 
vbturboConnect With a Mentor Commented:
Hi

a small sample.  Which takes the assumption that a xsd is created.

       Dim testing As New DataSet

        ' Load the prototype XSD file...
        testing.ReadXmlSchema("C:\SomeFolder\SomeXSDfile.xsd")

        ' Receiving a file based upon that schema...
        testing.ReadXml("C:\SomeFolder\SomeXMLfile.xml")

        ' Writing an xml file based upon that schema...
        testing.WriteXml("C:\SomeFolder\SomeXMLfile.xml")
            'save the schema
            testing.WriteXmlSchema("C:\SomeFolder\SomeXSDfile.xsd")

And a couple of other tips in this regard

Generating DataSet Relations from XML Schema (XSD)
http://msdn2.microsoft.com/en-us/library/yk6y3s8y(vs.71).aspx

Mapping XML Schema (XSD) Constraints to DataSet Constraints
http://msdn2.microsoft.com/en-us/library/f8bhbatb(VS.71).aspx

Create a DataRelation to link the two tables
http://msdn2.microsoft.com/en-us/library/system.data.dataset(vs.80).aspx

manage Constraints
http://msdn2.microsoft.com/en-us/library/0k21zcyx(VS.71).aspx
http://msdn2.microsoft.com/en-us/library/ms810294.aspx


vbturbo
0
 
surajgupthaCommented:
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
chuang4630Author Commented:
Thanks for the example. However, the sample file only shows how to load the data into a untyped dataset (based upon the schema). How to load the XML into a typed dataset?
0
 
anarki_jimbelCommented:
May be I'm missing something.. What do you call typed dataset? For me if schema is loaded it provides the dataset with types stored.
0
 
surajgupthaCommented:
Well it would help if we know what you are trying to implement.
0
 
chuang4630Author Commented:
Here are what I have and what I need to achieve:
(1) I have a XML data string. It consists three parts: LOGIN, ASSETHEADER and ASSETSITEMS.
(2) The XML schema is predefined (MySchema.xsd) in MyProjectCommon
(3) I need to populate part of the XML data into the database table TempAssets.

I can ReadXML to the generic DataSet and process the data from there. However, due to the nature of the generic dataset, I have to reference the data column through row["PONUMBER"]. And there is no relationship between the tables in the dataset.

What I am thinking about is to predefine a dataset that models after the schema. Load the XML data string to this dataset. So I can utilize typed dataset feature to manipulate data.
Also, I try to avoid to read the schema fom file system (I/O) and prefer the reference. Otherwise I have provide the filepath and heavily access the disk I/O.

How do I achieve that?


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.