XMLtoJSON 政策

本頁內容適用於 ApigeeApigee Hybrid

查看 Apigee Edge 說明文件。

政策圖示

結果

這項政策會將可延伸標記語言 (XML) 格式的訊息轉換為 JavaScript 物件標記法 (JSON),並提供多種選項,讓您控管訊息的轉換方式。

假設意圖是將 XML 格式的回應轉換為 JSON 格式的回應,則政策會附加至回應流程 (例如 Response / ProxyEndpoint / PostFlow)。

這項政策屬於標準政策,可部署至任何環境類型。如要瞭解各環境類型適用的政策類型和可用性,請參閱「政策類型」。

關於

在典型的中介服務情境中,通常會將入站要求流程的 JSON 轉 XML 政策,與出站回應流程的 XML 轉 JSON 政策配對。透過這種方式合併政策,即可為僅原生支援 XML 的後端服務公開 JSON API。

如果 API 的使用對象是各種用戶端應用程式,且這些應用程式可能需要 JSON 或 XML,您可以設定 JSON 轉 XML 和 XML 轉 JSON 政策,有條件地執行這些政策,動態設定回應格式。如要瞭解如何實作這個情境,請參閱「流程變數和條件」。


範例

如要詳細瞭解如何轉換 JSON 和 XML,請參閱這篇文章

轉換回覆

<XMLToJSON name="ConvertToJSON">
  <Options>
  </Options>
  <OutputVariable>response</OutputVariable>
  <Source>response</Source>
</XMLToJSON>

這項設定是將 XML 轉換為 JSON 的最低要求,會以 XML 格式的回覆訊息做為來源,然後建立 JSON 格式的訊息,並填入 response OutputVariable。Apigee 會自動將這個變數的內容做為訊息,用於下一個處理步驟。


元素參考資料

您可以在這項政策中設定下列元素和屬性。

<XMLToJSON async="false" continueOnError="false" enabled="true" name="XML-to-JSON-1">
    <DisplayName>XML to JSON 1</DisplayName>
    <Source>response</Source>
    <OutputVariable>response</OutputVariable>
    <Options>
        <RecognizeNumber>true</RecognizeNumber>
        <RecognizeBoolean>true</RecognizeBoolean>
        <RecognizeNull>true</RecognizeNull>
        <NullValue>NULL</NullValue>
        <NamespaceBlockName>#namespaces</NamespaceBlockName>
        <DefaultNamespaceNodeName>&</DefaultNamespaceNodeName>
        <NamespaceSeparator>***</NamespaceSeparator>
        <TextAlwaysAsProperty>true</TextAlwaysAsProperty>
        <TextNodeName>TEXT</TextNodeName>
        <AttributeBlockName>FOO_BLOCK</AttributeBlockName>
        <AttributePrefix>BAR_</AttributePrefix>
        <OutputPrefix>PREFIX_</OutputPrefix>
        <OutputSuffix>_SUFFIX</OutputSuffix>
        <StripLevels>2</StripLevels>
        <TreatAsArray>
            <Path unwrap="true">teachers/teacher/studentnames/name</Path>
        </TreatAsArray>
    </Options>
    <!-- Use Options or Format, not both -->
    <Format>yahoo</Format>
</XMLToJSON>

<XMLtoJSON> 屬性

<XMLtoJSON async="false" continueOnError="false" enabled="true" name="XML-to-JSON-1">

下表說明所有政策父項元素的共同屬性:

屬性 說明 預設 存在必要性
name

政策的內部名稱。name 屬性的值可以包含英文字母、數字、空格、連字號、底線和句號。這個值不得超過 255 個半形字元。

您可以選擇使用 <DisplayName> 元素,在管理 UI 代理程式編輯器中為政策加上不同、自然語言的名稱。

不適用 必填
continueOnError

將其設為 false,即可在政策失敗時傳回錯誤。這是大多數政策的預期行為。

將其設為 true,即使政策失敗,流程執行作業仍會繼續進行。另請參閱:

false 選用
enabled

設為 true 即可強制執行政策。

設為 false 即可關閉政策。即使政策仍附加至流程中,也不會強制執行。

選用
async

此屬性已淘汰。

false 已淘汰

<DisplayName> 元素

除了 name 屬性之外,您也可以在管理 UI 代理程式編輯器中使用不同的自然語言名稱標示政策。

<DisplayName>Policy Display Name</DisplayName>
預設

