Help Retrieving Xml Elements In Vb

I managed to retrieve the top elements in an xml file (see link in the code) and it works but I want to retrieve elements deeper in the xml file and more particularly these 2 elements: price, productUrl but these are under offers/offer namespace, but in the code below I only managed to retrieve the elements under products/product namespace. Can anyone please help with the code below so I can retrieve the 2 elements: price, productUrl ? Thanks

indent preformatted text by 4 spaces
Dim doc As New XmlDocument()
doc.Load("http://api.tradedoubler.com/1.0/products.xml?token=_token_")

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:

<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>

@hm9, FYI, I formatted your post and removed the token so it doesn’t get spread around. Next time please be more careful of what you copy and paste onto the Internet.

1 Like

Thanks cpradio

Also, when I get back to work tomorrow, I’m going to open this open again to see if I can give you any tips. I’d try it right now, but its been a long day and having Visual Studio in front of me tomorrow will surely help me lead you in the right direction.

This is what I believe you are wanting

		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, _
		Price = node.SelectSingleNode("ns1:offers/ns1:offer/ns1:priceHistory/ns2:price", nsManager).InnerText, _
		ProductUrl = node.SelectSingleNode("ns1:offers/ns1:offer/ns2:productUrl", nsManager).InnerText

Yes thank you. regarding the url for productUrl, How do I make it so it can be clicked something like this but not sure about the syntax

<a href =
“<%# Eval(“ProductUrl”) %>”>Go to Link

may be something like this:

<a href = "<%# Eval("ProductUrl") %>"> go to link</a>

Yeah, that looks right to me.

Thanks again

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.