Read complicated xml into a DataSet

I am trying to read in an XML doc ument into a DataSet such that I can get the data and potentially re-set values as well. The XML document looks as follows:

      <remark>Password for database.</remark>
      <remark>Path for location of file.</remark>
            <pvalRemark>Relative path to foo 1.</pvalRemark>
            <pvalRemark>Relative path to bar 1.</pvalRemark>
      <ConfigTimeRemark>Relative path to time field.</ConfigTimeRemark>

As you can see there is a bit of nesting here so getting tables and rows is a bit different. The "Paths" section can have any number of 'pval' / 'pvalRemark' entries.

Simply using ds.Tables["SEC-A01"].Rows[0]["pval"].toString() or any combination that I've tried throws exceptions.

How can I use DataSet/DataTable/DataRow (to which ever combination) to get the data from this xml doc?

Who is Participating?
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
You can use the objects in the System.Xml namespace. The DataSet is only really a viable option if you have your XML in a format that can easily be loaded into related tables.

For example, the following code block will grab the SEC-A01 node and loop through all of its "pval" and "pvalRemark" nodes:

            XmlDocument doc = new XmlDocument();

            XmlNode node = doc.SelectSingleNode("/MyDoc/SEC-A01");
            foreach (XmlNode child in node.ChildNodes[0].ChildNodes)
                MessageBox.Show(child.Name + ": " + child.InnerText);
Carl TawnSystems and Integration DeveloperCommented:
Reading your XML straight into a DataSet produces six tables. "pval" and "pvalRemark" are put into their own tables, so you can access all "pval" records using:

    DataSet ds = new DataSet();

    foreach (DataRow row in ds.Tables["pval"].Rows)
ipamanAuthor Commented:
carl tawn.....OK, I forgot to mention one other attribute of this xml document. (brain still asleep)

There will be other sections like <SEC-A01>. Except they will be <SEC-A02>, <SEC-A03>, etc... and
I will need to differentiate between the pval in SEC-A01 and the pval in SEC-A02, etc...

What would be the code to differentiate these sections?

thanks in advance,

Carl TawnSystems and Integration DeveloperCommented:
That may be a little tricky due to the structure of your document. Could you not just parse the document as an XML file rather than reading it into a DataSet ?
ipamanAuthor Commented:
what is the other way of parsing the xml doc? (Not xerces!)

I thought bringing it in to a DataSet would be the quickest and easiest.....
All Courses

From novice to tech pro — start learning today.