Parsing the nodes of an xml document

Without seeing more of your script, and the XML source you’re working with, it’s hard to tell exactly what the problem is here or how to resolve it. Using “as tree” on a node really shouldn’t make any difference as it should be a tree already so I’m not sure what Erik is seeing there.

There are a couple of useful things to be aware of, though. First, there are currently some problems with the ‘node’ (xpath) expression functionality. Some node expressions throw an exception in the Mac version of eggPlant and don’t work at all. Other node expressions work differently on Windows than they do on the Mac. These problems are being addressed and we expect to have a fix ready in version 12.1 (in about a month or so).

In the meantime there is a good workaround for these issues and incompatibilities. For now, we strongly recommend using the DocumentTreeFromXML() function rather than ‘as tree’. This will create a full XML document internally (rather than a non-rooted node) which will provide these benefits:

  • all node expressions are supported (no exceptions thrown on Mac)
  • node expressions will work the same on all platforms (Mac, Windows, and Linux)
  • node expressions will work the same in future versions of eggPlant

The last point above is important because the future fix will (by necessity) change the behavior of at least some node expressions on at least one platform. We plan to make this change in behavior opt-in (only if you ask for it) at first, but it will likely become the default in a later release. Using DocumentTreeFromXML will save you from having to worry about these changes.

Getting back to your specific case, here is a simple script I wrote to test your scenario. Note that I’m using DocumentTreeFromXML here, and I believe everything is working as it should. Please feel free to expand on the very minimal xmlSource here if you have additional questions about specific node expressions or anything else about how this works.

set xmlSource to  {{
<document>
 <layout>
  <table>
  </table>
  <table>
  </table>
 </layout>
</document>

}}

put DocumentTreeFromXML(xmlSource) into xmlDoc 

put node "/document/layout" of xmlDoc into layoutNode
put layoutNode
put layoutNode is a tree
put "--------"
put node "/document/layout/table[@name='Windows']" of xmlDoc into tableNode
put tableNode
put "------------"

//  update tableNode and put the modified node back into the document
insert "<testCase>FirstTest</testCase>" into tableNode
put tableNode
set node "/document/layout/table[@name='Windows']" of xmlDoc to tableNode
put "=========="
put xmlDoc