用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>
  1. SAXReadersaxReader=newSAXReader();
  2. try{
  3. Documentdocument=saxReader.read(newFile(filename));
  4. Elementroot=document.getRootElement();
  5. HashMapxmlMap=newHashMap();
  6. xmlMap.put("plugins","http://www.**.com/yanfa/appmonschema");//http://www.**.com/yanfa/appmonschema为命名空间
  7. XPathx=document.createXPath("//plugins:AppMonConfig/plugins:outputStrategy/plugins:monStrategy/plugins:item/plugins:targetId");//读取targetId节点
  8. x.setNamespaceURIs(xmlMap);
  9. ElementvalueElement=(Element)x.selectSingleNode(document);
  10. System.out.println(valueElement.getText());//输出该节点内容
  11. }catch(Exceptione){
  12. }

你可能感兴趣的:(C++,c,xml,C#)