Tools, FAQ, Tutorials:
Mapping Repeating XML Elements to a JSON Array
What is the standard to map XML repeating elements to JSON values?
✍: FYIcenter.com
There seems to be no industry standard on how to map XML repeating elements to JSON values. 
But there are some commonly used conventions:
1. Aggregating continuously repeating XML sub elements to a single JSON object property. If a chunk of continuously repeating XML sub elements is detected, all repeating elements are aggregated into a single JSON object property. The property name is set to the common element name and the property value is set to an array holding child information of each repeating sub element. For example:
XML:
<ol>
  <li>Scope</li>
  <li>Time</li>
  <li>Cost</li>
</ol>
JSON: 
{
  "ol": {
    "li": [
      "Scope",
      "Time",
      "Cost"
    ]
  }
}
2. Aggregating scattered repeating XML sub elements to a single JSON object property. If a set of scattered repeating XML sub elements (multiple XML sub elements with a common element name are scattered among other sibling sub elements or text contents) is detected, all repeating elements are aggregated into a single JSON object property. The property name is set to the common element name and the property value is set to an array holding child information of each repeating sub element. For example:
XML:
<body>
  <p>Username:</p>
  <blockquote>nobody</blockquote>
  <p>Password:</p>
  <blockquote>noidea</blockquote>
</body>
JSON:
{
  "body": {
    "p": [
      "Username:",
      "Password:"
    ],
    "blockquote": [
      "nobody",
      "noidea"
    ]
  }
}
Note that aggregating scattered repeating XML sub elements to a single JSON object property will damage the order of XML sub elements in which they are listed in the parent element. In most cases, the order of sub elements is not important to applications that are consuming the message.
⇒ Mapping XML Elements with Mixed Contents to JSON Values
2023-07-08, ∼3647🔥, 0💬
Popular Posts:
How to start Docker Daemon, "dockerd", on CentOS systems? If you have installed Docker on your CentO...
How to access Query String parameters from "context.Request.Url.Que ry"object in Azure API Policy? Q...
How to use "{{...}}" Liquid Codes in "set-body" Policy Statement? The "{{...}}" Liquid Codes in "set...
How to use the "Ctrl-p Ctrl-q" sequence to detach console from the TTY terminal of container's runni...
Where to find tutorials on PHP language? I want to know how to learn PHP. Here is a large collection...