"Re: [xml] how to write a xmlAttr with xmlTextWriter?"


on 2/10/2004 4:45 PM Daniel Veillard wrote:

On Tue, Feb 10, 2004 at 04:38:10PM +0100, Kasimier Buchcik wrote:


on 2/10/2004 2:23 PM Kasimier Buchcik wrote:


does there exist a function that can serialize the content of a xmlAttr 
(attr->children) to be used with "xmlTextWriterWriteAttribute"? It 
should bear analogy to "xmlAttrSerializeContent" which is used by the 
serialization mechanism internally. If no, did someone already succeded 
in xml-text-writing an xmlAttr?

Hmm, I tried the following combination but it does not behave properly:

attrVal = xmlNodeListGetString(NULL, attr->children, 0);
xmlTextWriterWriteAttribute(writer, attr->name, attrVal);

Since "xmlNodeListGetString" and "xmlTextWriterWriteAttribute" both lead 
to a "&" to "&" conversion, I get a recursive conversion if cycling 
serialization & parsing:

"<" --> "&amp;lt;" --> "&amp;amp;lt;" --> etc.

Entity references will be mangled by xmlTextWriterWriteAttribute.
Is there any chance of adding to "xmlAttrSerializeTxtContent" (called by 
"xmlTextWriterWriteAttribute") a heuristic evaluation if a "&" is a 
beginning of an entity reference or not? But maby this does not fit in 
the big picture. Any other clues?

  < in attributes must be escaped. attr->children should be a list
of text node and attribute references, usually you will just get
a text node. Apparently the current xmlTextWriter API won't allow
you to output entities references. That's all I can say. If you
have just a text node use its content as the value passed to
xmlTextWriterWriteAttribute(), otherwise if you have an entity reference
well that would need an API extension I'm afraid.

I see. Hmm, would it be correct to use "xmlNodeListGetString" with 
conjunction with "xmlTextWriterWriteRaw" for the attribute value? When I 
compare "xmlNodeListGetString" with "xmlAttrSerializeTxtContent", the 
latter does some additional text processing (which I'm not able to 
understand by now), so I wonder if "xmlNodeListGetString" chews enough 
to produce a text to be written.


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