JSON to XML Convertor with XSD Validation
In the following example, the Map input to first repeating element in XSD field is selected.
Assume the given XSD file is:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:books" xmlns:bks="urn:books">
<xsd:element name="books" type="bks:BooksForm"/>
<xsd:complexType name="BooksForm">
<xsd:sequence>
<xsd:element name="book" type="bks:BookForm" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="BookForm">
<xsd:sequence>
<xsd:element name="author" type="xsd:string" maxOccurs="unbounded"/>
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="genre" type="xsd:string"/>
<xsd:element name="price" type="xsd:float" />
<xsd:element name="pub_date" type="xsd:date" />
<xsd:element name="review" type="xsd:string"/>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string"/>
</xsd:complexType>
</xsd:schema>
Suppose the following are the two input documents:
[
{
"@id": "bk001",
"title": "The First Book",
"author": "John Smith",
"genre": "Fiction",
"price": "44.95",
"pub_date": "2000-10-01",
"review": "An amazing story of nothing." },
{
"@id": "bk002",
"title": "The Poet's First Poem",
"author": "Mary Parker",
"genre": "Poem",
"price": "24.95",
"pub_date": "2000-10-01",
"review": "Least poetic poems." }
]
The Snap extracts "books" as the root element name and "book" as the wrapper name
from the XSD file.The following is the default XML
output:
<?xml version='1.0' encoding='UTF-8'?>
<books>
<book id="bk001">
<title>The First Book</title>
<author>John Smith</author>
<genre>Fiction</genre>
<price>44.95</price>
<pub_date>2000-10-01</pub_date>
<review>An amazing story of nothing.</review>
</book>
<book id="bk002">
<title>The Poet's First Poem</title>
<author>Mary Parker</author>
<genre>Poem</genre>
<price>24.95</price>
<pub_date>2000-10-01</pub_date>
<review>Least poetic poems.</review>
</book>
</books>
The following is the canonical XML output:
<books>
<book id="bk001">
<title>The First Book</title>
<author>John Smith</author>
<genre>Fiction</genre>
<price>44.95</price>
<pub_date>2000-10-01</pub_date>
<review>An amazing story of nothing.</review>
</book>
<book id="bk002">
<title>The Poet's First Poem</title>
<author>Mary Parker</author>
<genre>Poem</genre>
<price>24.95</price>
<pub_date>2000-10-01</pub_date>
<review>Least poetic poems.</review>
</book>
</books>
- Download and import the pipeline in to the SnapLogic Platform.
- Configure Snap accounts, as applicable.
- Provide pipeline parameters, as applicable.