document as child in DOM ??

Uche Ogbuji uche at ogbuji.net
Sat Nov 6 21:43:09 EST 2004


Juliano Freitas <jubafre at atlas.ucpel.tche.br> wrote in message news:<mailman.5827.1099417246.5135.python-list at python.org>...
> I have a document as a string:
> 
> xmltext = """<?xml version='1.0'?>
> <root>
> 	<parara>text</parara>
> </root>"""
> 
> then i transform the string into a document with fromString method.
> 
> i want tu put this "xmltext" as a child to another document called
> "swdb"?
> how can i do this??
> 
> <swdb>
>   <root>
> 	<parara>text</parara>
>   </root>
> ...
> </swdb>
> 
> i tryed the importNode and appendNode, but i dont if i'm doing right!

I think you want something like the following (pseudocode):

1) parse "root" document into root_dom
2) new_docelem = root_dom.createElementNS(None, 'swdb')
3) old_docelem = root_dom.documentElement
4) root_dom.documentElement = new_docelem
5) new_docelem.appendChild(old_docelem)

There.  Now doesn't DOM just completely suck?  :-)

If this doesn't work, please post specific error messages or
unexpected results so we can hekp you better.

-- 
Uche Ogbuji                                    Fourthought, Inc.
http://uche.ogbuji.net    http://4Suite.org    http://fourthought.com
A hands-on introduction to ISO Schematron -
http://www-106.ibm.com/developerworks/edu/x-dw-xschematron-i.html
Schematron abstract patterns -
http://www.ibm.com/developerworks/xml/library/x-stron.html
Wrestling HTML (using Python) -
http://www.xml.com/pub/a/2004/09/08/pyxml.html
XML's growing pains - http://www.adtmag.com/article.asp?id=10196
XMLOpen and more XML Hacks -
http://www.ibm.com/developerworks/xml/library/x-think27.html
A survey of XML standards -
http://www-106.ibm.com/developerworks/xml/library/x-stand4/



More information about the Python-list mailing list