Inspect XML Attributes and Repeated Elements After Conversion

Convert a fictional XML catalog to JSON while checking how attributes, repeated tags, and mixed text are represented.

By DevSphere Editorial · · 5 min read

Open Converter

Plan for XML-to-object mapping

XML and JSON organize information differently, so converting one to the other requires choices about attributes, repeated elements, text, and empty values. Format Converter supports XML input with JSON, CSV, String, or YAML output. Its XML parser uses the browser DOMParser and converts attributes into an @attributes object; repeated child element names become arrays. This is a practical representation for a small catalog but not a universally agreed mapping, and it does not preserve every XML feature. Use a fictional snippet with one attribute and two repeated entry elements. The aim is to understand the output shape before designing a consumer. Keep the original XML because any object conversion may lose comments, namespace details, or mixed-content ordering.

<?xml version="1.0"?>
<catalog><entry code="D-1"><title>Demo Map</title></entry><entry code="D-2"><title>Sample Guide</title></entry></catalog>

Select the XML to JSON route

Open Format Converter, choose XML in From, and JSON in To. XML offers JSON, CSV, String, and YAML outputs. Paste the sample into the input panel and wait for the output to update. The XML parser checks for a DOMParser error and then walks the document element. The root catalog contains two entry children with the same tag name, so the converter should represent entry as an array. Each entry's code attribute should appear under @attributes, while title is a child property. The output panel displays indented JSON. If the input is malformed, the error panel indicates invalid XML rather than producing a JSON result. This is basic parsing, not an XSD validator.

Read the generated structure

Inspect the JSON output for the catalog root, the entry array, and two objects. Confirm the first code value is D-1 and title is Demo Map; the second is D-2 and Sample Guide. The attribute representation is a converter convention, not a property required by JSON. Empty XML elements may become null, and leaf elements with only text become strings. Mixed content is more complicated: this parser joins direct text nodes and handles element children separately, so the original ordering between text and nested elements may not be retained. CDATA handling, comments, processing instructions, and namespace semantics should be verified before depending on the result. XML prefixes and namespace URIs may not appear in a way that preserves the full namespace model. Treat this conversion as a useful inspection mapping, not a lossless archive format.

{
  "entry": [
    {"@attributes": {"code": "D-1"}, "title": "Demo Map"},
    {"@attributes": {"code": "D-2"}, "title": "Sample Guide"}
  ]
}

Choose another output only with a defined shape

CSV output may be helpful if repeated entry objects share scalar fields, but attributes stored under @attributes are nested and may not become obvious columns. YAML output uses the converter's simple YAML serializer and may likewise represent the attribute object in a way that needs review. String output creates an escaped JSON string representation rather than retaining original XML bytes. The conversion matrix prevents unsupported choices such as XML to HTML in this tool. Before changing the destination, decide which fields should become columns or how attributes should be flattened. Do not assume a one-click format switch preserves meaning. If the receiving application expects specific property names, map them deliberately and validate with its schema.

Verify and troubleshoot the mapping

If JSON output is empty, check that XML input is complete and contains a single valid document root. Confirm tags are closed, attributes are quoted, and entity characters such as ampersands are escaped. Then verify two entry records, attribute codes, and titles against the original. The Converter uses the browser XML parser for well-formedness but does not validate DTD or XSD rules, and its XML-to-object logic is a simplified mapping rather than a full XML data model implementation. If mixed content, namespaces, or signatures matter, use an XML-aware library and an explicit mapping. Copy is available on the output panel, but keep the original XML separately. The utility does not retrieve external resources or perform a network request. Use only synthetic examples for public tutorials and approved channels for real records.

The repeated-element case is why the sample contains two entry tags: a single child may first be represented as one value, then repeated occurrences are promoted to an array. A consumer that assumes entry is always an array can therefore encounter a shape change when the XML has only one record. If the application needs a stable array shape regardless of count, normalize it after parsing and test documents with zero, one, and multiple entries. The generated @attributes object is also a convention the recipient must understand. XML attributes are not children, and mapping them to JSON properties is a design choice. Write down that mapping in the consumer rather than depending on a visual resemblance. Preserve raw XML for troubleshooting cases where namespace or mixed-text behavior matters.

The example also contains only element text, so it does not exercise mixed content such as text surrounding a child element. The parser collects direct text nodes separately from element children and may not preserve the original interleaving. Namespaces need care too: DOM node names can include prefixes, but the object conversion is not a namespace-aware contract mapper. A robust integration should define how prefixes, expanded namespace names, attributes, and text are represented, then test that mapping with representative documents. The Converter can help a reviewer see a simple shape quickly. It cannot replace that design, and JSON output should not be treated as a lossless copy of an XML document.

Browse all tutorials