实体名称必须紧跟在'&'在实体中;错误

What causes a "The entity name must immediately follow the '&' in the entity" error?

本文关键字:实体 错误      更新时间:2023-09-26
{
    "code" : "messaging.config.beans.ImportFailed",
    "message" : "Failed to import the bundle : com.apigee.repository.RepositoryException: javax.xml.bind.UnmarshalException'n - with linked exception:'n[org.xml.sax.SAXParseException: The entity name must immediately follow the '&' in the entity reference.]",
    "contexts" : [ ],   "cause" : {
        "message" : "javax.xml.bind.UnmarshalException'n - with linked exception:'n[org.xml.sax.SAXParseException: The entity name must immediately follow the '&' in the entity reference.]",
        "contexts" : [ ],
        "cause" : {
            "contexts" : [ ],
            "cause" : {
                "message" : "The entity name must immediately follow the '&' in the entity reference.",
                "contexts" : [ ]
            }
        }
    }
}

每次我尝试上传到apigee时,我都会收到这个错误。我几乎检查了所有的&符号。有人知道如何获得更多的信息吗?

检查您的条件和条件流&&——虽然你可以使用&&在UI中(因为它可以帮助您将"&&"转换为"and"),如果您直接通过Management API部署,则不能使用双&号。

通过UI部署

<Condition>(1 = 1) && (2 = 2)</Condition>

将显示成功,但如果您随后检查代码(可能需要刷新),您将看到它变成了

<Condition>(1 = 1) and (2 = 2)</Condition>

但是,如果您尝试使用&&通过管理API,你得到错误:

{
  "code" : "messaging.config.beans.ImportFailed",
  "message" : "Failed to import the bundle : com.apigee.repository.RepositoryException: javax.xml.bind.UnmarshalException'n - with linked exception:'n[org.xml.sax.SAXParseException: The entity name must immediately follow the '&' in the entity reference.]",
  "contexts" : [ ],
  "cause" : {
    "message" : "javax.xml.bind.UnmarshalException'n - with linked exception:'n[org.xml.sax.SAXParseException: The entity name must immediately follow the '&' in the entity reference.]",
    "contexts" : [ ],
    "cause" : {
      "contexts" : [ ],
      "cause" : {
        "message" : "The entity name must immediately follow the '&' in the entity reference.",
        "contexts" : [ ]
      }
    }
  }

到目前为止,导致这种解析错误的最常见原因是XML文本中的某个地方存在未编码的&号。您需要在XML中对&符号进行编码。您可以使用&amp;&#038;(与&符号等效的Unicode),或者您可以将其嵌入CDATA节中。

您说您已经检查了几乎所有的&符号——除了检查其余符号的明显建议之外,如果您在XSL转换中使用参数,我会确保您发送进来的数据没有未编码的&符号。您可能需要运行JavaScript或其他代码策略,在转换之前对输入参数中的任何&符号进行编码。

已经解决了。&符号已经包含在属性文件中,因此在maven构建过程中,&符号将包含在最终zip/jar文件的XML中。

容易出错