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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parsing xml 1

Status
Not open for further replies.

thompom

Technical User
Dec 4, 2006
395
GB
Hi,

how do i loop through and display companies details

have tried
Code:
set nodes = xml.selectNodesset nodes = xml.selectNodes("/QuotesResponse/QuotesResult/InsuranceCalculationResult/Calculations/CalculationCalculation/Companies/Company")
for each N in nodes
Response.Write N.text & "<br>"
next

Code:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="[URL unfurl="true"]http://schemas.xmlsoap.org/soap/envelope/"[/URL] xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xmlns:xsd="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema">[/URL]

<soap:Body>
<QuotesResponse xmlns="">
<QuotesResult>
<InsuranceCalculationResult xmlns="">

<CustomerDetailsForm>
    <Url></Url>
    <DisplayText>Change customer details</DisplayText>
</CustomerDetailsForm>

<Calculations>
  <Calculation>
   <Vehicle>
      <CapId>12345</CapId>
      <VehicleYear>2002</VehicleYear>
   </Vehicle>

  <Companies>
    <Company id="12" bestquote="true">
      <CampaignId>143</CampaignId>
      <Name><![CDATA[Highway Insurance]]></Name>
      <LogoUrl>image.png</LogoUrl>
      <AnnualPremium>493.35</AnnualPremium>
      <MonthlyPremium>44.81</MonthlyPremium>
         <MonthlyPremiumDetails>
           <Deposit>82.23</Deposit>
           <NumberOfPayments>10</NumberOfPayments>
           <TotalAmountPayable>530.33</TotalAmountPayable>
           <Apr>21.0</Apr>
         </MonthlyPremiumDetails>

       <RestrictionApplies>False</RestrictionApplies>

      <Urls>
      <Logo>image.png</Logo>
      <ReviewAndBuy></ReviewAndBuy>
      <KeyFacts></KeyFacts>
      </Urls>

    </Company>
</Companies>
</Calculation>
</Calculations>
</InsuranceCalculationResult>
</QuotesResult>
</QuotesResponse>
</soap:Body>
</soap:Envelope>
 
Code:
response.write xmlDoc.getElementsByTagName("CapId").item(0).text 
response.write "<br>"
response.write xmlDoc.getElementsByTagName("VehicleYear").item(0).text

etc
 
ok thanks - can you please tell me how to loop through the calculation nodes, will need to loop through and find a vehicle where capId = 12345
then loop through company nodes outputting each company

have googled and tried many things to get the hang of this - so appreciate your help

 
have tried

Code:
For Each Company in xml.SelectNodes("Company")
response.write Company.getElementsByTagName("Name").item(0).text
next
 
There is only 1 company in your sample XML, so i did it the direct way. If there are more then 1 you can list them thsi way:

Code:
Set oNodeList = xmlDoc.getElementsByTagName("Name")
For i = 0 TO (oNodeList.length -1)
  response.Write  oNodeList.item(i).text & "<br>"
Next

i recommend reading this tutorial:
 
Hi - am having probs again

Code:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="[URL unfurl="true"]http://schemas.xmlsoap.org/soap/envelope/"[/URL] xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xmlns:xsd="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema">[/URL]

<soap:Body>
<QuotesResponse xmlns="">
<QuotesResult>
<InsuranceCalculationResult xmlns="">

<CustomerDetailsForm>
    <Url></Url>
    <DisplayText>Change customer details</DisplayText>
</CustomerDetailsForm>

<Calculations>
  <Calculation>
   <Vehicle>
      <CapId>12345</CapId>
      <VehicleYear>2002</VehicleYear>
   </Vehicle>

  <Companies>
    <Company id="12" bestquote="true">
      <CampaignId>143</CampaignId>
      <Name><![CDATA[Highway Insurance]]></Name>
      <LogoUrl>image.png</LogoUrl>
      <AnnualPremium>493.35</AnnualPremium>
      <MonthlyPremium>44.81</MonthlyPremium>
         <MonthlyPremiumDetails>
           <Deposit>82.23</Deposit>
           <NumberOfPayments>10</NumberOfPayments>
           <TotalAmountPayable>530.33</TotalAmountPayable>
           <Apr>21.0</Apr>
         </MonthlyPremiumDetails>

       <RestrictionApplies>False</RestrictionApplies>

      <Urls>
      <Logo>image.png</Logo>
      <ReviewAndBuy></ReviewAndBuy>
      <KeyFacts></KeyFacts>
      </Urls>

    </Company>

   <Company id="12" bestquote="true">
      <CampaignId>143</CampaignId>
      <Name><![CDATA[Highway Insurance]]></Name>
      <LogoUrl>image.png</LogoUrl>
      <AnnualPremium>493.35</AnnualPremium>
      <MonthlyPremium>44.81</MonthlyPremium>
         <MonthlyPremiumDetails>
           <Deposit>82.23</Deposit>
           <NumberOfPayments>10</NumberOfPayments>
           <TotalAmountPayable>530.33</TotalAmountPayable>
           <Apr>21.0</Apr>
         </MonthlyPremiumDetails>

       <RestrictionApplies>False</RestrictionApplies>

      <Urls>
      <Logo>image.png</Logo>
      <ReviewAndBuy></ReviewAndBuy>
      <KeyFacts></KeyFacts>
      </Urls>

    </Company>