不適用

如果省略這個元素,系統會使用政策的 name 屬性值。

存在必要性 選用
類型 字串

<Source> 元素

指定要轉換為 JSON 的 XML 訊息的變數。

來源訊息的 HTTP Content-type 標頭必須設為 application/xml,否則系統不會強制執行這項政策。

如果未定義 <Source>,系統會將其視為 message,在政策附加至要求流程時解析為 request,或在政策附加至回應流程時解析為 response

如果無法解析來源變數,或解析為非訊息類型,政策就會擲回錯誤。

<Source>response</Source>
預設 Source 元素的值
存在必要性 選用
類型 訊息

<OutputVariable> 元素

指定要將 XML 轉換為 JSON 格式的輸出內容儲存在哪個位置。一般來說,這項元素不會納入政策設定。

Apigee 會剖析 Source 中指定的 XML 訊息酬載,並將其轉換為 JSON,然後將結果儲存到 OutputVariable 的酬載中,並將 OutputVariable 訊息的 HTTP Content-type 標頭設為 application/json

如未指定 OutputVariable,系統預設會使用 Source 的值。舉例來說,如果 sourceresponse,則 OutputVariable 預設為 response

<OutputVariable>response</OutputVariable>
預設 Source 中指定的訊息
存在必要性 選用
類型 訊息

<Options>

您可以透過選項控制 XML 到 JSON 的轉換作業。您可以使用 <Options> 群組 (可新增特定轉換設定),也可以使用 <Format> 元素 (可參照預先定義選項的範本)。您無法同時使用 <Options><Format>

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

<RecognizeNumber> 元素

如果為 true,XML 酬載中的數字欄位會保留原始格式。

<RecognizeNumber>true</RecognizeNumber>

請參考以下 XML 範例:

<a>
  <b>100</b>
  <c>value</c>
</a>

如果 RecognizeNumbertrue,政策會將其轉換為:

{
    "a": {
        "b": 100,
        "c": "value"
    }
}

如果 RecognizeNumberfalse,政策會將其轉換為:

{
  "a": {
    "b": "100",
    "c": "value"
  }
}
預設 false
存在必要性 選用
類型 布林值

<RecognizeBoolean> 元素

讓轉換維持布林值 true/false,而非將值轉換為字串。

<RecognizeBoolean>true</RecognizeBoolean>

以下 XML 範例:

<a>
  <b>true</b>
  <c>value</c>
</a>

如果 RecognizeBooleantrue,政策會將其轉換為:

{
    "a": {
        "b": true,
        "c": "value"
    }
}

如果 RecognizeBooleanfalse,政策會將其轉換為:

{
    "a": {
        "b": "true",
        "c": "value"
    }
}
預設 false
存在必要性 選用
類型 布林值

<RecognizeNull> 元素

可將空白值轉換為空值。

<RecognizeNull>true</RecognizeNull>

針對下列 XML:

<a>
  <b></b>
  <c>value</c>
</a>

如果 RecognizeNulltrue,且沒有 NullValue 選項,這個 XML 會轉換為:

{
  "a": {
    "b": null,
    "c": "value"
  }
}

如果 RecognizeNullfalse,這個 XML 會轉換為:

{
  "a": {
    "b": {},
    "c": "value"
  }
}
預設 false
存在必要性 選用
類型 布林值

<NullValue> 元素

指出來源訊息中可辨識的空值應轉換為的值。預設值為 null。只有在 RecognizeNull 為 true 時,這個選項才會生效。

<NullValue>not-present</NullValue>

針對下列 XML:

<a>
  <b></b>
  <c>value</c>
</a>

如果 RecognizeNulltrue,且未指定 NullValue, 這個 XML 會轉換為:

{
  "a": {
    "b": null,
    "c": "value"
  }
}

如果 RecognizeNulltrue,且 NullValuenot-present,則此 XML 會轉換為:

{
  "a": {
    "b": "not-present",
    "c": "value"
  }
}
預設 null
存在必要性 選用
類型 字串

命名空間選項

根據預設,這項政策會在產生的 JSON 中省略 XML 命名空間。如要指定 XML 文件中的命名空間應翻譯成產生的 JSON,請一併使用這些元素。

<NamespaceBlockName>#namespaces</NamespaceBlockName>
<DefaultNamespaceNodeName>&</DefaultNamespaceNodeName>
<NamespaceSeparator>***</NamespaceSeparator>

