How do I make & a literal character in an XML parse?

I

Ivan Marsh

Hey Folks,

....and here I thought I was done with my AJAX application.

The XML my PHP app is returning to my JavaScript function has elements in
it that contain special characters... specifically the ampersand & which
hoses up the data. ex: Company Name = "K & B Construction".

Can anyone give me some idea of how I make the data coming out of my
database translate as literal characters in the XML output?

-thx
 
J

Janwillem Borleffs

Ivan said:
Can anyone give me some idea of how I make the data coming out of my
database translate as literal characters in the XML output?

Simply by applying the htmlentities or htmlspecialchars function.


JW
 
B

Bart Van der Donck

Ivan said:
The XML my PHP app is returning to my JavaScript function has elements in
it that contain special characters... specifically the ampersand & which
hoses up the data. ex: Company Name = "K & B Construction".

Can anyone give me some idea of how I make the data coming out of my
database translate as literal characters in the XML output?

I think you should deal with this at the PHP side because '&' is
reserved for the declaration of entities. The best way is to encode
your special chars to html entities before adding them to the XML file.
I'ld say that PHP should have ready-to-go regexes for this kind of
things.

If necessary, you could add !ENTITY !DOCTYPE !ELEMENT headers etc, but
don't rely too much on parser-specific implementations. You'll do
yourself a big favour with that :)
 
R

R. Rajesh Jeba Anbiah

Ivan Marsh wrote:
The XML my PHP app is returning to my JavaScript function has elements in
it that contain special characters... specifically the ampersand & which
hoses up the data. ex: Company Name = "K & B Construction".
<snip>

Not sure, if you need CDATA.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top