org.xml.sax.SAXParseException: The reference to entity “T” must end with the ';' delimiter

前端 未结 9 1611
北海茫月
北海茫月 2020-12-29 07:35

I am trying to parse an XML file whcih contains some special characters like \"&\" using DOM parser. I am getting the saxparse exception \"the reference to entity must e

9条回答
  •  别那么骄傲
    2020-12-29 07:47

    Your input is invalid XML. Specifically, you cannot have an '&' character in an attribute value unless it is part of a well-formed character entity reference.

    AFAIK, you have two choices:

    • Write a "not exactly XML" parser yourself. I seriously doubt that you will find an existing one. Any self-respecting XML parser will reject invalid input.
    • Fix whatever is creating this (so-called) XML so that it doesn't put random '&' characters in places where they are not allowed. It's quite simple really. As you are building the XML, replace the '&' character that is not already part of a character reference with '&'

提交回复
热议问题