问题
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>
回答1:
The error message is correct. A <
must be the start of a tag, and cannot appear inside a string. It must be <
instead. I don't believe the quotes is a problem.
回答2:
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).
来源:https://stackoverflow.com/questions/8185005/xml-illegal-attribute-value