You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Monte Philip V NPRI <Mo...@Npt.NUWC.Navy.Mil> on 2006/02/01 14:37:56 UTC

RE: XML Strings with special Characters

OK, thanks for the clarification. I will modify the side that reads the XML with the &amp; to replace it with &. Thanks again.

-----Original Message-----
From: Lawrence Jones [mailto:ljones@bea.com] 
Sent: Tuesday, January 31, 2006 1:04 PM
To: user@xmlbeans.apache.org
Subject: RE: XML Strings with special Characters



Hi Philip

 

This is a mandatory restriction of XML.

 

Literal ampersands have to be translated into &amp; in order to be valid XML unless they are part of a comment, a processing instruction or (as Richard mentions below) a CDATA section - see http://www.w3.org/TR/REC-xml/ <http://www.w3.org/TR/REC-xml/>  section 2.4. This is because & is used to mark the start of an escaped entity and therefore cannot be used literally (like the '\' character in Java strings). As mentioned in the same document section 4.6 all XML processors _must_ recognize and translate back to the original character data any such reference.

 

Ultimately you sound like you are using XmlBeans to generate XML and then send that XML (containing the &amp; 's) to something. It is that something's responsibility to translate the &amp; back to & before it uses it (in your case as a URL). XmlBeans itself will do this if it is used to receive the XML as well as to construct it.

 

Sorry - I know it sounds like we're passing the buck - but the XML spec is very specific on this.

 

Cheers,

 

Lawrence

 


  _____  


From: Butterwood, Richard [mailto:Richard.Butterwood@infor.com] 
Sent: Tuesday, January 31, 2006 9:37 AM
To: user@xmlbeans.apache.org
Subject: RE: XML Strings with special Characters

 

How about CDATA?

 

Richard Butterwood | Senior Analyst/Programmer | Infor | office: 770-418-2000 X 1167 | cell: 678-492-3080 | fax: 770-418-2022 | richard.butterwood@infor.com <ma...@infor.com> 


  _____  


From: Monte Philip V NPRI [mailto:MontePV@Npt.NUWC.Navy.Mil] 
Sent: Tuesday, January 31, 2006 12:24 PM
To: 'user@xmlbeans.apache.org'
Subject: XML Strings with special Characters

 

I  am not sure if this message got through the first time: 

I am very new to xml beans. I am trying to set the string content of an element. I simply do parentName.setElement("some_string"); The problem is that the string contains ampersands (&). The string is actually a URL referring to a Servlet. XMLBeans is replacing my &s with &amp;. How can I prevent this and preserve my &s?

 

 


Philip V. Monte  (Newport, RI)