How to get path of an XML tag containing a specific value?


I’m collecting tweets in an XML file, using this format:

		<STATUS>Artists working as artists</STATUS>
		<STATUS>Literally same</STATUS>

How can I find the XML path of a particular TWEET if I know its URL? It’s not clear to me from the ofXML example how to do this. I’m using an ofXML object, by the way.


I don’t think there’s a way of searching for a particular value (I could be wrong about this), so you’d have to iterate through the list. something like:

if (xml.exists("TWEET")) {
    do {
        string url = xml.getValue<string>("URL");
        if (url == URL_TO_SEARCH_FOR) {
            string status = xml.getValue<string>("STATUS");
            string image = xml.getValue<string>("IMAGE");
    while (xml.setToSibling());

if you need it to go faster, you can run through it once and put all the entries into a map.

1 Like

Thank you @genekogan! I was hoping there was some way to do it besides linear search, but this looks viable for now – I may use map as you suggest.