Python with Rev and postGreSQL?
kee nethery
kee at kagi.com
Fri Jul 14 09:17:18 EDT 2006
On Jul 13, 2006, at 11:40 PM, John Tregea wrote:
> Hi Kee,
>
> I am aware of Rev having XML capabilities, but because of a whole
> bunch of SQL requirements I have kept it in the back of my mind for
> future investigation.
Actually, When I say use XML what I really mean is pass the data
using that format but don't bother with using an XML library. Since
you control the XML you will be reading, keep it simple and one
simple parser is all you need.
For example:
User=joe Bob
account=9274564
Postal=7263 Anystreet
Apartment 16B
Flockingham
Stillton by the Whatever
Round the back and over the bridge
Camshire upon the Avon
Some British Country, UK L8K 9U6
When you use tagged pairs, and you pass data around, you have to deal
with the data containing a return. It just confuses the situation.
If instead, you pass the data around in something that looks like
XML, returns are not an issue.
<xml>
<user>joe Bob</user>
<account>9274564</account>
< Postal>7263 Anystreet
Apartment 16B
Flockingham
Stillton by the Whatever
Round the back and over the bridge
Camshire upon the Avon
Some British Country, UK L8K 9U6</Postal>
</xml>
So just so you know, the above is not legit xml
The parser for this (assuming you put the whole thing into a variable
named 'theData' would be
put getXmlNode('user',getXmlNode('xml',theData)) into theUser
put getXmlNode('account',getXmlNode('xml',theData)) into theAccount
put getXmlNode('Postal',getXmlNode('xml',theData)) into thePostal
and that function looks like:
on getXmlNode nodeName, theText
put offset("<" & nodeName & ">",theText) + the number of chars in
nodeName + 2 into startChar
put offset("</" & nodeName & ">",theText) -1 into endChar
if startChar > 0 AND endChar > 0 then
return char startChar to endChar of theText
else
return empty
end if
end getXmlNode
As long as you control the XML coming in and don't use attributes
<user name="ralph" />
and you don't duplicate data tags
<user>ralph</user>
<user>joe</user>
the above XML parser should be all that you need to use and you can
create and pass data around using the XML format. My homebuilt XML
parsers handle duplicate data tags and attributes but that is only
because other people create the data and I have to deal with it. But
if you own the data format, keep it simple and thats all the XML
parser you'll need.
Kee
More information about the use-livecode
mailing list