Dr. Strangelove (or: How I Learned to Stop Worrying and Love XML)
Sarah Reichelt
sarah.reichelt at gmail.com
Sun Jan 14 17:29:20 EST 2007
On 1/15/07, Derek Bump <list at dreamscapesoftware.com> wrote:
> Well, I'm a little behind the game, but I'm trying to work with XML
> documents, and I'm running into walls. I am having difficulty
> understanding all the different variations of XML, or for that matter,
> making Regular Expressions that allow me to forget trying to understand
> XML and just pull the data I need.
>
> For example, I can get tags with no problems by using the following command:
>
> -- Example: <ShortName>Google</ShortName>
> get matchText(tData,"<Shortname>(.*)</Shortname>", tShortName)
>
> But I start running into problems with tags that have attributes:
>
> <Url type="text/html" template="http://www.whatever.com/search">
> </Url>
>
> And tags that have attributes AND "slashes" at the end:
>
> <Url type="text/html" template="http://www.whatever.com/search"/>
>
Hi Derek,
I tried saving your XML as a text file with the official XML header:
<?xml version="1.0"?>
<Url type="text/html" method="GET" template="http://www.google.com/search">
<Param name="q" value="{searchTerms}"/>
<Param name="ie" value="utf-8"/>
<Param name="oe" value="utf-8"/>
<!-- Dynamic parameters -->
<Param name="rls"
value="{moz:distributionID}:{moz:locale}:{moz:official}"/>
<MozParam name="client" condition="defaultEngine"
trueValue="firefox-a" falseValue="firefox"/>
</Url>
Then I opened it using the XML construction kit that is part of my XML
demo <http://www.troz.net/Rev/tutorials/XMLdemo1.rev.gz>.
It worked perfectly and I was able to extract all the elements & their
attributes perfectly. While the XML library has a learning curve, I
would recommend that you use it for such parsing. Or use Ken Ray's
third-party XML library.
Cheers,
Sarah
More information about the use-livecode
mailing list