Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XmlFile Containing the & Character in text 1

Status
Not open for further replies.

Trob70

Programmer
Sep 25, 2012
89
AU
Just a query about the & character in an xml file


Say Text = Me & my dog?

I run it through a UTF-8 conversion and i get

Me & My Dog?

I am planning using this file for a game on the internet

?? will i have any problems with the &

Appreciate any advice

Regards Robert


 
Robert,

A UTF-8 converter should not transform [highlight #FCE94F][tt]&[/tt][/highlight] into anything else and just leave it as it is.

The string [highlight #FCE94F][tt]Me & my dog?[/tt][/highlight] must be encoded in XML as [highlight #FCE94F][tt]Me &amp; my dog?[/tt][/highlight] or, if (part of) a text node inside an element, as [highlight #FCE94F][tt]<![CDATA[Me & my dog?]]>[/tt][/highlight]
 
Thanks for your advice.. much appreciated.

Just double confirming

Yes the original is <Me & my Dog?> ie its is within <>

do i have to make it <Me &amp;amp; My Dog?>
or <![CDATA[Me & my dog?]]>

if i leave it as <Me &amp;amp; My Dog?> it seems to load into a browser ok

I am pretty new to xml hope i do not sound too vague !!@@!

Regards Robert



 
Robert,

You mean within ><, right?

If you encode your text as [highlight #FCE94F][tt]Me &amp;amp; my dog?[/tt][/highlight], the system that will read your XML data will interpret it as [highlight #FCE94F][tt]Me &amp; my dog?[/tt][/highlight], while if you encode as [highlight #FCE94F][tt]Me &amp; my dog?[/tt][/highlight] the document contents will be read as [highlight #FCE94F][tt]Me & my dog?[/tt][/highlight], which is what you intend.

The reason why [highlight #FCE94F][tt]&[/tt][/highlight] must be encoded as [highlight #FCE94F][tt]&amp;[/tt][/highlight] is because it signals an escape sequence that textually represents (among others) the characters that serve some purpose in XML: [highlight #FCE94F][tt]<>'"[/tt][/highlight] and [highlight #FCE94F][tt]&[/tt][/highlight] itself (as a consequence of its role).
 
Atlopes

Thanks for your help...much appreciated

Regards Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top