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
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