請參考以下 XML 範例:

<a xmlns="http://ns.com" xmlns:ns1="http://ns1.com">
  <ns1:b>value</ns1:b>
</a>

如果未指定 NamespaceSeparator,系統會產生下列 JSON 結構:

{
    "a": {
        "b": "value"
    }
}

如果元素 NamespaceBlockNameDefaultNamespaceNodeNameNamespaceSeparator 分別指定為 #namespaces&***,系統就會產生下列 JSON 結構:

{
    "a": {
        "#namespaces": {
            "&": "http://ns.com",
            "ns1": "http://ns1.com"
        },
        "ns1***b": "value"
    }
}
預設 無,如果未指定 <NamespaceBlockName>,無論來源訊息是否參照命名空間,政策都會產生不參照任何 XML 命名空間的輸出 JSON。
存在必要性 選用
不過,如果指定 <NamespaceBlockName>,則必須一併指定其他兩個元素。
類型 字串

文字選項

請一併使用這些元素。

      <TextAlwaysAsProperty>true|false</TextAlwaysAsProperty>
      <TextNodeName>TEXT</TextNodeName>

當政策遇到只包含單一文字節點做為子項的 XML 元素時,政策會將該 XML 元素的文字內容轉換為 JSON 雜湊中的屬性。

當政策遇到含有多個混合內容的 XML 元素時,您可以透過這些選項控管任何子項文字節點的輸出 JSON。

舉例來說,請參考下列政策設定:

<XMLToJSON name='XMLToJSON-1'>
  <Options>
    <TextAlwaysAsProperty>???</TextAlwaysAsProperty>
    <TextNodeName>#text</TextNodeName>
  </Options>
</XMLToJSON>

根據 TextAlwaysAsPropertytruefalse,這項政策會針對指定的 XML 輸入內容產生下列輸出內容:

XML 輸入 JSON 輸出
TextAlwaysAsPropertyfalse TextAlwaysAsPropertytrue
<a>value1</a>
{
  "a": "value1"
}
{
  "a": {
    "#text": "value1"
  }
}
<a>value1
  <b>value2</b>
</a>
{
  "a": {
    "#text": "value1\n",
    "b": "value2"
  }
}
{
  "a": {
    "#text": "value1\n",
    "b": {
      "#text": "value2"
    }
  }
}
預設 <TextAlwaysAsProperty>:false
<TextNodeName>:(空白字串)
存在必要性 選用
類型 <TextAlwaysAsProperty>:布林值
<TextNodeName>:字串

屬性選項

這些元素可讓您將屬性值分組到 JSON 區塊中,並在屬性名稱中附加前置字元。

<AttributeBlockName>FOO_BLOCK</AttributeBlockName>
<AttributePrefix>BAR_</AttributePrefix>

請參考以下 XML 範例:

<a attrib1="value1" attrib2="value2"/>

如果兩個屬性 (AttributeBlockNameAttributePrefix) 都指定為 XML 至 JSON 範例中定義的屬性,系統會產生下列 JSON 結構:

{
  "a": {
    "FOO_BLOCK": {
      "BAR_attrib1": "value1",
      "BAR_attrib2": "value2"
    }
  }
}

如果只指定 AttributeBlockName,系統會產生下列 JSON 結構:

{
    "a": {
        "FOO_BLOCK": {
            "attrib1": "value1",
            "attrib2": "value2"
        }
    }
}

如果只指定 AttributePrefix,系統會產生下列 JSON 結構:

{
    "a": {
        "BAR_attrib1": "value1",
        "BAR_attrib2": "value2"
    }
}

如果兩者皆未指定,系統會產生下列 JSON 結構:

{
    "a": {
        "attrib1": "value1",
        "attrib2": "value2"
    }
}
預設 無。
存在必要性 選用
類型 字串

<OutputPrefix> 和 <OutputSuffix> 元素

一併使用這些元素,即可在產生的 JSON 中套用前置字元和/或後置字元。

<OutputPrefix>PREFIX_</OutputPrefix>
<OutputSuffix>_SUFFIX</OutputSuffix>

請參考以下 XML 範例:

<a>value</a>

假設政策設定如下:

<XMLToJSON name='XMLToJSON-4'>
  <Options>
    <OutputPrefix>{ "result": </OutputPrefix>
    <OutputSuffix>}</OutputSuffix>
  </Options>
</XMLToJSON>

