En Sun, 01 Apr 2007 05:26:48 -0300, Manuel Ospina <[EMAIL PROTECTED]>  
escribió:

> I am new on the list and I already have a question :-(.

Welcome!

> I have something like this:
>
> import xml.dom.minidom
> from xml.dom.minidom import getDOMImplementation
> impl = getDOMImplementation()
> myDoc = impl.createDocument(None, "example", None)
> myRoot = myDoc.documentElement
> myNode1 = myDoc.createElement("node")
> myNode2 = myDoc.createElement("nodeTwo")
>  myText = myDoc.createTextNode("Here is the <b>problem</>")
> myNode2.appendChild(myText)
> myNode1.appendChild(myNode2)
> myRoot.appendChild(myNode1)
> print myDoc.toxml()
>
> The result is:
> '<?xml version="1.0" ?>\n<example><node><nodeTwo>Here is the  
> &lt;b&gt;problem&lt;/&gt;</nodeTwo></node></example>'

That's right...

> My question is how I can avoid that toxml() replaces the tags?

createTextNode is used to create a *text* node: its argument is  
interpreted as the node contents, and quoted as appropiate. What if you  
want it to say "Price<1000"? The < sign must be quoted.

You need a text node AND a <b> node, both children of nodeTwo.

Note: Using ElementTree is a lot easier!

-- 
Gabriel Genellina

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to