ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> pythoncard
pythoncard
[Pythoncard-users] flatfileDatabase and XML
by Kevin Altis other posts by this author
Jan 11 2003 10:37PM messages near this date
[Pythoncard-users] Re: [wxPython-users] persistent problem with mailing lists | Re: [Pythoncard-users] flatfileDatabase and XML
I've adopted the Python Cookbook recipe

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/149368

to read in an XML file as a list of dictionaries. With the help of John
Bair, I was able to get a workable format (shown at the end of this message
for the data). I think this is legal XML, but if not, XML experts please
speak up.

The code is in util.py for now. The code that generates XML from a list of
dictionaries is in parse_companies.py in the companies sample directory. I
don't really understand XML escaping and quoting rules, so this is
definitely a work-in-progress and not ready for real use, but it does look
promising. My previous experiments with converting XML to native Python
types was extremely slow, but I read all 6635 records of the companies data
set in under a second using Xml2Obj, which is fast enough to avoid using a
pickle if some of the quoting details can be figured out.

In particular, right now, when I read in the XML file newlines encoded in
the string such as \n get quoted so they are \\n in the dictionary strings.
I'm not dealing with integers or floats either.

The companies sample contains a commented line for the filename. To try
loading the companies-recs.xml file, just run parse_companies.py again to
generate the companies-recs.xml file and change the comments to:

#DATA_FILE = 'companies.pickle'
DATA_FILE = 'companies-recs.xml'

The flatfileDatabase.py and util.py module changes shouldn't break any
existing code, I just added methods and functions, didn't change any
existing methods or functions.

I would appreciate help from people that actually know XML and use it with
Python on getting reading and writing to work correctly.

ka
---

Example three record "list of dictionaries" XML file.

<?xml version="1.0" encoding="UTF-8"?> 
<records> 
    <rec Profile='http://biz.yahoo.com/p/a/a.html' Phone='(650) 752-5000'
NumberOfEmployees='41,000' Web='http://www.agilent.com' Exchange='NYSE'
Company='Agilent Technologies Inc.' Address='395 Page Mill Road\nPalo Alto,
CA 94306' Symbol='A' > </rec>
    <rec Profile='http://biz.yahoo.com/p/a/aa.html' Phone='(412) 553-4545'
NumberOfEmployees='142,000' Web='http://www.alcoa.com' Exchange='NYSE'
Company='Alcoa, Inc.' Address='Alcoa Corporate Center\n201 Isabella
Street\nPittsburgh, PA 15212' Symbol='AA' > </rec>
    <rec Profile='http://biz.yahoo.com/p/a/aaab.html' Phone='(561) 624-4701'
NumberOfEmployees='81' Web='http://www.admiraltybank.com'
Exchange='NasdaqNM' Company='Admiralty Bancorp, Inc.' Address='4400 PGA
Boulevard\nPalm Beach Gardens, FL 33410' Symbol='AAAB' > </rec>
</records> 



-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
Pythoncard-users mailing list
Pythoncard-users@[...].net
https://lists.sourceforge.net/lists/listinfo/pythoncard-users
Thread:
Kevin Altis
Donnal Walter

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved