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

Discussion in 'ASP .Net' started by =?Utf-8?B?ZGF2aWQ=?=, Mar 12, 2007.

  1. 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
     
    =?Utf-8?B?ZGF2aWQ=?=, Mar 12, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,641
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,211
    Smokey Grindel
    Dec 2, 2006
  3. Stefan_W
    Replies:
    1
    Views:
    8,374
    Stefan_W
    Nov 5, 2008
  4. thunk
    Replies:
    0
    Views:
    536
    thunk
    Apr 1, 2010
  5. thunk
    Replies:
    14
    Views:
    659
    thunk
    Apr 3, 2010
Loading...

Share This Page