How to get an element's type in XML ?

  • Thread starter Thread starter C# newbie
  • Start date Start date
C

C# newbie

Hi Group,
Assume we have an xml as:

<GrandFather>
<Father>
<Son/>
<GrandSon>'Tim'</GrandSon>
</Son>
</Father>
</GrandFather>

How can I get the type of every element during a search by XPath query in
above xml file ? Let's say I've searched for "Tim" and found it. During
every step I need to find out the type of elemet. I need something like:

if (Current Element is a Text)
do this // this would let me to do some process for the text
container
else
do that // ignore the predefind process since it's not a text
container


Your help would be appreciated greatly.

Thanks
Newbie
 
Like this:
System.Xml.XmlNode n = doc.SelectSingleNode("xpath");

if (System.Xml.XmlNodeType.Text == n.NodeType)

{

Console.WriteLine("This is a text node.");

}
 
Dennis thanks for the tip but the thing is it passes the if statement and
doesn't show the messagebox. Just you kow I'm using SelectNodes although I
tried it on SelectSingleNode too.

Any suggestions ?

thanks
 
Back
Top