在该接口的文档中,它声明文本节点都返回“#text”作为其名称而不是实际的标记名称.但是对于我正在做的事情,标签名称是必要的.
// I'm using the following imports
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
// In the .xml input file
US // This is a "text node" .getTextContent()
// returns "US", I need "country" and .getNodeName()
// only returns "#text"
我怎么能访问标签名称?这必须是某种可能的,我不介意一个hackish解决方案.
文档:
谢谢.