Docuemnt 的 NamespaceURI为空问题

创建doc的方式不同,需要增加 DocumentBuilderFactory.setNamespaceAware(true); 这样Element Node.getNamespaceURI 才不为空


        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
InputStream inputStream = resource.getInputStream();
Document doc = builder.parse(inputStream);
这种方式创建的Document,Element中获取的NamespaceURI为空,生成的Element类型和上面生成的不同

原文地址:https://www.cnblogs.com/zhongchang/p/12081777.html