Stop the mini-conversion <> to & lt; & gt;

I am trying to output some data from my data store in google app engine in xml so that the flash file can read it,

The problem is that when using CDATA tags, the output xml contains &lt;instead of <

eg

<name>&lt;![CDATA][name]]&gt;</name>

here is my python that outputs xml:

    doc = Document()

    feed = doc.createElement("feed")
    doc.appendChild(feed)
    tags_element = doc.createElement("names")
    feed.appendChild(tags_element)
    copen = "<![CDATA]["
    cclose = "]]>"

    tags = db.GqlQuery("SELECT * FROM Tag ORDER BY date DESC")

    for tag in tags:
        tag_element = doc.createElement("name")
        tags_element.appendChild(tag_element)
        the_tag = doc.createTextNode("%s%s%s" % (copen,str(tag.thetag), cclose))
        tag_element.appendChild(the_tag)

    self.response.headers["Content-Type"] = "application/xml"
    self.response.out.write(doc.toprettyxml(indent="    "))

I know that this is an encoding problem that simply cannot get in the way of the problem,

early

+3
source share
3 answers

The createCDATASection method seems to work for me.

for tag in tags:
    tag_element = doc.createCDATASection(tag.thetag)
    tags_element.appendChild(tag_element)
+8
source

, , CDATA-, . , , createTextNode, XML , , .

0

createTextNodeconverts reserved characters ( < > &) to objects.

0
source

Source: https://habr.com/ru/post/1744320/


All Articles