Why XmlNode.Name get node name and its first attribute together?

G

Guest

When I create a tree view control from XML document, I use XmlNode.Name in
the node list iteration. But sometime, it is supposed that it got the element
name. But sometimes it got the element name and first attribute together.

For eaxmple, I use the following iteration code after creating the root from
DOM.DocumentElement.Name.
-----
private void AddNode2(XmlNode inXmlNode, TreeNode inTreeNode)
{
XmlNode xNode;
TreeNode tNode;
XmlNodeList xNodeList;
int i;

if(inXmlNode.HasChildNodes)
{
xNodeList = inXmlNode.ChildNodes;
for(i=0; i < xNodeList.Count; i++)
{
inTreeNode.Nodes.Add(new TreeNode(xNode.Name));
tNode=inTreeNode.Nodes;
AddNode(xNode, tNode);
}
}
else
{
inTreeNode.Text = inXmlNode.Name;
}
}
-----
Here is my XML file:
-------
<?xml version="1.0" encoding="utf-8"?>
<PA id="08-01-01">
<ST part="head" date="20040403">1
<SE desc="Scout">1
<IM>1</IM>
<IM>2</IM>
</SE>
<SE desc="Routine">2
<IM>1</IM>
<IM>2</IM>
<IM>3</IM>
<IM>4</IM>
</SE>
</ST>
</PA>
-------
My tree view looks like:
--------
PA
|---1
|---ST
|---1
|---SEScout
| |---1
| |---IM
| |---1
| IM
| |---2
|---SERoutine
| |---2
| |---IM
| |---1
................
----------

The XmlNode.Name return ST for <ST part="head" date="20040403">
but return SEScout for <SE desc="Scout"> and SERoutine for <SE
desc="Routine">.


I do not know why.
Could any one here give a help?

Thanks

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top