简体   繁体   中英

How to escape double quotes?

I have a function that generates a clob with xml like

<?xml version="1.0"?>
<OBJECT_TYPES meta_version="1.0"><OBJECT_TYPE type_name="Absorber "Geo""/>
</OBJECT_TYPES>

When I try to escape double quote with \\" I get an error:

Error: Required white space was missing. Line: (1) <OBJECT_TYPE type_name="Absorber \\"Geo\\""/>

I can't understand why it happens.

The way to escape a double quote character inside a double-quoted attribute value in XML is to use &quot; :

<?xml version="1.0"?>
<OBJECT_TYPES meta_version="1.0"><OBJECT_TYPE type_name="Absorber &quot;Geo&quot;"/>
</OBJECT_TYPES>

Alternatively you can use single quotes around the attribute value which then allows literal double quotes within it

<?xml version="1.0"?>
<OBJECT_TYPES meta_version="1.0"><OBJECT_TYPE type_name='Absorber "Geo"'/>
</OBJECT_TYPES>

Similarly, to escape single quote characters within a single-quoted attribute you use &apos;

<OBJECT_TYPE type_name='Ian&apos;s type'/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM