Using multiple Xpath queries to search XML

REALbasic

New Member
I'm trying to write a simple script to search an XML file containing performance event information. A simplified version of the file is as follows:\[code\]<event> <title>Big Event 1</title> <tags>hip-hop</tags> <ticketed>YES</ticketed></event><event> <title>Big Event 2</title> <tags>jazz</tags> <ticketed>NO</ticketed></event><event> <title>Big Event 3</title> <tags>jazz</tags> <ticketed>YES</ticketed><event>\[/code\]Using SimpleXml and Xpath I'm able to easily search any of the nodes I want. However, the problem comes when I want to search on two parameters, i.e. "give me all the events tagged jazz that are ticketed". My idea was to pass the loaded XML through an Xpath query for each desired parameter. However, I now realise that the second query will fail, because what was returned from the first query was not a SimpleXMLObject, but an array containing SimpleXMLObjects that match. EDIT - here's the questionHow do I search the XML with multiple parameters which may or may not be present in each case. Some example queries.
  • tags contain hip-hop
  • tags contain hip-hop and is ticketed
  • title contains "3" and is not ticketed
I thought I could pass the SimpleXMLObject through an XPath query per required search parameter, but this doesn't work, because the returned value from the first XPath query is an Array, not a SimpleXmlObject.
 
Back
Top