• 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: XMLlib library
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: XMLlib library


  • Subject: Re: XMLlib library
  • From: "koenig.yvan" <email@hidden>
  • Date: Sun, 27 Apr 2014 11:54:38 +0200


Le 26/04/2014 à 14:57, Shane Stanley <email@hidden> a écrit :

On 26 Apr 2014, at 7:43 am, Wayne Melrose <email@hidden> wrote:

Can we call this closed now?

Not quite. In case they come to their senses, here's some sample ASObjC code for doing an XPATH query. Results are returned as an XML object containing matching nodes, and a list of any matching attributes.

use framework "Foundation"

on extractFrom:thePath matchingXPath:theQuery
set aURL to current application's |NSURL|'s fileURLWithPath:thePath -- make NSURL
set theXMLDoc to current application's NSXMLDocument's alloc()'s initWithContentsOfURL:aURL options:0 |error|:(missing value) -- make XMLDoc
set attStrings to {} -- where attributes will be stored
set theXMLOutput to current application's NSXMLElement's alloc()'s initWithName:"output" -- found nodes added to this
set {theResults, theError} to (theXMLDoc's nodesForXPath:theQuery |error|:(reference)) -- query
if theResults is not missing value then
repeat with aNode in (theResults as list)
aNode's detach() -- need to detach first
if aNode's |kind|() as integer = current application's NSXMLAttributeKind then -- see if it's an attribute or node
set end of attStrings to (aNode's stringValue()) as text
else
(theXMLOutput's addChild:aNode) -- add node
end if
end repeat
return {(theXMLOutput's XMLStringWithOptions:(current application's NSXMLNodePrettyPrint)) as text, attStrings} -- change options to suit
else
return missing value
end if
end extractFrom:matchingXPath:

No plug-ins, nothing up your sleeves...

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>

Hello Shane

My understanding is that Wayne's customer refuse every file external to the script itself.

An OSAX is external because given what Wayne explained his script is in fact made of several ones so using the OSAX embedded in one of the scripts bundle is too constraining.
A faceless application is external.
Your library is external which must be installed in : "~/Library/Script Libraries/"

My own choice would be to include in the first script a piece of code installing the library if it is not already available.

Here is a quick and dirty sample code :

set libraryName to "my Lib.scptd"
set DestFolder to ((path to library folder from user domain as text) & "Script Libraries:")
tell application "System Events"
set isInstalled to exists disk item libraryName of folder DestFolder
end tell
if not isInstalled then
# The library is stored in the subfolder Contents of the script bundle (or package if it's saved as an application)
set quotedSourcePath to quoted form of POSIX path of ((path to me as text) & "Contents:" & libraryName)
do shell script "ditto " & quotedSourcePath & space & quoted form of POSIX path of (DestFolder & libraryName)
end if

Yvan KOENIG (VALLAURIS, France) dimanche 27 avril 2014 11:54:34


 _______________________________________________
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

  • Follow-Ups:
    • Re: XMLlib library
      • From: Paul Berkowitz <email@hidden>
    • Re: XMLlib library
      • From: Shane Stanley <email@hidden>
References: 
 >Re: XMLlib library (From: Chris Paveglio <email@hidden>)
 >Re: XMLlib library (From: waynemelrose <email@hidden>)
 >Re: XMLlib library (From: Shane Stanley <email@hidden>)
 >Re: XMLlib library (From: G Wood <email@hidden>)
 >Re: XMLlib library (From: Wayne Melrose <email@hidden>)
 >Re: XMLlib library (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: XMLlib library
  • Next by Date: Re: XMLlib library
  • Previous by thread: Re: XMLlib library
  • Next by thread: Re: XMLlib library
  • Index(es):
    • Date
    • Thread