try this, “path:to:file.xml” is the full HFS path to the xml file
tell application "System Events"
set XMLFile to XML file "path:to:file.xml"
set numberOfPages to value of XML element "egGr:nrpages" of XML element "rdf:Description" of XML element "rdf:RDF" of XML element 1 of contents of XMLFile
end tell
set fichier_file to (path to desktop as text) & "file.xml"
tell application "System Events"
set XMLFile to XML file fichier_file
set numberOfPages to value of XML element "egGr:nrpages" of XML element "rdf:Description" of XML element "rdf:RDF" of XML element 1 of contents of XMLFile
end tell
and got :
→ error number -1728 from XML element “rdf:RDF” of XML element 1 of XML file “Macintosh HD:Users:yvankoenig:Desktop:file.xml”
So I decided to use brute force :
set fichier_file to (path to desktop as text) & "file.xml"
read file fichier_file
item 2 of my decoupe(result, "<egGr:nrpages>")
item 1 of my decoupe(result, "<")
--> "3"
#=====
on decoupe(t, d)
local oTIDs, l
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set l to text items of t
set AppleScript's text item delimiters to oTIDs
return l
end decoupe
#=====
The problem was not the forgotten lines which I added.
It was that after copying from the original mail and pasting in TextEdit, many space characters were embedded as “C2 A0”. Opening the file with TextWrangler displayed the file correctly indented but when I saved, the surprising characters weren’t replaced by standard spaces and the script was fooled. I used Hexedit to replace the “C2 A0” by “20” and now the Stefan’s script behaves flawlessly.
Just a request to Stefen and David : may you correct the typo which I made in my original message ? A letter s is wrongly replacing the wanted d. This way everybody would read « tested » as it was supposed to do.
Glad you found your problem. Weird that you system replaces all spaces by non-braking spaces when you paste. At least it’s not default system behavior as it for text edit (maybe a browser issue). Just to be clear, the error you mentioned in post #3 is just because you copied and pasted the code from TS the wrong way!?