BizTalk Utilities CV ,   Jobs ,   Code library
 
Home Page


Add/Edit your code items
Search the code library
Browse for the code library


.NET and XML
How to verify if an element is empty with XmlTextReader and IsEmptyElement?
How to check if the XML elements contains any attributes with XmlTextReader
How to avoid to read the XML declaration with XmlTextReader?
How to create a XML file with XmlTextWriter?
Is it possible to add attributes with XmlTextWriter?
How to Write a Comment to a XML File with XmlTextWriter and WriteComment?
How to add the XML Declaration with XmlTextWriter and WriteStartDocument?
How to use Indentation in XmlTextWriter?
What is the usage of WriteFullEndElement and how do I use?
How to include a CData block with XmlTextWriter and WriteCData?
How to write raw XML with XmlTextWriter?
How to add a namespace with the XmlTextWriter and WriteStartAttribute?
How to create a new xml file with XmlDocument?
How to create a xml on the fly?
How to use the Item property in XmlTextReader?
How to Create a Comment with XmlDocument and XmlComment?
How to Read a XML from a Stream with XmlTextReader?
How to Read a XML from a URL with the XmlTextReader?
How to auto-increment an unique ID in XML with XmlTextReader?
How to read Nodes with XmlNodeReader?


 
 

<< XSLT 


By Sonu Kapoor
First Posted 02/05/2005
Times viewed 3515

How to compare a XML element with XmlTextReader?


Summary An easy example to compare an XML element with the System.Xml.XmlTextReader

In the previous example you learned to read a xml file with the XmlTextReader. However it displayed the data from all xml elements. In this short example you will see how to display the data only from the MainCategory element.

The trick is to use the Name property of the XmlTextReader class. This property returns the name of the current node. All you need is a if statement which compares the returned value of the Name property with MainCategory.

As you can see in the if block I am using a new function called ReadString(). This must be placed on a element or a text node to return the string, otherwise it will return an empty string.

Our code from the previous example is now change to this one.

Additional information


Rate this article on a scale of 1 to 10 (1 votes, average 5)

Your vote :  

<< XSLT 





Leave a comment for this article
Your name
Your email (optional)
Your comment
Optional: Upload an attachment
Enter the code shown:

 
 

    Email TopXML