Dom4j解析带有命名空间的XML文件

依赖包:

dom4j-1.6.1, jaxen -1.1.1

xml:






update user u set u.name=$name 

,u.sex=$sex

where u.id=#id



java类部份解析代码:


SAXReader saxReader = new SAXReader();
Document document = saxReader.read(file);
HashMap map = new HashMap();
map.put( "tns", "http://www.nl.org/mapper");
XPath xpath = document.createXPath( "//tns:mapper");
xpath.setNamespaceURIs(map);  
Element rootElement= (Element) xpath.selectSingleNode( document);


你可能感兴趣的:(java)