Solved

xml contails & and single quotes

Posted on 2003-11-09
8
284 Views
Last Modified: 2013-11-19
Hi ,
I am using jaxp to create my xml. I am fetching the values from database and mydata has & and ' ' . How can i allow special characters?
Do i have to specify something in my DTD for ignoring this kind of data.
Please help.
Mehak
0
Comment
Question by:mehaklala
  • 3
  • 2
8 Comments
 
LVL 6

Accepted Solution

by:
purpleblob earned 250 total points
ID: 9711279
When there's a chance you'll output characters which have special meaning then enclose the output data in a <!CDATA[ ] ]> block then anything within this block is ingored in terms of parsing the XML
0
 
LVL 7

Expert Comment

by:wsteegmans
ID: 9714631
You can indeed use the CDDATA block, but that's not such a nice solution ...

In XML, there are indeed some special characters you can't use ...

But, just like HTML, XHTML and XML provides built-in entities for representing markup characters inside of markup without disrupting parsing:

So, do a replace of all these characters ...

[&amp;] => Ampersand (&)
[&lt;] => Less Than (<)
[&gt;] => Greater Than (>)
[&apos;] => Apostrophe (')
[&quot;] => Quote (")
0
 
LVL 6

Expert Comment

by:purpleblob
ID: 9714934
I'm intrigued - why is CDATA not such a nice solution ?

If you're reading data out of a database you'd have to convert the "special characters" to the &X; equivalent's each time you create the XML output or store the data within the database in this format. Whilst enclosing the output from the db into a CDATA block requires no processing.
0
 
LVL 7

Expert Comment

by:wsteegmans
ID: 9722804
Let's say it's more personnal, but I prefer to minimize the use of CDATA.

But, you're absolutely right when building big XML-files with data from a DB, you can indeed better use CDATA.
0
 
LVL 7

Expert Comment

by:wsteegmans
ID: 9791664
mehaklala,

Did these comments solved your problem?
Please, give us some additional info/input, if required.

thx!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Download a website to hdd 2 89
Support for Notepad++ (including downloading & installing a plugin) 5 191
Why use this lambda? 12 60
Code Coverage and Coding Standards 2 43
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question