views:

165

answers:

2

Hi,

my xml file has a tag with an attribute "containsValue" which contains the "special" characters you can see in the subject:

<original_msg_body id="msgBodySpecialCharsRule" containsValue=";ìè+òàù-<^èç°§_>!£$%&/()=?~`'#;" />

in my xml schema the attribute has xs:string:

<xs:attribute name="containsValue" type="xs:string"  />

I use this value inside a Java software which check if this value is contained inside another String.

but I always obtain this Exception:

javax.xml.bind.UnmarshalException
 - with linked exception:
[org.xml.sax.SAXParseException: The value of attribute "containsValue" associated with an element type "original_msg_body" must not contain the '<' character.]

How can I solve it? I've tried changing the attribute type to xs:NMTOKEN, ut I get the same exception. Is there any other type?

I think I could change the characters encoding, for example using the HTML representation, like <, but than could be tricky for the string comparison...

+3  A: 

Use entity references: replace < with &lt; and > with &gt etc. in your XML document. Your XML parser will then handle conversion between actual character and its entity reference. That is, in your code you get the actual < or > character.

Juha Syrjälä
+1 - Exactly, a bare '<' or '>' or '"' character in an XML attribute value makes the XML malformed ... or in rare cases, well-formed but different to what you meant.
Stephen C
A: 

You need to escape special XML entities like <, >, " with &lt;, &gt;, &quote;

Aurril
I was thinking something like that, in my question I said "...the HTML representation, like <,..." where you see the "<" because I forgot to click on the "code" button in the editor.
Segolas