kczx3 wrote:Your XPath expression would be something like this: /breakfast_menu/food[@style = "meal"]/price. If instead you want the entire food node where the style is "meal", then just chop off the "/price".
An example of using XPath with the above XML data and printXML function.
Code: Select all
MsgBox % printXML(xDoc.SelectNodes("/breakfast_menu/food[@style = ""meal""]/price"))
Note you have to two quote (""meal"") the quotes inside quotes for AHK.
If also important to realize this is SelectNodes with an 's'. It is going to return a collection of nodes as you are not guaranteed a unique query result.
To get the actual value of price you could do:
Code: Select all
xNodes := xDoc.SelectNodes("/breakfast_menu/food[@style = ""meal""]/price")
MsgBox % xNodes.Item(0).childNodes.Item(0).nodeValue
Again, realizing you are dealing with collections. The node could have two or more prices. For example the first one being the regular price and second being a sale price. It would be nice to give them attributes to distinguish something like that but XML does not require it. This is one of the things that makes XML different from a typical array structure. There could be a thousand prices that are just a running history of every price of ever one of this item sold where the 5th price is the 5th back item sold.
This is working with the XPath given. In reality it would be better to use a more complex needle to get the specific nodes and values. XPath is kind of like an RegEx needle. It is its own little language for filtering XML.
FG