jdom有你需要的按元素名(标签名)定位的方法。DOM的话,你自己写一个方法实现也很简单啊。标准的dom就是这样。空的文本节点是因为两个元素之间的whitespace造成的(一般xml文档的两个元素都加了空格或回车),不过你可以在解析时靠设置解析器的属性来忽略whitespace,不过好像不一定起作用。
还有一种方法,就是在输出时判断节点的类型,只有当node.getNodeType()=Node.ELEMENT_NODE你才处理嘛。

解决方案 »

  1.   

    javax.xml.parsers 
    Class DocumentBuilderFactory
    java.lang.Object
      |
      +-javax.xml.parsers.DocumentBuilderFactory
    ---------------------------------------------------------------
    setIgnoringElementContentWhitespace
    public void setIgnoringElementContentWhitespace(boolean whitespace)
    Specifies that the parsers created by this factory must eliminate whitespace in element content (sometimes known loosely as 'ignorable whitespace') when parsing XML documents (see XML Rec 2.10). Note that only whitespace which is directly contained within element content that has an element only content model (see XML Rec 3.2.1) will be eliminated. Due to reliance on the content model this setting requires the parser to be in validating mode. By default the value of this is set to false. Parameters:
    whitespace - true if the parser created must eliminate whitespace in the element content when parsing XML documents; false otherwise.