473,396 Members | 1,891 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 1557
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.
2
by: sophia | last post by:
why scanf("%d. %d. %d",&d,&m,&y); is NOT reading the i/p 22 4 1972 correctly, whereas it is reading the i/p 22. 4. 1972 correctly ?. Is it because of the dot in the format string of scanf ?
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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.