Re: [xml] Building a DOM tree in python using libxml2
- From: "William M. Brack" <wbrack mmm com hk>
- To: xml gnome org
- Subject: Re: [xml] Building a DOM tree in python using libxml2
- Date: Thu, 15 Jul 2004 12:16:25 +0800 (HKT)
John Fleck said:
On Wed, 2004-07-14 at 16:19, Colin Fox wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi, all.
I posted before about trying to manually build a tree and getting
a
segfault.
Maybe I've overlooked something, but I've checked all the
documentation
I can find, and can't see any examples of doing this in python.
Can a kind soul out there provide me with a short example on how
to
construct a small tree in python? A root with a single text node
would
be great.
Thanks,
Here's one:
#!/usr/bin/python -u
import libxml2
doc = libxml2.newDoc("1.0")
root = doc.newChild(None, "root", "some content")
doc.saveFormatFile(("file.xml"),1)
doc.freeDoc()
Cheers,
John
Colin - Sorry not to have replied to your original post, but I had
the same problem as you with not having any examples of a simple
Python program that worked :-). John's example solves that problem.
I'll try to check into why your previous attempt produced a
segfault - we can argue over whether or not the code is "correct",
but I think we will agree it shouldn't crash in that manner.
In fact, I simplified your original post just a bit:-
import libxml2
d = libxml2.xmlDoc('1.0')
print d
and got a segfault at that point :-\. Anyway, I'll try to get it
fixed.
Bill
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]