0

I am trying to access the longitude value (-1.914) from this xml snippet where itemfileUID = 2000044 using an xpath query in vba [via Set latitudes = oXMLFile.SelectNodes("//ViewCoordinates[itemFileUID = '2000044']/ViewCoordinatePair[@name = 'latitude']/@value").] Can anyone help?

I have searched and searched but not found a way to find an attribute value based upon the contents of an element in the same node.

Thanks Tom

<schema>
    <view>
        <ViewCoordinatesList>
            <ViewCoordinates>
                <itemFileUID>2000044</ItemFileUID>
                <ViewCoordinatePair name="longitude" value="-1.91496237"/>
                <ViewCoordinatePair name="latitude" value="53.70811065"/>
                <ViewCoordinatePair name="height" value="136.06"/>
                <ViewCoordinatePair name="yaw" value="168.083809"/>
            </ViewCoordinates>
        </ViewCoordinatesList>
    </view>
</schema>
3
  • Note that you are asking latitude, but mentioning -1.914 which is longitude in your sample. Commented Aug 4, 2016 at 16:00
  • @alecxe apologies - updated now to longitude Commented Aug 4, 2016 at 16:01
  • vba snipped added above linked to @alecxe response Commented Aug 4, 2016 at 16:20

2 Answers 2

2

Use the following-sibling axis:

//itemFileUID[. = '2000044']/following-sibling::ViewCoordinatePair[@name = 'longitude']/@value

Or, checking the parent:

//ViewCoordinates[itemFileUID = '2000044']/ViewCoordinatePair[@name = 'longitude']/@value
Sign up to request clarification or add additional context in comments.

4 Comments

thanks for this - I am trying to msgbox this value but failing?
@TomH okay, failing how? Where are you running this in? Thanks.
@alexce - vba - this returns a IXMLDOMSelection and I don't know how to access the string... this isn't my field as you can guess...
@TomH not familiar with xml parsing with VBA unfortnately, but I suspect you should match the nodes first omitting the /@value part at the end. Then, when you have a node, get the value of value attribute/property.
0

This was the solution:

Set latitude = oXMLFile.SelectNodes("/schema/View/ViewCoordinatesList/ViewCoordinates[ItemFileUID = '2000044']/ViewCoordinatePair[@name = 'longitude']")
MsgBox latitude(0).getAttribute("value")

Thanks for people's help

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.