Solved

handle special characters in xml file

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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.
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 …

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now