Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 343
  • Last Modified:

handle special characters in xml file

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
Rocking
Asked:
Rocking
  • 3
  • 2
2 Solutions
 
GaryCommented:
0
 
RockingAuthor Commented:
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
 
GaryCommented:
strResultData.append("<Data>");
strResultData.append("<CompanyName>"
	+ "<![CDATA["
	+ rsRptDataProductReg.getString("registration_no")
	+"]]>"
	+ "</CompanyName>");

Open in new window

0
 
RockingAuthor Commented:
which one is the best approach to got for ?

1. StringEscapeUtils.escapeXml(yourData);
2. CDATA
0
 
GaryCommented:
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

Technology Partners: 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!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now