</Companies>
</Calculation>

 <Calculation>
   <Vehicle>
      <CapId>12345</CapId>
      <VehicleYear>2002</VehicleYear>
   </Vehicle>

  <Companies>
    <Company id="12" bestquote="true">
      <CampaignId>143</CampaignId>
      <Name><![CDATA[Highway Insurance]]></Name>
      <LogoUrl>image.png</LogoUrl>
      <AnnualPremium>493.35</AnnualPremium>
      <MonthlyPremium>44.81</MonthlyPremium>
         <MonthlyPremiumDetails>
           <Deposit>82.23</Deposit>
           <NumberOfPayments>10</NumberOfPayments>
           <TotalAmountPayable>530.33</TotalAmountPayable>
           <Apr>21.0</Apr>
         </MonthlyPremiumDetails>

       <RestrictionApplies>False</RestrictionApplies>

      <Urls>
      <Logo>image.png</Logo>
      <ReviewAndBuy></ReviewAndBuy>
      <KeyFacts></KeyFacts>
      </Urls>

    </Company>

   <Company id="12" bestquote="true">
      <CampaignId>143</CampaignId>
      <Name><![CDATA[Highway Insurance]]></Name>
      <LogoUrl>image.png</LogoUrl>
      <AnnualPremium>493.35</AnnualPremium>
      <MonthlyPremium>44.81</MonthlyPremium>
         <MonthlyPremiumDetails>
           <Deposit>82.23</Deposit>
           <NumberOfPayments>10</NumberOfPayments>
           <TotalAmountPayable>530.33</TotalAmountPayable>
           <Apr>21.0</Apr>
         </MonthlyPremiumDetails>

       <RestrictionApplies>False</RestrictionApplies>

      <Urls>
      <Logo>image.png</Logo>
      <ReviewAndBuy></ReviewAndBuy>
      <KeyFacts></KeyFacts>
      </Urls>

    </Company>
</Companies>
</Calculation>

</Calculations>
</InsuranceCalculationResult>
</QuotesResult>
</QuotesResponse>
</soap:Body>
</soap:Envelope>

As you can see there are multiple vehicles and within that there are multiple companies.
How do I loop through vehicles and select a certain ID then
display only the 1st company in the list.

The code below is what I was using but realised that it is just looping all companies and putting next to any vehicle regardless of ID

thanks again

Code:
 If xml.parseError.errorCode = 0 Then
 Set objLst = xml.getElementsByTagName("Calculation")
 noOfcompanies = objLst.length
 End If

 For i = 0 To (noOfcompanies - 1)

  Set objHdl = objLst.item(i)
  if xml.getElementsByTagName("VehicleId").item(i).text = x_vehicleid then
  x_ins_name = xml.getElementsByTagName("Name").item(i).text
  x_ins_logo = xml.getElementsByTagName("Logo").item(i).text
  x_ins_deposit = xml.getElementsByTagName("Deposit").item(i).text
  x_ins_NumberOfPayments = xml.getElementsByTagName("NumberOfPayments").item(i).text
  x_ins_TotalAmountPayable = xml.getElementsByTagName("TotalAmountPayable").item(i).text
  x_ins_Apr = xml.getElementsByTagName("Apr").item(i).text
  x_ins_ReviewAndBuy = xml.getElementsByTagName("ReviewAndBuy").item(i).text
  x_ins_KeyFacts = xml.getElementsByTagName("KeyFacts").item(i).text  
  x_ins_MonthlyPremium = xml.getElementsByTagName("MonthlyPremium").item(i).text 
  x_ins_AnnualPremium = xml.getElementsByTagName("AnnualPremium").item(i).text  

...display stuff

Exit for
end if
Next
[code]
 
edit: the xml is missing -
Code:
<VehicleId>12345</VehicleId>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top