系統會產生下列 JSON 結構:

{
  "result": {
    "a": "value"
  }
}

您可以省略 OutputPrefix 和/或 OutputSuffix

使用這些元素可能會產生無效的 JSON。舉例來說,使用這項政策設定:

<XMLToJSON name='XMLToJSON-4'>
  <Options>
    <OutputPrefix>PREFIX_</OutputPrefix>
  </Options>
</XMLToJSON>

這項政策會產生下列無效的 JSON:

PREFIX_{
  "a" : "value"
}

如果設定未指定 OutputPrefixOutputSuffix,政策會產生下列 JSON 結構:

{
  "a": "value"
}
預設 請參閱上方的範例。
存在必要性 選用
類型 字串

<StripLevels> 元素

<Options>
    <StripLevels>4</StripLevels>
</Options>

有時 XML 酬載 (例如 SOAP) 會有許多父層級,您不想納入轉換後的 JSON。以下是包含多個層級的 SOAP 回應範例:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/Schemata-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
      <GetCityWeatherByZIPResponse xmlns="http://ws.cdyne.com/WeatherWS/">
          <GetCityWeatherByZIPResult>
              <State>CO</State>
              <City>Denver</City>
              <Description>Sunny</Description>
              <Temperature>62</Temperature>
          </GetCityWeatherByZIPResult>
      </GetCityWeatherByZIPResponse>
  </soap:Body>
</soap:Envelope>

在「州」、「城市」、「說明」和「溫度」層級之前,共有 4 個層級。 如果不使用 <StripLevels>,轉換後的 JSON 回應會如下所示:

{
   "Envelope" : {
      "Body" : {
         "GetCityWeatherByZIPResponse" : {
            "GetCityWeatherByZIPResult" : {
               "State" : "CO",
               "City" : "Denver",
               "Description" : "Sunny",
               "Temperature" : "62"
            }
         }
      }
   }
}

如要從 JSON 回應中移除前 4 個層級,請設定 <StripLevels>4</StripLevels>,這樣就會得到下列 JSON:

{
  "State" : "CO",
  "City" : "Denver",
  "Description" : "Sunny",
  "Temperature" : "62"
}

您可以移除層級,直到包含多個子項的第一個元素為止。這是什麼意思?以下是較為複雜的 JSON 範例:

