2

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.

2
  • 1
    The name "CDATA" has two completely different meanings in XML, related only by a common heritage in SGML. A "CDATA section" appearing within an element allows you to use special characters such as < and & without escaping. An attribute declared in the DTD (explicitly or implicitly) with type CDATA does not. Jun 8, 2016 at 13:41
  • Thanks! I guess that got me confused.. Jun 8, 2016 at 20:07

1 Answer 1

5

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.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.