473,396 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
5 1559
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Collin VanDyck | last post by:
I have a basic understanding of this, so forgive me if I am overly simplistic in my explanation of my problem.. I am trying to get a Java/Xalan transform to pass through a numeric character...
3
by: Kaidi | last post by:
Hello guys, I get the "an invalid XML character" error when using xerces to parse a XML file. I know that XML will correspond the &, <, >, " to special strings like "&gt;&lt;". However, how about if the...
24
by: Romeo Colacitti | last post by:
Hi, Does anyone here have a strong understanding for the meanings of the terms "lvalue" and "rvalue" as it pertains to C, objects, and different contexts? If so please share. I've been...
23
by: Steven T. Hatton | last post by:
This is one of the first obstacles I encountered when getting started with C++. I found that everybody had their own idea of what a string is. There was std::string, QString, xercesc::XMLString,...
1
by: JeffP | last post by:
Currently I have a user control which contain a <a href> link tag. I have a requirement to change the name property of the anchor tag to something like this: <a href="somepage.aspx" id"thislink"...
5
by: Ivan Marsh | last post by:
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......
28
by: entfred | last post by:
I have the following line of html: &nbsp;&nbsp1234&nbsp;&nbsp;&nbsp;&nbsp;&nbspabc&nbsp;&nbsp;&nbspyow In Internet Explorer 6.0, the columns look ok using the above html: 1234 abcd ...
82
by: arnuld | last post by:
PURPOSE :: see statement in comments GOT: Segmentation Fault I guess the segfault is sourced in the compile-time warning but I am giving a char* to the function already.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.