0

I want to select the URL value (5.jpg) of the node that has Type=IMAGE and Key=XS ps: the order of the Images nodes is random, so I can't just select the nth node.

What I tried but fails:

Dim root As XmlNode = objXML.DocumentElement
Dim nodeList As XmlNodeList = root.SelectNodes("/Products/Product")

nodeList(i).SelectSingleNode("//URL[../Type='IMAGE' and ../Key='XS']").InnerText

and

nodeList(i).SelectSingleNode("/Images/[Type=IMAGE] and /Images/[Key=XS]").ChildNodes(0).SelectSingleNode("URL").InnerText

<Products>
    <Product>
        <Id>9200000093797005</Id>
        <Images>
            <Type>IMAGE</Type>
            <Key>XS</Key>
            <Url>5.jpg</Url>
        </Images>
        <Images>
            <Type>IMAGE</Type>
            <Key>S</Key>
            <Url>1.jpg</Url>
        </Images>
        <Images>
    </Product>
</Products>

Already checked here:

1 Answer 1

1

You are almost correct in your attempts. I think the use of the XmlNodeList is what was causing your problems. If you switch to using an XmlNode and SelectSingleNode then you would've had the answer sooner.

    Dim root As XmlNode = objXml.DocumentElement
    Dim node As XmlNode = root.SelectSingleNode("//Products/Product/Images[Type='IMAGE' and Key='XS']/Url")
    Dim url As String = node.InnerText
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.