By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,255 Members | 2,773 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,255 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

--
The USA Patriot Act is the most unpatriotic act in American history.
Feingold-Obama '08 - Because the Constitution isn't history,
It's the law.

Jun 23 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Ivan Marsh wrote:
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
Jun 24 '06 #2

P: n/a
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".

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 :-)

--
Bart

Jun 24 '06 #3

P: n/a
Rik
Bart Van der Donck wrote:
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".

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.


There is, htmlentities().
Unfortunately, it doesn't recognize every character, and coverts the
ampersand in already converted entitities. In the comments, someone claims
to have written a better function for it:
http://www.prolifique.com/entities.php.txt

I haven't tried the code yet, maybe it's usefull here.

Grtz,
--
Rik Wasmus
Jun 24 '06 #4

P: n/a
Ivan Marsh wrote:
<snip>
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.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jun 25 '06 #5

P: n/a
On Sun, 25 Jun 2006 11:22:57 -0700, R. Rajesh Jeba Anbiah wrote:
Ivan Marsh wrote:
<snip>
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.


I just parsed them into &amp; and it works fine. Thanks.

--
The USA Patriot Act is the most unpatriotic act in American history.
Feingold-Obama '08 - Because the Constitution isn't history,
It's the law.

Jun 26 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.