用dom4j解析带命名空间的xml文件
<script>function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}</script><div class="highlighter">[*]SAXReadersaxReader=newSAXReader();
[*]try{
[*]Documentdocument=saxReader.read(newFile(filename));
[*]Elementroot=document.getRootElement();
[*]HashMapxmlMap=newHashMap();
[*]xmlMap.put("plugins","http://www.**.com/yanfa/appmonschema");//http://www.**.com/yanfa/appmonschema为命名空间
[*]XPathx=document.createXPath("//plugins:AppMonConfig/plugins:outputStrategy/plugins:monStrategy/plugins:item/plugins:targetId");//读取targetId节点
[*]x.setNamespaceURIs(xmlMap);
[*]ElementvalueElement=(Element)x.selectSingleNode(document);
[*]System.out.println(valueElement.getText());//输出该节点内容
[*]}catch(Exceptione){
[*]}
页:
[1]