• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: System Events XML Suite - how to add / delete elements and attributes?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: System Events XML Suite - how to add / delete elements and attributes?


  • Subject: Re: System Events XML Suite - how to add / delete elements and attributes?
  • From: Geoff Sheehan <email@hidden>
  • Date: Wed, 23 Jul 2008 16:58:07 +1000

Hi

It is a bit difficult finding AppleScript XML examples, it seems to me quite a few are scared off and end up going with the LateNightSoftware tool.

With that said, after much searching, teeth gnashing I managed to sort a few things out with XML and subsequently posted at macsripter.net to make sure others could benefit from the examples I had worked out.

http://bbs.macscripter.net/viewtopic.php?id=24174 may help to get you started.

If you need more - give me a "hoy"

Best Regards
Macpomme

www.macpomme.com


On 23/07/2008, at 4:33 PM , Richard Rönnbäck wrote:

Philip,

You may well be right. I have used xsltproc in the past and it has worked
flawlessly, and as you say one should be able to dynamically generate an xsl
file that adds/deletes/changes whatever one wants


And in this case, where I decide on the XML syntax that should be pretty
straightforward


I'll let you all know what I come up with, in case someone else has similar
needs.


Thanks


------------------------------------------------- Richard Rönnbäck Publishing-konsult email@hidden Helsingörsgatan 24 164 44 KISTA SWEDEN +46 (0) 8 444 06 08 +46 (0) 70 774 06 08 -------------------------------------------------


Från: Philip Aker <email@hidden>
Datum: Tue, 22 Jul 2008 16:51:42 -0700
Till: Richard Rönnbäck <email@hidden>
Kopia: Scriptease <email@hidden>
Ämne: Re: System Events XML Suite - how to add / delete elements and
attributes?

On 08-07-21, at 11:04, Richard Rönnbäck wrote:

I have spent the last on trying to find some example of how to Edit
XML with System Event's XML Suite, to no avail. I am aware of the
Excellent XML tools from Satimage and LateNightSoftware, but
unfortunately I can't use them for the current project

So far this is about what I have managed to find (through Google),
in terms of creating something at all:


set myResult to do shell script "curl 'http://galacticaa.net/widget/feed.php?
ts=1171327909000&v=2.1'"

tell application "System Events"
   set myData to make new XML data with properties {text:myResult}
   --set {EpNum, EpName, EpType, EpIm, EpM, EpD, EpY, EpFul, EpSum,
NewVer, UpgradeMessage} to value of XML elements of XML element
"galacticaa" of result
end tell

But how on earth do I create a new element at end somewhere in the
structure, or delete one for that matter? I am really lost and would
greatly appreciate a working example.

I don't know much about System Events XML but if it's awkward to include third party OSAX then xsltproc <x-man-page://xsltproc> is probably the best way to go. In fact the Smile OSAX is built on the same libraries (libxml and libxslt) xsltproc uses and it's used by a lot of Apple products.

What you would do is include your .xsl file in a script bundle (or
create it dynamically). xsltproc is very fast.

Here's the Terminal call I use to transform the received XML from the
'curl' call above. It elides the 'upgrade_message' element and puts a
new 'info' element in its place:

curl 'http://galacticaa.net/widget/feed.php? ts=1171327909000&v=2.1'
2>/dev/null | xsltproc add.xsl -

You will have to change the path of "add.xsl".


### <?xml version="1.0" encoding="utf-8"?>

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
<xsl:output indent="yes"/>

<xsl:template match="*|@*">
<xsl:choose>
<xsl:when test="name()='upgrade_message'">
<xsl:element name="info">
<xsl:attribute name="version">
<xsl:value-of select="'1.2.3'"/>
</xsl:attribute>
<xsl:text>Too bad about Adama. Those paramedics were the enemy in
disguise.</xsl:text>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="/galacticaa">
<xsl:copy>
<xsl:apply-templates select="*|@*"/>
</xsl:copy>
</xsl:template>

</xsl:transform>
###

Philip Aker
echo email@hidden@nl | tr a-z@. p-za-o.@

Democracy: Two wolves and a sheep voting on lunch.

_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (applescript- email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users


This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. AppleScript-Users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
References: 
 >Re: System Events XML Suite - how to add / delete elements and attributes? (From: Richard Rönnbäck <email@hidden>)

  • Prev by Date: Re: System Events XML Suite - how to add / delete elements and attributes?
  • Next by Date: collect set of responses messages
  • Previous by thread: Re: System Events XML Suite - how to add / delete elements and attributes?
  • Next by thread: Re: System Events XML Suite - how to add / delete elements and attributes?
  • Index(es):
    • Date
    • Thread