小编Mar*_*hal的帖子

为什么getNamespaceURI()总是返回null?

为什么getNamespaceURI()总是返回null?printNSInfo方法有什么问题

public static void main(String[] args) {
    Document input = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(args[0]);
    Element root = input.getDocumentElement();
    printNSInfo(root);
}

private static void printNSInfo(Node node) {
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        if (node.getNamespaceURI() != null) {
            System.out.println("Element Name:" + node.getNodeName());
            System.out.println("Local Name:" + node.getLocalName());
            System.out.println("Namespace Prefix:" + node.getPrefix());
            System.out.println("Namespace Uri:" + node.getNamespaceURI());
            System.out.println("---------------");
        }
        if (node.hasAttributes()) {
            NamedNodeMap map = node.getAttributes();
            int len = map.getLength();
            for (int i = 0; i < len; i++) {
                Node attr = map.item(i);
                if (attr.getNamespaceURI() != null) …
Run Code Online (Sandbox Code Playgroud)

java dom namespaces

3
推荐指数
1
解决办法
2163
查看次数

标签 统计

dom ×1

java ×1

namespaces ×1