RE: Initial Setup
[email protected] Tue, 04 Mar 2003 12:54:28 -0800
| Newsgroups | gmane.comp.web.zope.parsed-xml |
|---|---|
| Message-ID | <AA7A72A46469D411B8B300508BE329500AE4D53D@desi2> |
I've posted this back to the parsed-xml-dev list in case it is useful to
anyone else, because generally speaking there is not a lot of documentation
on this sort of thing.
Make sure to have a copy of the book _Python & XML_, by Jones and Drake, and
published by O'Reilly; it has a Python DOM API reference (Chapter 4 and
Appendix D)... The thing about ParsedXML is that there is a supposition
made that you likely know DOM programming if you are using it.
If you are learning DOM, I would start by doing some playing around with
PyDOM (part of the Python XML package) in an interactive Python interpreter
session. Expect to use TTW Python Scripts in Zope to access and use XML
documents in ParsedXML instances, but you could also use something like ZPT
(or perhaps DTML) in an XSLT-like way to transform a portion of an XML
document...I have some code examples for doing this, but they are only on
hardcopy, since I lost some files. ;( I hope this is helpful.
Once you get the hand of using DOM, it becomes much easier (well, tedious,
but straightforward).
Trivial xhtml-traversal example:
#get root element inside the document, use this as starting point for
# deeper traversals
rootElementNode = myFolder['myXMLDoc'].getElementsByTagName('html')
bodyNode = rootElementNode.getElementsByTagName('head')
if bodyNode.hasAttribute('bgcolor'):
bgcolor = bodyNode.getAttribute('bgcolor')
else:
bgcolor = '#FFFFFF'
firstChildNodeInBody = bodyNode.childNodes[0]
if firstChildNodeInBody.nodeType == 3:
#text node (3), do something with it
firstText = firstChildNodeInBody.nodeValue
elif firstChildNodeInBody.nodeType == 1:
#element node, do something else:
pass #etc...
Another tip: get familiar with reading and traversing values from the DOM
before trying to do any write operations. Use existing well-formed XML docs
before trying to change node values, replace nodes, etc. ParsedXML works
quite well for both reading and writing documents, but DOM can often require
a lot of work to do this in a robust way, so you really need to master it if
you are going to use it to write data back to the document.
Good Luck,
Sean
-----Original Message-----
From: Bernard Golden [mailto:[email protected]]
Sent: Tuesday, March 04, 2003 11:44 AM
To: [email protected]
Subject: RE: [Parsed-XML-Dev] Initial Setup
Sean, many thanks for your thoughts. By following your suggestions, I have
been able to get ParsedXML up and running. The ParsedXML archive suggests
importing example.zexp to get a flavor for how to get ParsedXML to work and
manipulate XML files. Unfortunately, when I try and import it I get a
well-formed error; when I import a known well-formed xml doc it imports OK.
I'm trying to learn how to manipulate XML files in ZOPE and thought you
might have some example dtml files that I could use as templates to work
with my xml files. If you do, it would be much appreciated.
Many thanks.
Bernard Golden
-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Friday, February 28, 2003 11:21 AM
To: [email protected]; [email protected]
Subject: RE: [Parsed-XML-Dev] Initial Setup
ParsedXML 1.3+ requires no need to compile a specific version of the pyexpat
parser (older versions required this). You just need to install the
official Python2.1 (not the Zope bundled one) and the Python-XML package for
Windows for that Python version from the respective
http://pyxml.sourceforge.net/
http://sourceforge.net/project/showfiles.php?group_id=6473
If you are using a binary install of Zope (I'm pretty sure you are), it is
quite likely that you will need to copy the package files from the folder
they get installed in (C:\Python21\lib\ ???) to the appropriate folder in
your Zope install (somewhere in your PYTHONPATH, potentially lib/python). I
can't remember where the files are installed or the package names, so you
may need to do a bit of work to find the packages (read the tracebacks for
ParsedXML when you start up Zope, keep doing this until you get it right).
I haven't messed with installing PyXML on Windows in 2 years, so this is all
in theory, but give this a try as a starting point.
Sean
-----Original Message-----
From: Bernard Golden [mailto:[email protected]]
Sent: Friday, February 28, 2003 11:01 AM
To: [email protected]
Subject: [Parsed-XML-Dev] Initial Setup
Hi. I am trying to get xml functionality into Zope. It appears that
parsedxml is the right mechanism. I'm having a little trouble understanding
how to install and configure parsed xml onto my system (XP Pro). The
parsedxml doc points to pyxml, which is a bit confusing as well (mentions c
compiler, etc.). Has anyone documented the install/config in a step-by-step
document that makes it easy to follow? The functionality looks like it
will solve exactly the task at hand, but I'm having a hard time getting
started.
Also, the .exe comes up blank looking for a python install. I figured I
would just extract the files to the python location, but am not sure which
directory they should go in. Python lib, bin? Can anyone identify the
right installation location?
TIA.
Bernard Golden