排解 XML 到 JSON 政策部署錯誤

您正在查看 Apigee Edge 說明文件。
查看 Apigee X 說明文件
資訊

EitherOptionOrFormat

錯誤訊息

無法透過 Edge UI 或 Edge Management API 部署 API Proxy,並顯示以下錯誤訊息:

Error Saving Revision [revision_number]
XMLToJSON[{0}]: Either Options or Format must be specified.

錯誤示例

Error Saving Revision 1
XMLToJSON[{0}]: Either Options or Format must be specified.

螢幕截圖範例

原因

如果未在 XML 中對 JSON 政策宣告 <Options><Format> 其中之一,API Proxy 的部署就會失敗。

如果未使用 <Format>,就必須提供 <Options>

請使用 <Format> 元素或 <Options> 元素群組。您無法同時使用 <Format><Options>。預先定義的格式包括:xml.comyahoogooglebadgerFish

診斷

  1. 檢查發生錯誤的特定 API Proxy 中的所有 XML 至 JSON 政策。如有任何 XML 對 JSON 政策的未宣告 <Options><Format> 元素,就是發生錯誤的原因。

    舉例來說,以下政策未宣告任一元素:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <XMLToJSON async="false" continueOnError="false" enabled="true" name="XMLToJSON">
        <DisplayName>XMLToJSON</DisplayName>
        <Properties/>
        <OutputVariable>response</OutputVariable>
        <Source>response</Source>
    </XMLToJSON>
    

解析度

確認 XML 至 JSON 政策的 XML 包含政策中宣告的其中一個元素 <Options><Format>

範例 1:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XMLToJSON async="false" continueOnError="false" enabled="true" name="XMLToJSON">
    <DisplayName>XMLToJSON</DisplayName>
    <Properties/>
    <Format>google</Format>
    <OutputVariable>response</OutputVariable>
    <Source>response</Source>
</XMLToJSON>

範例 2:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XMLToJSON async="false" continueOnError="false" enabled="true" name="XMLToJSON">
    <DisplayName>XMLToJSON</DisplayName>
    <Properties/>
    <Options>
        <RecognizeNumber>true</RecognizeNumber>
        <RecognizeBoolean>true</RecognizeBoolean>
        <RecognizeNull>true</RecognizeNull>
    </Options>
    <OutputVariable>response</OutputVariable>
    <Source>response</Source>
</XMLToJSON>

UnknownFormat

錯誤訊息

無法透過 Edge UI 或 Edge Management API 部署 API Proxy,並顯示以下錯誤訊息:

Error Saving Revision [revision_number]
XMLToJSON[policy_name]: Unknown Format [unknown_format].

錯誤示例

Error Saving Revision 1
XMLToJSON[WithFormat]: Unknown Format google.com.

螢幕截圖範例

原因

如果 XML 到 JSON 政策中的 <Format> 元素定義不明格式,API Proxy 部署就會失敗。

預先定義的格式包括:xml.comyahoogooglebadgerFish

診斷

  1. 找出發生錯誤的 XML 到 JSON 政策。您可以在錯誤訊息中找到這項資訊。舉例來說,在下列錯誤中,政策名稱是 WithFormat,而不明的格式是 google.com

    Error Saving Revision 1
    XMLToJSON[WithFormat]: Unknown Format google.com.
    
  2. 確認失敗的 XML 至 JSON 政策中指定的不明格式,與錯誤訊息中指出的值 (請參閱上方的步驟 #1) 相符。舉例來說,下列政策會將格式指定為 google.com,以便與錯誤訊息中的內容相符:

    <XMLToJSON async="false" continueOnError="false" enabled="true" name="WithFormat">
      <DisplayName>WithFormat</DisplayName>
      <Properties/>
      <Format>google.com</Format>
      <OutputVariable>response</OutputVariable>
      <Source>response</Source>
    </XMLToJSON>
    
  3. 如果指定的格式不是預先定義的格式 xml.comyahoogooglebadgerFish,就是導致錯誤的原因。

    在上述 XML 到 JSON 政策的範例中,google.com 的格式無效。因此,API Proxy 的部署失敗並顯示以下錯誤:

    XMLToJSON[WithFormat]: Unknown Format google.com.
    

解析度

請確定 XML 至 JSON 政策的 <Format> 元素中指定的格式有效。例如:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XMLToJSON async="false" continueOnError="false" enabled="true" name="WithFormat">
  <DisplayName>WithFormat</DisplayName>
  <Properties/>
  <Format>google</Format>
  <OutputVariable>response</OutputVariable>
  <Source>response</Source>
</XMLToJSON>