您的位置:首页 > 其它

当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());


}


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: