XML & Python (Cont’d)

I have been fighting with XML. Here is the code I’ve been trying to run in Python.

 

(My apologies for including this as <img>. As soon as I have my blog running under my own domain, it will hopefully be easier to format code using the Google Syntax Highlighter for WordPress.)

The file I was using this time looks like this:

<?xml version=”1.0″?>
<dataroot>
<POINT>
<Name>B-1</Name>
<North>10342486</North>
<East>3259140</East>
</POINT>

<POINT>
<Name>B-2</Name>
<North>10342671</North>
<East>3259434</East>
</POINT>

<POINT>
<Name>B-3</Name>
<North>10342542</North>
<East>3259375</East>
</POINT>

</dataroot>

and the successful output looks like this:

Found Name
Found Northing
Found Easting
Found Name
Found Northing
Found Easting
Found Name
Found Northing
Found Easting
Borehole  B-1 has a Northing of 10342486 and Easting of 3259140
Borehole  B-2 has a Northing of 10342671 and Easting of 3259434
Borehole  B-3 has a Northing of 10342542 and Easting of 3259375

So what I have I learned ? I can now read the gINT created XML files into Python and turn the data into objects created from my existing classes. (Granted the POINT class used here is VERY basic.) I will probably have to re-write some of the def’s for the classes in my Project module so that I can use the same code for creating an instance, whether the data came from key board entry or was read from XML, and I need to reverse the process and let my program write XML. In fact, somewhere I read about the xml_pickle module. Will have to look at that, too.

Here is a short list of links to some helpful pages :

A Technical Introduction to XML
http://www.xml.com/pub/a/98/10/guide0.html

More XML Basics
http://www.xmlnews.org/docs/xml-basics.html#xmldecl

Columns by Uche Ogbuji
http://www.xml.com/pub/au/845.4

Understanding XML (Python & XML)
http://etutorials.org/Programming/Python.+Text+processing/Chapter+5.+Internet+Tools+and+Techniques/5.4+Understanding+XML/

A Brief History of SAX
http://ftp.accu.org/index.php/journals/515

Charming Python #2 (XML.DOM Module)
http://gnosis.cx/publish/programming/charming_python_2.html

On the ‘Pythonic’ treatment of XML documents as objects
http://www.ibm.com/developerworks/xml/library/xml-matters1/index.html

A Summary fo XML.SAX Exceptions
http://pydoc.org/2.5.1/xml.sax._exceptions.html#SAXParseException

Advertisements

Leave a comment

Filed under Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s