You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by shilpa patil <sh...@hotmail.com> on 2006/03/21 01:45:58 UTC
DOMEntityReference nodes in DOMAttr
Hi,
I am looking to generate an XML document using the DOMWriter and
DOMDocument in
xerces 2.7. The element is of the form
<Rule Id="&EURO;TEST" />
The code that I use to generate this is
DOMElement *elemNode = doc.createElement ( X("Rule"));
DOMAttr *attrNode = doc.createAttribute ( X("Id"));
DOMText *textNode = doc.createTextNode ( X("TEST"));
DOMEntityReference *entityRefNode = doc.createEntityReference
(X("EURO"));
if ( attrNode && textNode && entityRefNode ) {
attrNode->appendChild ( entityRefNode );
attrNode->appendChild ( textNode );
elemNode->setAttributeNode ( attrNode );
}
The issues are:
1) The element is generated as <Rule Id="" />
2) If I append the text node and then the entity reference node, the
element
is generated as <Rule Id="TEST" />
3) If I append two text nodes, only the first node is serialized.
However, if I append the entity reference and the text node to an element
node
(instead of an attribute node), it is serialized correctly (i.e.
<Id>&EURO;TEST</Id>).
Any help in adding entity reference nodes to an attribute node is greatly
appreciated.
Thx.
Re: DOMEntityReference nodes in DOMAttr
Posted by Alberto Massari <am...@datadirect.com>.
Hi Shilpa,
there is at least one bug in Xerces (when an attribute is constructed
using multiple Text or EntityReference nodes, DOMAttr::getNodeValue
will return the value of the first node only); as for the second
problem, DOMWriter always uses getNodeValue() to print attributes, so
it will not be able to print the entity references, but only their
value. I think that DOMWriter should look at the "entities" feature
in order to decide whether to use getNodeValue or walk the child
nodes, even if the specs are vague on this topic.
A fix for these bugs will be available shortly.
Thanks,
Alberto
At 12:45 AM 3/21/2006 +0000, shilpa patil wrote:
>Hi,
> I am looking to generate an XML document using the DOMWriter and
> DOMDocument in
>xerces 2.7. The element is of the form
>
> <Rule Id="&EURO;TEST" />
>
>The code that I use to generate this is
> DOMElement *elemNode = doc.createElement ( X("Rule"));
> DOMAttr *attrNode = doc.createAttribute ( X("Id"));
> DOMText *textNode = doc.createTextNode ( X("TEST"));
> DOMEntityReference *entityRefNode = doc.createEntityReference (X("EURO"));
>
> if ( attrNode && textNode && entityRefNode ) {
> attrNode->appendChild ( entityRefNode );
> attrNode->appendChild ( textNode );
> elemNode->setAttributeNode ( attrNode );
> }
>
>The issues are:
> 1) The element is generated as <Rule Id="" />
> 2) If I append the text node and then the entity reference node, the element
> is generated as <Rule Id="TEST" />
> 3) If I append two text nodes, only the first node is serialized.
>
>However, if I append the entity reference and the text node to an element node
>(instead of an attribute node), it is serialized correctly (i.e.
><Id>&EURO;TEST</Id>).
>Any help in adding entity reference nodes to an attribute node is greatly
>appreciated.
>Thx.
>