Re: [xml] how to add namespace-less node in python
- From: Hannu Krosing <hannu tm ee>
- To: John Fleck <jfleck inkstain net>
- Cc: xml gnome org
- Subject: Re: [xml] how to add namespace-less node in python
- Date: Sat, 20 Dec 2003 21:52:43 +0200
John Fleck kirjutas L, 20.12.2003 kell 19:17:
Try this:
#!/usr/bin/python -u
import libxml2
doc = libxml2.newDoc("1.0")
root = doc.newChild(None, "doc", None)
docns = root.newNs("http://www.krosing.net/testns","a")
para = root.newChild(docns, "para", None)
title = doc.newDocNode(None, "title", None)
para.addChild(title)
print doc.serialize(None,1)
Thanks!
Any idea why it is done this way ?
On Sat, 2003-12-20 at 09:50, Hannu Krosing wrote:
Hallo
I need to add a node that has no namespace prefix while building xml doc
in python (for my home-made SOAP server/client lib).
I know that such a tree is possible, as it is correctly generated by
libxml2.parseFile :
d = libxml2.parseFile('nstest.xml')
print d.serialize(None,1)
<?xml version="1.0"?>
<doc xmlns:a="http://www.krosing.net/testns">
<a:para>
<title/>
</a:para>
</doc>
But I am unable to make similar tree programmatically:
doc = libxml2.newDoc("1.0")
root = doc.newChild(None, "doc", None)
docns = root.newNs("http://www.krosing.net/testns","a")
para = root.newChild(docns, "para", None)
title = para.newChild(None, "title", None)
print doc.serialize(None,1)
<?xml version="1.0"?>
<doc xmlns:a="http://www.krosing.net/testns">
<a:para>
<a:title/>
</a:para>
</doc>
I want to get <title/> and not <a:title/> .
What am I doing wrong ?
----------------------
Hannu
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml gnome org
http://mail.gnome.org/mailman/listinfo/xml
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml gnome org
http://mail.gnome.org/mailman/listinfo/xml
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]