Type of node ?

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

C# newbie

Hello everybody,

in a code as this:

foreach (XmlNode xnode in node.SelectSingleNode(txtPattern.Text,nsmgr))

{


switch (xnode.NodeType){

case XmlNodeType.Element:

MessageBox.Show("This node is an ement");

break;

case XmlNodeType.Text:

MessageBox.Show("this node has type of text");

break;

}

for an xml file as :



<AAA>
<BCC>
<BBB/>
<data>'Text goes here'</data>
<BBB/>
</BCC>
</AAA>

the case only shows that all nodes types are Element! but there are some
text too. Does anybody know how I would be able to find out an element's
type ?



Thanks

Newbie
 
In the Xml that you provided, all are actually elements in its own right.

The XmlNodeType.Text enum is for referencing the text content of a node.

A Text node cannot have any child nodes. It can appear as the child node of the Attribute , DocumentFragment , Element , and EntityReference nodes.

Regards
Jonathan Rucker
 
Jonathan thanks for your help but still I don't know what to do! I'm new to
this. How can I know that an element has a text type ?
I think there must be a different between:
<AAA> and <AA>"text"</AA> also there must be a solution to figure that
out.
Can you help me out with this ?

Thanks in advance
newbie

Jonathan Ruckert said:
In the Xml that you provided, all are actually elements in its own right.

The XmlNodeType.Text enum is for referencing the text content of a node.

A Text node cannot have any child nodes. It can appear as the child node
of the Attribute , DocumentFragment , Element , and EntityReference nodes.
 
Are you trying to find out if an element has text in it

i.e. <AAA/> has no text <AAA>Text</AAA> has text

If you are, you can see if the XmlNode.InnerText has any text in it

HT

RS
 
Back
Top