XML to JSON Transformer

Descubra mais sobre o componente XML to JSON Transformer e saiba como utilizá-lo na Digibee Integration Platform.

O XML to JSON Transformer transforma um XML string em um objeto JSON.

Parâmetros

Dê uma olhada nas opções de configuração do componente. Parâmetros suportados por expressões Double Braces estão marcados com (DB).

Fluxo de mensagens

Entrada

O componente não espera uma mensagem de entrada específica, apenas o preenchimento do parâmetro de configuração XML Field Path referenciando o caminho do campo a ser transformado. Esse campo deve existir na mensagem do passo anterior à execução do XML to JSON Transformer.

Saída

A estrutura será igual a da recebida do passo anterior do fluxo, porém os campos informados no parâmetro XML Field Path serão transformados em sua representação de objeto JSON. Em caso de erro, a propriedade "error" será criada no mesmo nível da propriedade original.

Quando o parâmetro Preserve Original estiver ativado, para cada campo informado no parâmetro XML Field Path, será gerada uma nova propriedade apenas adicionando o caractere "_" no início de seu nome e contendo o XML string original.

A notação com pontos de JSON vai procurar pelo elemento raiz que está sendo processado pelo pipeline e realizar um cruzamento conforme as especificações passadas na propriedade XML Field Path.

Exemplo:

Em uma representação do XML Field Path contendo a.b.c.d, "a" será procurado no elemento raiz. Em seguida será o "b", depois o "c" e finalmente o "d". Se um array for encontrado durante o cruzamento, então o algoritmo vai gerar um caminho de cruzamento para cada elemento no array. O algoritmo substitui todas as ocorrências do caminho definido em XML Field Path.

XML to JSON Transformer em ação

Para todos os cenários abaixo, será considerado o seguinte payload contendo campo XML String:

{  
    "xmlField": "<?xml version=\"1.0\" ?><inf:ProductInformation xmlns:inf=\"urn:product:Info\" xmlns:stk=\"urn:product:Stock\"><inf:ProductName Code=\"C00001\">Computer</inf:ProductName><inf:Price Units=\"$\">2500</inf:Price><stk:Volume Units=\"Units\">200</stk:Volume></inf:ProductInformation>"
}

Transformação de XML

Entrada

Parâmetros

  • XML Field Path: xmlField

  • Preserve Original: false

  • With Namespace: false

  • Remove XML Attributes: false

  • All Values As String: false

Saída

{
  "xmlField": {
    "ProductInformation": {
      "ProductName": {
        "Code": "C00001",
        "content": "Computer"
      },
      "Price": {
        "Units": "$",
        "content": 2500
      },
      "Volume": {
        "Units": "Units",
        "content": 200
      },
      "xmlns:stk": "urn:product:Stock",
      "xmlns:inf": "urn:product:Info"
    }
  }
}

Transformação de XML com parâmetro Preserve Original ativado

Entrada

Parâmetros

  • XML Field Path: xmlField

  • Preserve Original: true

  • With Namespace: false

  • Remove XML Attributes: false

  • All Values As String: false

Saída

{
  "xmlField": {
    "ProductInformation": {
      "ProductName": {
        "Code": "C00001",
        "content": "Computer"
      },
      "Price": {
        "Units": "$",
        "content": 2500
      },
      "Volume": {
        "Units": "Units",
        "content": 200
      },
      "xmlns:stk": "urn:product:Stock",
      "xmlns:inf": "urn:product:Info"
    }
  },
  "_xmlField": "<?xml version=\"1.0\" ?><inf:ProductInformation xmlns:inf=\"urn:product:Info\" xmlns:stk=\"urn:product:Stock\"><inf:ProductName Code=\"C00001\">Computer</inf:ProductName><inf:Price Units=\"$\">2500</inf:Price><stk:Volume Units=\"Units\">200</stk:Volume></inf:ProductInformation>"
}

Transformação de XML com parâmetro With Namespace ativado

Entrada

Parâmetros

  • XML Field Path: xmlField

  • Preserve Original: false

  • With Namespace: true

  • Remove XML Attributes: false

  • All Values As String: false

Saída

{
  "xmlField": {
    "inf:ProductInformation": {
      "inf:Price": {
        "Units": "$",
        "content": 2500
      },
      "xmlns:stk": "urn:product:Stock",
      "xmlns:inf": "urn:product:Info",
      "inf:ProductName": {
        "Code": "C00001",
        "content": "Computer"
      },
      "stk:Volume": {
        "Units": "Units",
        "content": 200
      }
    }
  }
}

Transformação de XML com parâmetro Remove XML Attributes ativado

Entrada

Parâmetros

  • XML Field Path: xmlField

  • Preserve Original: false

  • With Namespace: false

  • Remove XML Attributes: true

  • All Values As String: false

Saída

{
  "xmlField": {
    "ProductInformation": {
      "ProductName": "Computer",
      "Price": 2500,
      "Volume": 200
    }
  }
}

Transformação de XML com parâmetro All Values As String ativado

Entrada

Parâmetros

  • XML Field Path: xmlField

  • Preserve Original: false

  • With Namespace: false

  • Remove XML Attributes: true

  • All Values As String: true

Saída

{
  "xmlField": {
    "ProductInformation": {
      "ProductName": "Computer",
      "Price": "2500",
      "Volume": "200"
    }
  }
}

Last updated