Wow.
Thanks for that great reply. Turned my jumbled mess into a lean, mean machine. Not to mention I understand how to use XMLLib correctly now. Thanks.
A few things for the benefit of someone that may have the same question now or in the future and come across this:
My XML looks like this:
<?xml version="1.0"?> <session> <values> <value id="PA_MD_CUST_ANGLE"> <string xml:space="preserve">ANGLE</string> </value> <value id="PA_MD_CUST_SCENE"> <string xml:space="preserve">SCENE</string> </value> <value id="CUST_SIZE"> <bigint>4036221402</bigint> </value> <value id="PA_MD_CUST_CLIPIT_ANNOTATION_REQUEST"> <bool>true</bool> </value>
...and so on...
And, I wanted to remove a number of <value>...</value> defined by value id's as: set fieldsToRemove to {"FIELD_NAME_ONE", "FIELD_NAME_TWO",...}
I ended up with:
set XMLtext to XMLOpen tempXML set the_root to XMLRoot XMLtext repeat with j from 1 to count of items in fieldsToRemove set theXMLPath to "values[1]/value[@id=" & quoted form of (item i of fieldsToRemove) & "]" XMLRemove (XMLXPath the_root with theXMLPath) XMLSave XMLtext end repeat XMLClose the_root
I struggled a bit with getting the XMLXPath argument correct (quotes and such) but it works as shown.
Thanks again Emmanuel and everyone.
|