[xml] Escaping when defining entity content



Hi, I'm creating an entity in my doc tree like so:

        entityPtr = xmlAddDocEntity(docPtr, name, XML_INTERNAL_GENERAL_ENTITY, publicID, systemID,
                                    (xmlChar *) "\"Strunk & White\"\'s book");

This does not quite work.

I have turned on XML_PARSE_NOENT. The resulting document includes an entity definition like this:

<!ENTITY myentity "&quot;Strunk & White&quot;'s book">

But when I use the entity is used later as an attribute value, I get an error, "xmlParseStringEntityRef: no name". This is caused by the "&" in the content string. If I say "&amp;" instead, it works.

What is the right function to use to convert an arbitrary string to a suitable form for passing to xmlAddDocEntity? xmlEncodeSpecialChars()? Are there any other escapes I need to do? I read something in the mailing list about CRLF issues…

xmlEncodeSpecialChars() says I need to deallocate the resulting string. If I pass it to xmlAddDocEntity and it gets added to the document tree as an entity, is that still true, or will libxml deallocate it when the document is freed? If I still need to deallocate it myself, can I do that immediately, or do I have to wait until after I finish with the document?

Thanks.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]