List Info

Thread: Use of the "&" character in the content of a Node




Use of the "&" character in the content of a Node
user name
2006-05-18 14:41:42
Hi,

I've a question about the "&" character.

  nodePtr = xmlNewNode(NULL, "node");
  if (nodePtr)
  {
    xmlNodeSetContent(nodePtr, "111&222");
  }

At this point, the content of the node has been set to
"111"

If I put the ampersand as &, the resulting node
content is "111&222"

Which is the correct way to put the content
"111&222" in the node? I mean, to get the
following result:

<node>111&222</node>

I want to be able to set it, and get it back later.

Do I have to create a new text node (xmlNewText) instead of
using xmlNewNode? 

Thanks in advance for your help,

Unai Astorquiza
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xmlgnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
Use of the "&" character in the content of a Node
user name
2006-05-18 16:02:05
* Unai Astorquiza <uastorquizapandasoftware.es>
[2006-05-18 16:50]:
> Which is the correct way to put the content
"111&222" in the
> node? I mean, to get the following result:
> 
> <node>111&222</node>

That is malformed XML. It must be
`<node>111&amp;222</node>`.

>  nodePtr = xmlNewNode(NULL, "node");
>  if (nodePtr)
>  {
>    xmlNodeSetContent(nodePtr,
"111&222");
>  }


    nodePtr = xmlNewNode(NULL, "node");
    if (nodePtr)
    {
        xmlNodeAddContent(nodePtr,
"111&222");
    }

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/&g
t;
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xmlgnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
Use of the "&" character in the content of a Node
user name
2006-05-18 16:26:27
* A. Pagaltzis <pagaltzisgmx.de> [2006-05-18
18:10]:
> >  nodePtr = xmlNewNode(NULL, "node");
> >  if (nodePtr)
> >  {
> >    xmlNodeSetContent(nodePtr,
"111&222");
> >  }
> 
> 
>     nodePtr = xmlNewNode(NULL, "node");
>     if (nodePtr)
>     {
>         xmlNodeAddContent(nodePtr,
"111&222");
>     }

Err, they’re probably both equally wrong. I *think* you
want
this:

    nodePtr = xmlNewNode(NULL, "node");
    textPtr = xmlNewText("111&222");
    if (nodePtr && textPtr)
    {
        xmlAddChild(nodePtr, textPtr);
    }

But I can’t check right now.

In any case, the correct solution will take the string
"111&222"
and automatically put the properly escaped
"111&amp;222" into the
text node.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/&g
t;
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xmlgnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )