Solved

handle special characters in xml file

Posted on 2014-07-19
5
323 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
  • 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

770 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