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

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



On Tue, Feb 10, 2004 at 04:38:10PM +0100, Kasimier Buchcik wrote:
> Hi,
> 
> on 2/10/2004 2:23 PM Kasimier Buchcik wrote:
> 
> > Hi,
> > 
> > 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.

Daniel


-- 
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
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]