xml文件:
   <employees>
<employee value="employee的值">
<name>Mary</name>
<sex>女</sex>
</employee>
   </employees>当遍历树时,发现employee下有5个子节点,下面是打印出的节点名
节点名:#text
节点名:name
节点名:#text
节点名:sex
节点名:#text现在想请各位高手解释一下为什么会有5个子节点,如何删除其中的#text节点

解决方案 »

  1.   

    楼主意思是应该6个?public bool Delete(int key)
    {
    Node current = root;
    Node parent = root;
    bool isLeftChild = true;
    while (current.Data != key)
    {
    parent = current;
    if (key < current.Data)
    {
    isLeftChild = true;
    current = current.Right;
    }
    else
    {
    isLeftChild = false;
    current = current.Right;
    }
    if (current == null)
    return false;
    }
    if ((current.Left == null) & (current.Right == null))
    if (current == root)
    root = null;
    else if (isLeftChild)
    parent.Left = null;
    else if (current.Right == null)
    if (current == root)
    root = current.Left;
    else if (isLeftChild)
    parent.Left = current.Left;
    else
    parent.Right = current.Right;
    else if (current.Left == null)
    if (current == root)
    root = current.Right;
    else if (isLeftChild)
    parent.Left = parent.Right;
    else
    parent.Right = current.Right;
    else
    {
    Node successor = GetSuccessor(current);
    if (current == root)
    root = successor;
    else if (isLeftChild)
    parent.Left = successor;
    else
    parent.Right = successor;
    successor.Left = current.Left;
    }
    return true;
    }
      

  2.   

    上面的兄弟,我问的是DOM树,你能告诉我DOM树的数据结构吗?
      

  3.   

    你用的xml解析包不对吧?或者方法不对。按照你的xml示例,不就是两个节点,怎么会多出来三个?把你用的DOM版本,和方法说一下。
      

  4.   

    五个子节点没什么问题啊?
    需要注意的是比如
    <name>Mary </name> 
    是两个节点,中间的Mary是一个文本节点,即#text, 他是属于name节点的子节点。
      

  5.   

    #text,这里其实是将换行符作为了一个节点
    可以采用这条语句过滤  if(node.getNodeType() != Node.TEXT_NODE)