{
   "Envelope" : {
      "Body" : {
         "GetCityForecastByZIPResponse" : {
            "GetCityForecastByZIPResult" : {
               "ResponseText" : "City Found",
               "ForecastResult" : {
                  "Forecast" : [
                     {
                        "ProbabilityOfPrecipiation" : {
                           "Nighttime" : "00",
                           "Daytime" : 10
                        }  ...

在本例中,第 3 層是 GetCityForecastByZIPResponse,只有一個子項。因此,如果您使用 <StripLevels>3</StripLevels> (移除前三個層級),JSON 會如下所示:

{
   "GetCityForecastByZIPResult" : {
      "ResponseText" : "City Found",
      "ForecastResult" : {
         "Forecast" : [
            {
               "ProbabilityOfPrecipiation" : {
                  "Nighttime" : "00",
                  "Daytime" : 10
               }  ...

請注意,GetCityForecastByZIPResult 有多個子項。由於這是第一個包含多個子項的元素,因此您可以使用 <StripLevels>4</StripLevels> 剝除最後一個層級,這會產生下列 JSON:

{
   "ResponseText" : "City Found",
   "ForecastResult" : {
      "Forecast" : [
         {
            "ProbabilityOfPrecipiation" : {
               "Nighttime" : "00",
               "Daytime" : 10
            }  ...

由於第 4 層是第一個包含多個子項的層級,因此您無法剝除任何低於這個層級的層級。如果將帶狀區域等級設為 5、6、7 等,您仍會收到上述回應。

預設 0 (不剝除任何層級)
存在必要性 選用
類型 整數

<TreatAsArray> 元素/<Path> 元素

<Options>
    <TreatAsArray>
        <Path unwrap="true">teachers/teacher/studentnames/name</Path>
    </TreatAsArray>
</Options>

這個元素組合可確保 XML 文件中的值一律會轉換為 JSON 陣列。如果不同有效負載的子項元素數量不同,這項功能就非常實用。Apigee 的預設行為是將多個同名子項元素轉換為 JSON 陣列,並將單一子項元素轉換為 JSON 基本型別。TreatAsArray 選項可確保子元素一律會翻譯為 JSON 陣列。

使用 TreatAsArray 可改善後續處理輸出的程式碼結構,因為陣列中的資料每次都會以相同方式傳回。舉例來說,評估 $.teachers.teacher.studentnames.name[0] 的 JSONPath 時,無論原始 XML 包含一個或多個 name 元素,都會一律傳回名字值。

我們先回顧 XML 到 JSON 的預設行為,然後瞭解如何使用 <TreatAsArray>/<Path> 控制輸出內容。

如果 XML 文件包含多次出現的元素 (XML 結構定義為元素指定 maxOccurs='unbounded' 時可能會發生這種情況),XML 至 JSON 政策會自動將這些值放入陣列。舉例來說,下列 XML 區塊

<teacher>
    <name>teacherA</name>
    <studentnames>
        <name>student1</name>
        <name>student2</name>
    </studentnames>
</teacher>

...會自動轉換為下列 JSON,不需要任何特殊政策設定:

{
  "teachers" : {
    "teacher" : {
      "name" : "teacherA",
      "studentnames" : {
        "name" : [
          "student1",
          "student2"
        ]
      }
    }
  }
}

請注意,這兩個學生姓名都包含在陣列中。

不過,如果 XML 文件中只有一位學生,XML 轉 JSON 政策會自動將值視為單一字串,而非字串陣列,如下列範例所示:

{
  "teachers" : {
    "teacher" : {
      "name" : "teacherA",
      "studentnames" : {
        "name" : "student1"
      }
    }
  }
}

在先前的範例中,類似的資料會以不同方式轉換,一次轉換為陣列,另一次轉換為單一字串。<TreatAsArray>/<Path> 元素可讓您控制輸出內容,確保即使只有一個值,學生姓名一律會轉換成陣列。如要設定這項功能,請找出要轉換為陣列的元素路徑,如下所示:

<Options>
    <TreatAsArray>
        <Path>teachers/teacher/studentnames/name</Path>
    </TreatAsArray>
</Options>

上述設定會產生如下所示的 JSON:

{
  "teachers" : {
    "teacher" : {
      "name" : "teacherA",
      "studentnames" : {
        "name" : ["student1"]
      }
    }
  }
}

請注意,student1 現在位於陣列中。現在,無論學生人數多寡,您都可以使用下列 JSONPath,從程式碼中的 JSON 陣列擷取學生: $.teachers.teacher.studentnames.name[0]

<Path> 元素也有 unwrap 屬性,詳情請見下一節。

預設 不適用
存在必要性 選用
類型 字串

屬性

 <Options>
    <TreatAsArray>
        <Path unwrap="true">teachers/teacher/studentnames/name</Path>
    </TreatAsArray>
</Options>
屬性 說明 存在必要性 類型
unwrap

預設值:false

從 JSON 輸出中移除元素。您可以使用這項功能簡化或平坦化 (「解除包裝」) JSON,縮短擷取值所需的 JSONPath。舉例來說,您可以將 JSON 攤平,並使用 $.teachers.studentnames[*],而非 $.teachers.teacher.studentnames.name[*]

JSON 範例如下:

{
  "teachers" : {
      "teacher" : {
          "name" : "teacherA",
          "studentnames" : {
              "name" : [
                 "student1",
                 "student2"
              ]}...

在這個範例中,您可以主張 teacher 元素和 studentnames name 元素是不必要的。因此您可以移除或取消包裝。如要設定 <Path> 元素來執行這項操作,請按照下列步驟操作:

<TreatAsArray>
    <Path unwrap="true">teachers/teacher</Path>
    <Path unwrap="true">teachers/teacher/studentnames/name</Path>
</TreatAsArray>

unwrap 屬性設為 true,並提供要解除包裝的元素路徑。JSON 輸出內容現在應如下所示:

{
  "teachers" : [{
      "name" : "teacherA",
      "studentnames" : ["student1","student2"]
      }]...

請注意,由於 <Path> 元素位於 <TreatAsArray> 元素中,因此路徑中的兩個元素都會在 JSON 輸出中視為陣列。

選用 布林值

如需更多範例和功能逐步說明,請參閱 這篇 Google Cloud 社群文章

<Format>

格式可讓您控管 XML 到 JSON 的轉換作業。輸入預先定義的範本名稱,該範本包含本主題所述的特定選項元素組合。預先定義的格式包括:xml.comyahoogooglebadgerFish

使用 <Format> 元素或 <Options> 群組。您無法同時使用 <Format><Options>

以下是每個預先定義範本的格式定義。

xml.com

<RecognizeNull>true</RecognizeNull>
<TextNodeName>#text</TextNodeName>
<AttributePrefix>@</AttributePrefix>

yahoo

<RecognizeNumber>true</RecognizeNumber>
<TextNodeName>content</TextNodeName>

google

<TextNodeName>$t</TextNodeName>
<NamespaceSeparator>$</NamespaceSeparator>
<TextAlwaysAsProperty>true</TextAlwaysAsProperty>

badgerFish

<TextNodeName>$</TextNodeName>
<TextAlwaysAsProperty>true</TextAlwaysAsProperty>
<AttributePrefix>@</AttributePrefix>
<NamespaceSeparator>:</NamespaceSeparator>
<NamespaceBlockName>@xmlns</NamespaceBlockName>
<DefaultNamespaceNodeName>$</DefaultNamespaceNodeName>

元素語法:

<Format>yahoo</Format>
預設 (無)
有效值 下列其中一項:
xml.comyahoogooglebadgerFish
存在必要性 選填,但如果未使用 <Options>,則為必填。
類型 字串

結構定義


錯誤參考資料

This section describes the fault codes and error messages that are returned and fault variables that are set by Apigee when this policy triggers an error. This information is important to know if you are developing fault rules to handle faults. To learn more, see What you need to know about policy errors and Handling faults.

Runtime errors

These errors can occur when the policy executes.

Fault code HTTP status Cause Fix
steps.xmltojson.ExecutionFailed ExecutionFailed This error occurs when the input payload (XML) is empty or the input XML is invalid or malformed.
steps.xmltojson.InCompatibleTypes ExecutionFailed This error occurs if the type of the variable defined in the <Source> element and the <OutputVariable> element are not the same. It is mandatory that the type of the variables contained within the <Source> element and the <OutputVariable> element matches.
steps.xmltojson.InvalidSourceType ExecutionFailed This error occurs if the type of the variable used to define the <Source> element is invalid.The valid types of variable are message and string.
steps.xmltojson.OutputVariableIsNotAvailable ExecutionFailed This error occurs if the variable specified in the <Source> element of the XML to JSON policy is of type string and the <OutputVariable> element is not defined. The <OutputVariable> element is mandatory when the variable defined in the <Source> element is of type string.
steps.xmltojson.SourceUnavailable ExecutionFailed This error occurs if the message variable specified in the <Source> element of the XML to JSON policy is either:
  • Out of scope (not available in the specific flow where the policy is being executed) or
  • Can't be resolved (is not defined)

Deployment errors

These errors can occur when you deploy a proxy containing this policy.

Error name Cause Fix
EitherOptionOrFormat If one of the elements <Options> or <Format> is not declared in the XML to JSON Policy, then the deployment of the API proxy fails.
UnknownFormat If the <Format> element within the XML to JSON policy has an unknown format defined, then the deployment of the API proxy fails. Predefined formats include: xml.com, yahoo, google, and badgerFish.

Fault variables

These variables are set when a runtime error occurs. For more information, see What you need to know about policy errors.

Variables Where Example
fault.name="fault_name" fault_name is the name of the fault, as listed in the Runtime errors table above. The fault name is the last part of the fault code. fault.name = "SourceUnavailable"
xmltojson.policy_name.failed policy_name is the user-specified name of the policy that threw the fault. xmltojson.XMLtoJSON-1.failed = true

Example error response

{
  "fault": {
    "faultstring": "XMLToJSON[XMLtoJSON-1]: Source xyz is not available",
    "detail": {
      "errorcode": "steps.xml2json.SourceUnavailable"
    }
  }
}

Example fault rule

<faultrule name="VariableOfNonMsgType"></faultrule><FaultRule name="XML to JSON Faults">
    <Step>
        <Name>AM-SourceUnavailableMessage</Name>
        <Condition>(fault.name Matches "SourceUnavailable") </Condition>
    </Step>
    <Step>
        <Name>AM-BadXML</Name>
        <Condition>(fault.name = "ExecutionFailed")</Condition>
    </Step>
    <Condition>(xmltojson.XMLtoJSON-1.failed = true) </Condition>
</FaultRule>

相關主題

JSON 轉 XML:JSONtoXML 政策