2013-01-16 200 views
0

解析我有下面的XMLXML命名空間

<?xml version="1.0"?> 
<response status="200"> 
    <ns3:output xmlns="http://xmlns.oracle.com/apps/fnd/wf/worklist/service/rt/artifacts/notificationdetails/" 
       xmlns:ns2="http://xmlns.oracle.com/apps/fnd/wf/worklist/service/rt/artifacts/worklistmgmt/" 
       xmlns:ns3="http://xmlns.oracle.com/apps/fnd/wf/worklist/service/rt/artifacts/worklist/"> 
    <ns2:notifications count="140552"> 
     <ns2:notification> 
     <ns2:NotificationId>4687807</ns2:NotificationId> 
     </ns2:notification> 
    </ns2:notifications> 
    </ns3:output> 
</response> 

我需要解析這一點,並獲得每行的NotificationId值。 我嘗試使用下面的代碼以獲取列表,但它返回0。

notificationrows = xmlDoc.documentElement.selectNodes("/ns3:output/ns2:notifications"); 

誰能告訴如何實現這一目標?

+3

你在用什麼語言? – SLaks

回答

1

按照評論你還沒有告訴我們您所使用的語言/分析器,但您可以使用local-name()實現命名空間不可知的XPath,避免使用NamespaceManager或類似的,如下:

notificationrows = xmlDoc.documentElement.selectNodes("/response/*[local-name()='output']/*[local-name()='notifications']"); 

更新

請注意,你的根元素是response(在全局命名空間),所以你要麼需要顯式導航,或者使用//找到匹配的後代。

+0

嗨,感謝您的回覆 – later2013

+0

但它確實爲我工作.. – later2013

+0

的通知來作爲空... – later2013