为什么我的xml文件中有#text节点?

Otr*_*tra 7 android dom xml-parsing

我正在制作一个在xml文件上进行DOM解析的android应用程序.我有一个xml文件,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<family>
    <grandparent>
        <parent1>
            <child1>Foo</child1>
            <child2>Bar</child2>
        </parent1>
        <parent2>
            <child1>Raz</child1>
            <child2>Mataz</child2>
        </parent2>
    </grandparent>  
</family>
Run Code Online (Sandbox Code Playgroud)

如果我在其上运行dom解析器,就像这样:

try {
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();

    Document doc = builder.parse(input);
    doc.getDocumentElement().normalize();   //added in since the edit
    NodeList nodd = doc.getElementsByTagName("grandparent");
    for (int x = 0; x < nodd.getLength(); x++){
        Node node = nodd.item(x);
        NodeList nodes = node.getChildNodes();
        for(int y = 0; y < nodes.getLength(); y++){
            Node n = nodes.item(y);
            System.out.println(n.getNodeName());
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我的应用程序打印出以下内容

07-20 18:24:28.395:INFO/System.out(491):#text

07-20 18:24:28.395:INFO/System.out(491):parent1

07-20 18:24:28.395:INFO/System.out(491):#text

07-20 18:24:28.395:INFO/System.out(491):parent2

07-20 18:24:28.395:INFO/System.out(491):#text

我的问题是,那些#text字段是什么,更重要的是,我如何摆脱它们?

编辑:所以现在我知道它们是什么,我试图将它标准化.我已更新代码以反映更改,但结果相同.

Ray*_*oal 5

它是空格(换行符,空格,制表符):)