way to get XML attributes
way to get XML attributes
- Subject: way to get XML attributes
- From: Darwin Zins <email@hidden>
- Date: Mon, 10 Mar 2003 20:56:22 -0600
I am using the XML tools from Late Night Software to parse an xml file.
The problem I am having is that the data in the xml file is all stored
as attributes and each element may have a different number of
attributes. Like they should mostly all have LastName and FirstName,
but some won't have BusinessPhone or BusinessFax. Is there a way to go
through all the attributes that are there and then determine the label
and value of the individual attribute?
This is what I have so far, but I don't want to have to do the try on
every single possible field, I tried to create a simple procedure, but
that doesn't work.
Thanks in advance for any help,
Darwin
-- Parse the XML File
set z_contacts to (((path to current user folder) as text) &
folderZOSXSync & ":addressbook.xml")
open for access file z_contacts returning inputFile
set theXMLSource to read inputFile
close access inputFile
set theXML to parse XML theXMLSource
repeat with anItem in XML contents of theXML
display dialog XML tag of anItem
if XML tag of anItem is equal to "Contacts" then
repeat with aSubItem in XML contents of anItem
getAttribute(|LastName|, aSubItem) -- does not work
try
display dialog |FirstName| of XML attributes of aSubItem
on error number -1728
end try
try
set z_business_phone to |BusinessPhone| of XML attributes of
aSubItem
on error number -1728
end try
end repeat
end if
end repeat
on getAttribute(theItem, theAttribute)
try
display dialog theItem in XML contents of theAttribute
on error number -1728
end try
end getAttribute
On Saturday, March 8, 2003, at 01:11 AM, Marc K. Myers wrote:
>
I wrote a little droplet to display file information. It contains
>
this code:
>
>
on run
>
--display dialog "This script functions only as a droplet" buttons
>
{"Cancel"} default button 1
>
open ((choose file) as list)
>
end run
>
>
on open(inItems)
>
repeat with anItem in inItems
>
if last character of (anItem as text) is not ":" then
>
report(anItem as alias)
>
end if
>
end repeat
>
end open
>
>
on report(theFile)
>
set theInfo to info for theFile
>
tell theInfo
>
set theName to name
>
set creDate to creation date
>
set modDate to modification date
>
set fType to file type
>
set fCreate to file creator
>
set bAlias to alias of theInfo
>
end tell
>
if bAlias then
>
set aliasMsg to return & return & "This file is an alias"
>
else
>
set aliasMsg to ""
>
end if
>
activate
>
display dialog theName & return & return & ,
>
"Creation date: " & formDate(creDate) & return & ,
>
"Mod date: " & formDate(modDate) & return & ,
>
"File type: " & fType & return & ,
>
"File creator: " & fCreate & ,
>
aliasMsg
>
end report
>
>
When I execute it from Script Editor the "This file is an alias"
>
message is displayed. When I execute it as a droplet using the same
>
alias file it isn't. I can't debug it because it works just fine in
>
Script Editor. Has anyone got a clue as to why I'm getting this
>
behavior? I'm running the standard AppleScript installation under OS
>
10.2.4.
>
>
Marc [03/08/03 2:11:25 AM]
>
_______________________________________________
>
applescript-users mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/applescript-users
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.