Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Using xmldocument.SelectNodes

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 4/4/2006 6:33:00 PM



JoeKatz@g... wrote:

> This is all being done in .NET.  I'm using an xmldocument and I load
> XML into it that i received back from a web service.  Below is a
> "section" of that chunk of xml.  Now for each section i use the
> xmld.selectnodes("/xmlhistory/violation") to create an xmlnodelist for
> all the chunks that are "violation" nodes.  Once I have that into an
> xmlnodelist , i iterate through them using for each xmlnode in
> xmlnodelist. Inside this for loop i'm gathering the values of each tag
> and creating a nice html table that will later be stored. Now once
> inside this for loop i'm running into an issue.  In some cases this xml
> below will have additional fields such as <disposition> but sometimes
> it won't.  How can I check while in this for loop if the tag of
> <disposition> is present.  

SelectNodes and SelectSingleNode is not only a method of the XML 
document (XmlDocument) object but also of any node so for that node in 
your for each loop you can call e.g. (C#)
   XmlNodeList dispositions = node.SelectNodes("disposition");
and process those elements with another loop or of course, if you expect 
only one disposition element or are interested only in the first 
disposition element then e.g.
   XmlElement disposition = node.SelectSingleNode("disposition") as 
XmlElement;
   if (disposition != null) {
     // now use element node here
   }
   else {
     // do what you want to do if there is no dispositon
   }

 > If it is I want to ( _disposition =
> xmlnode.Item("disposition").InnerText ) grab the value , if its not I
> want to ignore that tag all together.  

That is another possibility the .NET DOM offers, indexing by name e.g.
   if (node["disposition"] != null) {
     // use node["disposition"].InnerText
   }

If you use VB.NET then it should be alike
   If Not node.Item("disposition") Is Nothing Then
     ' use node.Item("disposition").InnerText
   End If

-- 

	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