[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 584
  • Last Modified:

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
0
chuang4630
Asked:
chuang4630
  • 2
  • 2
  • 2
  • +1
1 Solution
 
surajgupthaCommented:
0
 
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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
 
vbturboCommented:
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now