List all XML nodes
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 115
- Joined: Thu Mar 06, 2014 9:29 am
- Location: UK
List all XML nodes
Hello all,
Is there a simple way to separately list out the paths to all nodes, regardless of depth, in an XML document?
revXMLMatchingNode does what I want, but unfortunately it stops at the first match and I need all the nodes with a given attribute value. The source XML often has multiple siblings of the same name with the attribute value.
Maybe the answer lies with revXMLEvaluatePath, but the dictionary entry on that one isn't exactly clear.
Is there a simple way to separately list out the paths to all nodes, regardless of depth, in an XML document?
revXMLMatchingNode does what I want, but unfortunately it stops at the first match and I need all the nodes with a given attribute value. The source XML often has multiple siblings of the same name with the attribute value.
Maybe the answer lies with revXMLEvaluatePath, but the dictionary entry on that one isn't exactly clear.
Re: List all XML nodes
I *think* the easiest might be a repeat loop, something like (not tested)
Code: Select all
put "" into (variable or field used as container)
repeat for each revXMLMatchingNode(your parameters)
put (value looked for) & cr after (variable or field)
end repeat
-
- Posts: 115
- Joined: Thu Mar 06, 2014 9:29 am
- Location: UK
Re: List all XML nodes
Thanks for the reply. That makes sense... and that was exactly how I ran my first attempt. But the issue with revXMLMatchingNode is that it only returns the first matching node. So if I have
Root/nodeX/nodeY and
Root/nodeX/nodeY
both with the same attribute and value, only the path to the first will be returned. But I need to get a different attribute value from both nodes and combine it later on.
I basically just need a version of revXMLMatchingNode that returns a list of all matching nodes. Should I copy the whole tree and just delete the matched nodes from the copy as I go?
Root/nodeX/nodeY and
Root/nodeX/nodeY
both with the same attribute and value, only the path to the first will be returned. But I need to get a different attribute value from both nodes and combine it later on.
I basically just need a version of revXMLMatchingNode that returns a list of all matching nodes. Should I copy the whole tree and just delete the matched nodes from the copy as I go?
-
- Posts: 115
- Joined: Thu Mar 06, 2014 9:29 am
- Location: UK
Re: List all XML nodes
Guess I'll just use an XPATH expression unless someone has a better idea. I was hoping to avoid those though as they seem a bit temperamental in LC (causing LC to close without saving and without explanation if the xpath expression is formatted incorrectly in v8.1).
Re: List all XML nodes
I'm sorry it took so long to reply. Unfortunately, I don't do much wihth xml (read that nothing), so short of your reply nothing is hitting me off the top of my head. Hopefully one of the xml'ers will chime in shortly
-
- Posts: 115
- Joined: Thu Mar 06, 2014 9:29 am
- Location: UK
Re: List all XML nodes
Got it... you wouldn't think so from the name, but the answer lies in revXMLChildContents.
I'll definitely be putting the lines into an array before running the repeat loop above, but this demonstrates the concept.
Code: Select all
function listNodes pContent
put revXMLCreateTree(pContent,false,true,false) into tTreeID
put revXMLRootNode(tTreeID) into tRoot
put revXMLChildContents(tTreeID,tRoot,COMMA,CR,"full",-1) into tNodesList
repeat with n = 1 to the number of lines of tNodesList
put item 1 of line n of tNodesList into line n of tNodesList
end repeat
revXMLDeleteAllTrees
return tNodesList
end listNodes
I'll definitely be putting the lines into an array before running the repeat loop above, but this demonstrates the concept.
Last edited by theotherbassist on Sun Dec 10, 2017 2:36 pm, edited 1 time in total.
Re: List all XML nodes
Actually, that makes sense to me. I probably should have looked in the dictionary a bit longer <sigh> but congrats on figuring it out