Re: System Events XML Suite - how to add / delete elements and attributes?
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: Richard Rönnbäck <email@hidden>
- Date: Wed, 23 Jul 2008 08:33:33 +0200
- Thread-topic: System Events XML Suite - how to add / delete elements and attributes?
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 (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden