Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Question

Status
Not open for further replies.

c100cbk2

Programmer
Sep 20, 2010
11
GB
Can anyone spot where I have gone wrong,

vb.net code;

Dim responseDoc As New Xml.XmlDocument
responseDoc.LoadXml(response)

Debug.Print(responseDoc.SelectSingleNode("aggregateQuoteResponse/brokerResponse/quote/premium").InnerText)

Issue:

the above line ALWAYS errors with the following error ; object reference not set to an instance of an object

the XML is below, i have done this dozens of times before so it must be me missing the obvious;

XML:

<?xml version="1.0" encoding="UTF-8" ?>

- <ns:aggregateQuoteResponse xmlns:ns="
<transactionID>5aa0c2aec0c14a6d:-13bcb51e:12afbc91fdb:-7f52.Mon Sep 20 16:52:11 BST 2010</transactionID>

- <brokerResponse xmlns:xsi="
<brokerRef>Onequote</brokerRef>

<webReference>67F-2HC-D48</webReference>

- <quote xsi:type="ns:aggregateQuoteResultTypeCaravan">

<premium>18830</premium>

<ipt>990</ipt>

<iptRate>5.0</iptRate>

<insurerCode>DW</insurerCode>

<insurerName>Drewe</insurerName>

<schemeCode>DO</schemeCode>

<reason>Total Premium (Excl IPT).........(#)</reason>

<totalSumInsured>900000</totalSumInsured>

<caravanSumInsured>400000</caravanSumInsured>

<equipmentSumInsured>200000</equipmentSumInsured>

<contentsSumInsured>300000</contentsSumInsured>

</quote>

</brokerResponse>

</ns:aggregateQuoteResponse>
 
too busy to test but perhaps your xpath needs to take into account the ns: namespace for the aggregateQuoteResponse element
 
Yes, I agree. The XPath expression must use the namespace.

Tom Morrison
Micro Focus
 
I took your advice and added in the namespace as shown below and now get a retrun vale so many thanks.

Dim ns As Xml.XmlNamespaceManager = New Xml.XmlNamespaceManager(responseDoc.NameTable)
ns.AddNamespace("ns", "
Debug.Print(responseDoc.SelectSingleNode("ns:aggregateQuoteResponse/brokerResponse/quote/premium", ns).InnerText)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top