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

Dim doc As New XmlDocument()

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

My XML looks like this:

<asp:repeater id="rpMyRepeater" runat="server>
    <table border="0">
    <tr style="background-color:FFECD8">
            <%# Eval("Name") %&>
            <%# Eval("Description") %&>
            <asp:image runat="server"
                ImageUrl='<%# Eval("Image") %>'
Updated 7-Sep-15 5:06am
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:"

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