0

我有以下 xml

<?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");

谁能告诉如何实现这一目标?

4

1 回答 1

1

As per the comment you haven't told us which language / parser you are using, but you can use local-name() to achieve namespace agnostic xpath, to avoid using a NamespaceManager or similar, as follows:

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

Update

Note that your root element is response (in global namespace), so you'll either need to navigate it explicitly, or use // to find matching descendants.

于 2013-01-16T15:32:53.010 回答