[Spring] Rules for special characters in spring configuration files

Source: Internet
Author: User
Tags cdata xml parser

Find an error today and find that the XML cannot contain special characters: &, to summarize:

There are 5 special characters in the XML, namely,:&<> "'. If the injected value in the configuration file includes these special characters, special processing is required. There are two workarounds: first, the <! in this example [cdata[]]> Special tags, wrapping strings containing special characters, and second, using XML escape sequences to represent these special characters, the corresponding XML escape sequences for these 5 special characters are described in table 4-2:

When spring is in the XML configuration, if the property value contains a special symbol for the XML, we deliberately add a <! outside the property value. [cdata[]]> 's XML special handling tag, <! [cdata[]]> 's role is to have the XML parser treat the string in the tag as plain text to prevent some strings from damaging the XML format. Take a look at an example:
XML code:

Java code
<BeanID= "Car"class= "Com.baobaotao.attr.Car">    < Propertyname= "Maxspeed">        <value>200</value>    </ Property>    < Propertyname= "Brand"><value><! [Cdata[Red Flag &ca72]]></value>    </ Property></Bean>

If you use an XML escape sequence, we can replace the configuration in Listing 4-10 with the following configuration:
XML code:

Java code
<name= "brand"><value> red flag &amp; CA72</value></Property>  
Reference: http://hechuanzhen.iteye.com/blog/1739062/

[Spring] Rules for special characters in spring configuration files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.