0

I am using the SAX parser in java to read some XML. The XML I am giving it has problems and is causing the parse to fail. Here is the error message:

11-18 10:25:37.290: W/System.err(3712): org.xml.sax.SAXParseException: Illegal: "<" inside attribute value (position:START_TAG <question text='null'>@1:23 in java.io.InputStreamReader@4074c678)

I have a feeling that it does not like the fact that I have some HTML tags inside of a string in the XML. I would think that anything inside the quotes gets ignored from a syntax standpoint. Also, is it valid to use single quotes here? Here is an example:

<quiz>
    <question text="<img src='//files/alex/hilltf.PNG' alt='hill' style='max-width:400px' />  is represented on map by cut. ">
        <answer text="1"/>
        <answer text="2" correct="true"/>
    </question>
</quiz>
NeilMonday
  • 2,680
  • 2
  • 25
  • 29
  • 1
    What exactly is your question? If the XML has problems, wouldn't you expect the parser to tell you about them? – Michael Kay Nov 19 '11 at 20:45

2 Answers2

5

You need to escape the < inside the text attribute value. Since XML uses < and > to denote tags, it's illegal in content unless escaped or enclosed in a CDATA tag (which isn't an option for an attribute value).

Chris
  • 22,923
  • 4
  • 56
  • 50
4

The error message is correct. A < must be the start of a tag, and cannot appear inside a string. It must be &lt; instead. I don't believe the quotes is a problem.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130