• 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: Help parsing XML file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help parsing XML file


  • Subject: Re: Help parsing XML file
  • From: Emmanuel <email@hidden>
  • Date: Sat, 8 Mar 2008 01:57:30 +0100

Title: Re: Help parsing XML file
At 1:11 PM -0600 3/7/08, Jim Skibbie wrote:
<?xml version="1.0" encoding="UTF-8"?>
<FMPDSORESULT xmlns="http://www.filemaker.com/fmpdsoresult">
    <ERRORCODE>0</ERRORCODE>
    <DATABASE>ColorTable</DATABASE>
    <LAYOUT>XMLLayout</LAYOUT>
    <ROW MODID="4" RECORDID="12915141">
        <ValueColor01>Process</ValueColor01>
        <ValueColor02>Process</ValueColor02>
[...]
Here's the code I'm using, but I don't get any nodes returned for the variable x.
set XMLfile to alias "Macintosh HD:tempscripttext.xml"

set theDoc to XMLOpen XMLfile
set the_root to XMLRoot theDoc

set x to XMLXPath the_root with "/FMPDSORESULT/ROW/ValueColor01"

You're the victim of two very common mistakes.

1/ The document's root is that first node which is the whole, "FMPDSORESULT" for you, so you must not start the XPath with that node. In fact the root's [tag] name is transparent.

2/ You know that joke, the Creator made France, then the day after he thought no, good food and wine, smooth weather, gorgeous mountains, valleys and seasides, that's too much good stuff in one single place, I'll make the French now. One day w3.org made XML, a very natural and handy standard, then they said, it would be too simple, let's geek it up, let's make namespaces.

Of course namespaces do ensure the universality of XML, on the other hand you have to pay for that even when you don't care. Enough philosophy now, either you get rid of your namespace (the attribute of the root node) by brute force, I mean in the text (don't even try in XML), or you have to handle it. Handling it means, telling XMLXPath what "ROW" you mean. When you think "ROW" you don't really mean "ROW", you mean "ROW in the context of http://www.filemaker.com/fmpdsoresult". So, you are required to provide an (arbitrary) code for your namespace, and to prefix your tag names with that code.

Whence:

set x to XMLXPath the_root with "fred:ROW/fred:ValueColor01" namespace {nsprefix:"fred", nsurl:"http://www.filemaker.com/fmpdsoresult"}
  --  {«data XMLR5300000030BF001987560000», «data XMLR530000004054091987560000», «data XMLR5300000040AA971A87560000»}

Emmanuel
 _______________________________________________
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: Help parsing XML file (From: Jim Skibbie <email@hidden>)

  • Prev by Date: Re: Help parsing XML file
  • Next by Date: can't get class of the object
  • Previous by thread: Re: Help parsing XML file
  • Next by thread: Re: Help parsing XML file
  • Index(es):
    • Date
    • Thread