Joseph Herraez
Joseph Herraez

Reputation: 154

CONTROL CHARACTERS IN XML ATTRIBUTE VALUES

This is a common question, but i couldn't find an answer that satisfied me. I'm using a propietary tool(SIMATIC IT MES System), and when i feed an XML with a '<' symbol in the value of an attribute to its xml parsing tool, it chokes on it. From what i understand, attribute values within string literals should be treated as CDATA and thus the XML should be valid, and thats what most online validators say. Is this correct? Is the parser at fault or am i missing something? Is there a solution that doesnt involve manually replacing the offending character with it's entity equivalent? I unclude the XML text for reference:

<PARAM ATT1='DESPIECE' 
       ATT2='BU_O_DES' 
       ATT3= '1' 
       ATT3= '0' 
       ATT4='1.0' 
       ATT4= 'BU.SD01.L02' 
       ATT5= 'BU.SD01.L02' 
       ATT6='1ESP1586CV00' 
       ATT7='CLASS FIFO AÑOJO < 350'
       ATT8='08/06/2016' 
       ATT9='115001' 
       MARCA_EMPRESA='false' 
       VARIANTE='' 
       ID_CLASS_ESTABILIZACION='91'
 />

The offending character is in ATT7.

Thanks.

Upvotes: 2

Views: 1029

Answers (1)

potame
potame

Reputation: 7905

Unfortunately, you don't have any other solution but to "escape" the < with the character entity &lt;.

If you look at the XML specification, §2.4 Character data and markup, you will see that the definition is the following:

Character Data

[14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)

Put shortly, it means that < and & must always be escaped in XML.

Upvotes: 5

Related Questions