Tools, FAQ, Tutorials:
Mapping XML Attributes to JSON Values
What is the standard to map XML Attributes to JSON Values?
✍: FYIcenter.com
There seems to be no industry standard on how to map XML Attributes to JSON Values.
But there are some commonly used conventions:
1. Converting each XML attribute to a single JSON object property. The property name is set to the attribute name and the property value is set to the attribute value. For example:
XML:
<div id="1001" class="banner"/>
JSON:
{
"div": {
"id": "1001",
"class": "banner"
}
}
2. Prefixing XML attribute name with "@". To differentiate JSON object properties converted from XML attributes from XML sub elements, "@" is added to each XML attribute name. For example:
XML:
<div id="1001" class="banner"/>
JSON:
{
"div": {
"@id": "1001",
"@class": "banner"
}
}
3. Converting empty XML attributes to JSON properties with Null values. If the value of an XML attribute is an empty string, it is converted to the JSON Null value. For example:
XML:
<div id="1001" class=""/>
JSON:
{
"div": {
"@id": "1001",
"@class": null
}
}
⇒ Mapping XML Simple Elements to JSON Values
2023-07-08, ∼3730🔥, 0💬
Popular Posts:
How to login to Azure API Management Publisher Dashboard? If you have given access permission to an ...
How To Get the Minimum or Maximum Value of an Array in PHP? If you want to get the minimum or maximu...
How To Access a Global Variable inside a Function? in PHP? By default, global variables are not acce...
How To Convert a Character to an ASCII Value? If you want to convert characters to ASCII values, you...
How to register and get an application ID from Azure AD? The first step to use Azure AD is to regist...