Click here to Skip to main content
15,388,688 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to retrieve the values of xml elements which are located under sub nodes in the xml file (see link in the code). I am after the following elements: price, productUrl but these are under offers/offer namespace. how do I achieve this? I tried adding it to the XmlNodeList but then I will miss the other elements directly under product. thanks

VB
Dim doc As New XmlDocument()
doc.Load("http://api.tradedoubler.com/1.0/products.xml?token=96CC0E0A10851500F10431D64EC5585BFC8597DF")

Dim nsManager As New XmlNamespaceManager(doc.NameTable)
nsManager.AddNamespace("ns1", "urn:com:tradedoubler:pf:model:xml:output")
nsManager.AddNamespace("ns2", "urn:com:tradedoubler:pf:model:xml:common")

Dim nodes As XmlNodeList = doc.SelectNodes("//ns1:products/ns1:product", nsManager)

Dim dataSource As IEnumerable
dataSource = From node As XmlNode in nodes
             Select Name = node.SelectSingleNode("ns2:name", nsManager).InnerText, _
             Description = node.SelectSingleNode("ns2:description", nsManager).InnerText, _
             Image = node.SelectSingleNode("ns2:productImage", nsManager).InnerText

rpMyRepeater.DataSource = dataSource
rpMyRepeater.DataBind()


My XML looks like this:

XML
<asp:repeater id="rpMyRepeater" runat="server>
<HeaderTemplate>
    <table border="0">
</HeaderTemplate>
<ItemTemplate>
    <tr style="background-color:FFECD8">
        <td>
            <%# Eval("Name") %&>
        </td>
        <td>
            <%# Eval("Description") %&>
        </td>
        <td>
            <asp:image runat="server"
                ImageUrl='<%# Eval("Image") %>'
            />
        </td>
    </tr>
</ItemTemplate>
<FooterTemplate>
    </table>
</FooterTemplate>
</asp:repeater>
Posted
Updated 7-Sep-15 5:06am
v2
Comments
Maciej Los 7-Sep-15 10:58am
   
Xml sample structure and data, please!
hm9 7-Sep-15 11:13am
   
The xml file is in this link:

http://api.tradedoubler.com/1.0/products.xml?token=96CC0E0A10851500F10431D64EC5585BFC8597DF"

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