Click here to Skip to main content
15,067,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
what is the xpath of xml to read node PatientDrugDetail
XML
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<GetPatientFullMedicationHistoryResponse xmlns="https://secure.newcropaccounts.com/V7/webservices">
<GetPatientFullMedicationHistoryResult>
<result>
<Status>OK</Status>
<Message/>
<XmlResponse/>
<RowCount>2</RowCount>
<Timing>0</Timing>
</result>
<patientDrugDetail>

<PatientDrugDetail>
<Name>abc</Name>

</PatientDrugDetail>
<PatientDrugDetail>
<Name>bca</Name>
</PatientDrugDetail>

</patientDrugDetail>
</GetPatientFullMedicationHistoryResult>
</GetPatientFullMedicationHistoryResponse>
</soap:Body>
</soap:Envelope>
Posted

1 solution

Are you using XmlDocument.SelectNodes ?

If so, I suspect that you are running into a problem with the namespace on the third line -- which applies to all the elements within the GetPatientFullMedicationHistoryResponse element.

In order to use XPath to select the desired Element you need to specify a prefix to use by using an XmlNamespaceManager. (It's counter-intuitive.)

http://msdn.microsoft.com/en-us/library/4bektfx9(v=vs.110).aspx[^]

I don't have the code I use to do that handy and I still haven't gotten around to writing an article on it.


If I recall correctly, you'll need to use;
System.Xml.XmlNamespaceManager nsm = new System.Xml.XmlNamespaceManager ( Document.NameTable ) ;
nsm.AddNamespace ( someprefix , "https://secure.newcropaccounts.com/V7/webservices" ) ;


Then use someprefix as the prefix.
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900