re : Python - ParsedXML - Optimizations
"Damien Connolly" <[email protected]> Fri, 15 Nov 2002 15:47:30 +1300
| Newsgroups | gmane.comp.web.zope.parsed-xml |
|---|---|
| Message-ID | <[email protected]> |
I've written some simple python to fetch data in nodes from a ParsedXML
document.
The problem I am having is trying to figure out how many nodes are in an
XML document.
Below is my code that reads in the nodes.=20
It actually works somehow!=20
However at the moment I am checking the data in every node to see if it
is an end tag which kind of sucks :)=20
What is exposed in ParsedXML to tell me how many nodes I have?
### Python to read in Nodes ...=20
import string
a =3D 0;
b =3D 0;
i =3D 0;
cell =3D 0;
print "<tr>";
obj =3D getattr(context, name);
while ( a =3D=3D 0 ):=20
=20
objb =3D obj.childNodes[0][i];=20
i =3D i + 1;
=20
myobj =3D str(objb.firstChild); =20
if myobj[9:len(myobj)-3] =3D=3D "xml-end" : a =3D 1;
if myobj[9:len(myobj)-3] =3D=3D "." : b =3D 1;
if ( a =3D=3D 0 ): =20
if ( len(myobj) > 2 ) : =20
cell =3D cell + 1;
=20
if ( b =3D=3D 0 ) : print "<td bgcolor=3D",color,"><p>" ,
myobj[9:len(myobj)-3] , "</p></td>";
if ( b =3D=3D 1 ) : print "<td =
bgcolor=3D",color,"><p></p></td>";
b =3D 0;
if ( cell =3D=3D 6 ) :=20
print "</tr><tr>";
cell =3D 0; =20
return printed;
=09
___________________________=20
Damien Connolly=20
Development Engineer=20
Right Hemisphere=20
www.righthemisphere.com=20
NZ Ph: +64.9.523.4670=20
NZ Fax: +64.9.523.4671
___________________________=20