Solved

xml contails & and single quotes

Posted on 2003-11-09
8
286 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

751 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