Re: [xml] Behaviour of xmlNodeAddContent() vs. xmlNodeSetContent()



On Tue, Oct 31, 2006 at 09:07:53AM +0100, Keim, Markus wrote:
You could, however, be in a situation where you don't know if a content
buffer that's to be passed to libxml2 contains unescaped special characters
*or* entity references. I didn't put me there, it's a factual situation
I've do deal with. I'm just looking for a clean way to do so.

  "we dont' know what the data are but we expect to process them cleanly"
this sounds very similar to not knowing the encoding of a piece of text,
you may try to apply heuristic but it will come bite you back no matter
what. In both case only one solution: educate the users/developpers.

But even if I scrap the idea of a general solution and implement
dedicated calls for escaped/raw input, I'm still looking for a (clean)
way to

- *set* node content if I'm sure that I've raw input (going through
  xmlEncodeEntitiesReentrant() and xmlNodeSetContent() seems inefficient
  to me, since the latter will simply undo the work of the former)

- *add* node content if I actually need entity support

I hope I'm wrong, but AFAICS (from tree.c), I'd have to play with the
members of the libxml2 node structure and some (internal) functions to
do so!?

  it's perfectly clean to use diret access to the node structure. Just
check that the target strings are not from the doc dictionnary (in which case
don't free them) and overwise use xmlMalloc/xmlFree to manipulate the target
text nodes. Of course if you use non-predefined entities, then you will
have to add entities references to the element children list.

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/



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