?
Solved

handle special characters in xml file

Posted on 2014-07-19
5
Medium Priority
?
331 Views
Last Modified: 2014-07-19
Hi,

How to handle special characters in the xml which are coming from the database.
I am creating the xml through stringbuffer in java.now the comapny name contains special characters like "&" etc
example

strResultData.append("<Data>");
                        strResultData.append("<CompanyName>"
                                    + rsRptDataProductReg.getString("registration_no")
                                    + "</CompanyName>");

what is the best way to handle the above?
0
Comment
Question by:Rocking
[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
5 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 40206410
0
 

Author Comment

by:Rocking
ID: 40206446
I came across the " Wrap your data inside a CDATA block" what is CDATA? How it can be used in the stringbuffer while making xml?
0
 
LVL 58

Assisted Solution

by:Gary
Gary earned 2000 total points
ID: 40206463
strResultData.append("<Data>");
strResultData.append("<CompanyName>"
	+ "<![CDATA["
	+ rsRptDataProductReg.getString("registration_no")
	+"]]>"
	+ "</CompanyName>");

Open in new window

0
 

Author Comment

by:Rocking
ID: 40206873
which one is the best approach to got for ?

1. StringEscapeUtils.escapeXml(yourData);
2. CDATA
0
 
LVL 58

Expert Comment

by:Gary
ID: 40206891
It's better to escape your data else you are just posting extraneous data in the xml.
But whichever works easier for you...
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month8 days, 14 hours left to enroll

764 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