Solved

handle special characters in xml file

Posted on 2014-07-19
5
326 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 500 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 500 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTML question 2 33
How does initial implicit objects  are set up in JSP? 7 40
Expanding/Collapsing Tree on SharePoint List 29 62
Load XML element 3 43
This article discusses how to create an extensible mechanism for linked drop downs.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

739 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