XML Illegal Attribute Value

做~自己de王妃 提交于 2019-12-25 04:21:50

问题


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 &lt; 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!