I’m trying to use XML tools in a script to extract attributes from an XML file but am only able to do it by parsing the XML, then repeating through the parsed contents. I was hoping there was a way to extract the attributes of the record I am looking for without repeating through until my search criteria has been met.
Mac OS 9.2 AS 1.8.3
XML Tools 2.5 (Latenite SW)
Here’s how I have it working now:
--these are what I am looking for, I want to get the top and left attributes of the xml element whose attributes match this criteria
set strXMLLayout to "_006"
set strLine to "line1"
--I've simplified my xml document by just including it in the script as text for posting purposes.
set theXML to "<layouts>
<layout is ="_004" line_num="line1" top="483" left="199" type="AD"/>
<layout is ="_005" line_num="line1" top="480" left="198" type="AD"/>
<layout is ="_005" line_num="line2" top="390" left="222" type="S"/>
<layout is ="_006" line_num="line1" top="481" left="199" type="AD"/>
<layout is ="_006" line_num="line2" top="397" left="237" type="S"/>
</layouts>"
(*the only way I seem to be able to do this is
to repeat through the contents of the parsed XML
and compare the "is" and "line_num" attributes. Is
there any way to just get the item of the parsed
xml whose "is"="_006" and whose line_num="line1"?*)
set xmlParsedBox to XML contents of (parse XML theXML)
repeat with thisElement in xmlParsedBox
set xmlLayout to (|is| of XML attributes of thisElement)
if strXMLLayout = (|is| of XML attributes of thisElement) then
set xmlLine to (line_num of XML attributes of thisElement)
if strLine = (line_num of XML attributes of thisElement) then
set strTop to (top of XML attributes of thisElement)
set strLeft to (|left| of XML attributes of thisElement)
set strStyle to (|type| of XML attributes of thisElement)
exit repeat
end if
end if
end repeat
Anyone out there using XML tools know the syntax I am missing to be able to just extract the record I’m looking for? I’ve tried everything in the variation of:
set myTop to (top of xml attributes of xml element (whose |is| of xml attributes="_006" amd line_num of xml attributes="line1"))of xmlParsedBox
--does not compile
Any help would be super!
Thanks in advance.