Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: Display all node names and values [Thread Next] Re: Display all node names and valuesTo: NULL Date: 9/4/2007 9:56:00 AM
Hi Martin,
Thanks! -- that is exactly what I needed -- just the code to extract the
node names and values.
Sorry about my misleading first post -- I was in a rush and should have
checked my request prior to posting... In any case, now there are two
different solutions.
I won't have any problem using the node names/values with the database end
of things.
Thanks again.
"Martin Honnen" wrote:
> Brent D. wrote:
>
> > My problem is I need to extract the node names and values from the XML
> > document for use in a database. I am fully aware of the XML classes in the
> > asp.net framework. My problem has been finding a piece of sample code that
> > can iterate through ALL the nodes of any XML document.
> >
> > If you have any sample code that does this using the XML classes of the
> > asp.net framework, please let me know.
>
> Use XmlReader for instance, here is an example (writing to Console.Out
> but it shows how to use the XmlReader methods):
>
> using (XmlReader xmlReader =
> XmlReader.Create(@"..\..\XMLFile3.xml"))
> {
> while (xmlReader.Read())
> {
> switch (xmlReader.NodeType)
> {
> case XmlNodeType.Element:
> Console.Write(xmlReader.Name);
> break;
> case XmlNodeType.SignificantWhitespace:
> case XmlNodeType.Whitespace:
> Console.Write(xmlReader.Value);
> break;
> case XmlNodeType.Text:
> Console.Write(" = {0}", xmlReader.Value);
> break;
> }
> }
> }
>
> Result applied on your sample XML (with the typo Neil found corrected)
> is as follows:
>
> root
> node1 = value 1
> list
> node2 = value 2
> node3 = value 3
>
> node4 = value 4
>
> Pretty much what you want. You will need to be more specific about the
> database stuff if you need more help, your original request said "the
> output would display", your last request talked about a database, it is
> not clear how that relates together. Hopefully the above code snippet
> does show you how to use XmlReader and you can add the code to store the
> data in a database yourself.
>
>
> --
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/
>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
