当xml中存在命名空间,三种处理办法(dom4j)
2008-04-02 11:56
309 查看
当你解析XML时,是否会因为命名空间的存在而不能得偿所愿呢?
.net上的解决方法我就不多说了(.net有世界上最详细的开发文档。这是我最欣赏微软的地方<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.15" id="1">
<list-property name="cssStyleSheets">
<structure>
<property name="fileName">D: eport.css</property>
</structure>
</list-property>
</report>
第一个方案.设置你的xpath的命名空间setNamespaceURIs
public class TransferXML ...{
public class TransferXML ...{
public class TransferXML ...{
public static void main(String[] args) throws Exception...
SAXReader saxReader = new SAXReader();
File file = new File("D:\test.xml");
Document document = saxReader.read(file);
List tmp = document.selectNodes("//*[local-name()='report' and namespace-uri()='http://www.eclipse.org/birt/2005/design']/* [local-name()='list-property']");
System.out.println(tmp.size());
}
}
.net上的解决方法我就不多说了(.net有世界上最详细的开发文档。这是我最欣赏微软的地方<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.15" id="1">
<list-property name="cssStyleSheets">
<structure>
<property name="fileName">D: eport.css</property>
</structure>
</list-property>
</report>
第一个方案.设置你的xpath的命名空间setNamespaceURIs
public class TransferXML ...{
public class TransferXML ...{
public class TransferXML ...{
public static void main(String[] args) throws Exception...
SAXReader saxReader = new SAXReader();
File file = new File("D:\test.xml");
Document document = saxReader.read(file);
List tmp = document.selectNodes("//*[local-name()='report' and namespace-uri()='http://www.eclipse.org/birt/2005/design']/* [local-name()='list-property']");
System.out.println(tmp.size());
}
}
相关文章推荐
- 当xml中存在命名空间,三种处理办法(dom4j)
- 当xml中存在命名空间,三种处理办法(dom4j)
- 当 xml中存在命名空间,三种处理办法(dom4j)
- 当xml中存在命名空间,三种处理办…
- 当xml带有命名空间时。dom4j的处理办法
- java 在dom4j中,使用XPath处理XML(主要对命名空间的处理)
- xml内容解析,包含命名空间时需特殊处理(dom4j)
- dom4j中通过xpath处理带命名空间的XML文件
- dom4j处理带命名空间的XML-使用XPath
- 当xml中存在命名空间,dom4j解析以及写入xml文档时的乱码问题
- 【转】+【改】DOM4J处理XML带有命名空间的四种方法
- DOM4J处理XML带有命名空间的四种方法
- dom4j创建带有命名空间的xml
- C#处理带命名空间的XML
- XML中处理带有命名空间的XPath查询
- dom4j解析带命名空间的xml
- dom4j 使用原生xpath 处理带命名空间的文档
- QML处理xml---查询含命名空间的节点
- Flex中处理带命名空间的XML
- dom4j 解析带命名空间的XML