later2013
later2013

Reputation: 41

XML Parsing with NameSpace

I have the below 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>

I need to parse this and get the NotificationId value for each row. I tried using the below code to get the list but it returned 0.

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

can anyone tell how to achieve this?

Upvotes: 0

Views: 197

Answers (1)

StuartLC
StuartLC

Reputation: 107367

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.

Upvotes: 1

Related Questions