Processing XML - Working, but can't get sub items?

JoeyMe

New member
Joined
Sep 21, 2013
Messages
2
Programming Experience
1-3
Hi,

I am using the Ebay API to get lists of items. I can get the item ID and Title easy enough, but not the price etc as the XML sheet displays these at sub items.

I need to get the info listed under "sellingStatus/currentPrice" on each item.

Here is the XML:

HTML:
<?xml version="1.0" encoding="UTF-8"?>
<findItemsByKeywordsResponse>
   <ack>Success</ack>
   <version>1.12.0</version>
   <timestamp>2013-09-21T16:24:53.632Z</timestamp>
   <searchResult count="1">
      <item>
         <itemId>130996071573</itemId>
         <title>Microsoft Xbox 360 S 250 GB Glossy Black Console (PAL)   RGH</title>
         <globalId>EBAY-GB</globalId>
         <primaryCategory>
            <categoryId>139971</categoryId>
            <categoryName>Consoles</categoryName>
         </primaryCategory>
         <sellingStatus>
            <currentPrice currencyId="GBP">100.0</currentPrice>
            <convertedCurrentPrice currencyId="GBP">100.0</convertedCurrentPrice>
            <bidCount>0</bidCount>
            <sellingState>Active</sellingState>
            <timeLeft>P0DT0H34M14S</timeLeft>
         </sellingStatus>
         <listingInfo>
            <bestOfferEnabled>false</bestOfferEnabled>
            <buyItNowAvailable>false</buyItNowAvailable>
            <startTime>2013-09-18T17:00:08.000Z</startTime>
            <endTime>2013-09-21T16:59:07.000Z</endTime>
            <listingType>Auction</listingType>
            <gift>false</gift>
         </listingInfo>
      </item>
   </searchResult>
</findItemsByKeywordsResponse>

And the code I am using to get the ID number and Title:

VB.NET:
    Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim xmlDoc As New Xml.XmlDocument

        xmlDoc.Load("http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.0.0&SECURITY-APPNAME=MangoOnl-5334-482c-b66b-2709f95583df&GLOBAL-ID=EBAY-GB&keywords=XBox-360&sortOrder=StartTimeNewestpaginationInput.entriesPerPage=3")

        Dim root As Xml.XmlNode = xmlDoc("findItemsByKeywordsResponse")


        For Each itemNode As Xml.XmlNode In root("searchResult")

            Dim ID As String = itemNode("itemId").InnerText
            Dim Title As String = itemNode("title").InnerText
            'Dim Price As String = itemNode("currentPrice").InnerText


            ListView1.Items.Add(New ListViewItem(New String() {ID, Title}))
        Next

    End Sub


Any ideas would be great.

Thanks
 
I tried the following code, but it returns not just the price, but all of the info in the node:

VB.NET:
Dim Location As String = itemNode.Item("sellingStatus").InnerText

Returned: 100.0100.00ActiveP0DT0H34M14S
 
Hi,

Its just a case of navigating to the correct Node Element within the current Node that you are working with. Have a look at this for an example:-

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  Dim myXMLDoc As New XmlDocument
  myXMLDoc.Load(IO.Path.Combine(Application.StartupPath, "XMLFile1.xml"))
 
  For Each searchResult As XmlNode In myXMLDoc.DocumentElement.SelectNodes("searchResult")
    Dim myTitle As String = searchResult.SelectSingleNode("item/title").InnerText
    Dim myPrice As Decimal = CDec(searchResult.SelectSingleNode("item/sellingStatus/currentPrice").InnerText)
 
    MsgBox(String.Format("The Current Product is {0} with a Current Price of {1}", myTitle, myPrice.ToString("c")))
  Next
End Sub


Hope that helps.

Cheers,

Ian

BTW, just a side note, be careful of case sensitivity when accessing node elements in this way.
 

Latest posts

Back
Top