Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Display all node names and values

From: BrentD@-----------.---------.---
To: 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/
> 


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent