Hello,
I am doing a script that needs to parse XML info that I get from a command line call. I am able to parse an xml when it comes from a file, but it doesn’t seem to work so well from with XML info is passed from a do shell script.
The following is just a portion of a script.
repeat with i in paragraphs of z
set theAssetXMl to (do shell script x & "dataapp getmd --xml /asset/" & theAsset) as string
my myREADXML(theAssetXMl)
display dialog mytitle
end repeat
on myREADXML(theAssetXMl)
tell application "System Events"
set mytitle to ""
set assetID to ""
set status to ""
set creationDate to ""
tell XML element "values" of XML element "sessions" of XML data theAssetXMl
repeat with thisElement in XML elements
tell thisElement
if value of XML attribute "fieldName" is "CUST_TITLE" then
set mytitle to its value as text
end if
end tell
end repeat
end tell
end tell
end myREADXML
So what happens is the script goes and shell script queries the commandline application for a certain Asset.
The commandline app returns XML data like so (I have shortened it, because it is a lot longer):
<?xml version="1.0"?> 2009-03-09T17:29:34Z Test Me Self PityAnyway, this currently doesn’t work. However if I start from an XML file first (like in the snippet below…also not the full script because it is very long), the XML parsing would work.
on myREADXML(myFile)
tell application "Finder"
set xmlFile to POSIX path of myFile
end tell
tell application "System Events"
set mytitle to ""
set assetID to ""
set status to ""
set creationDate to ""
tell XML element "getMdReply" of XML element "Dataapp" of XML file xmlFile
tell XML element "metadata" of XML element "entity"
repeat with thisElement in XML elements
tell thisElement
if value of XML attribute "fieldName" is "Title" then
set mytitle to its value as text
else if value of XML attribute "fieldName" is "Asset ID" then
set assetID to its value as text
else if value of XML attribute "fieldName" is "Status" then
set status to its value as text
else if value of XML attribute "fieldName" is "Creation Date" then
set creationDate to its value as text
end if
end tell
end repeat
end tell
end tell
end tell
end myREADXML
So, can you parse XML info without an actual XML file, just passed data?