Configure the XML Connector Parser
When the REST XML connector parses XML files, it cannot infer from the XML tag whether it represents a collection or a structure. To get this information, the parser refers to a YAML file that maps XML entities to their type definition.
How to configure the XML parser YAML file
The YAML file maps all XML entities to one of the following categories: type attributes, types, primitives, structures, and collections.
Type Attributes
The typeAttribute key enables the parser to identify what is the XML type attribute.
XML
<element type=“int”>42</element>
YAML
typeAttribute: type
Types
The types key enables the parser to identify what is the Java type of the type denoted by the type attribute.
XML
<element type=“Int”>42</element>
<element type=“FortyTwo”>forty two</element>
YAML
types:
Int: java.lang.Integer
FortyTwo: java.lang.String
Primitives
The primitives key enables the parser to identify which XML entities describe elements with value. In cases where the XML element is not mapped in the YAML file, the parser identifies an element as primitive when it has no nested elements.
XML
<root>
<one>123</one>
<two/>
</root>
YAML
primitives:
- root.one
- root.two
Structures
XML
<root>
<structure1>
<value1>1</value1>
<value2>2</value2>
<value3>2</value3>
</structure1>
<structure2/>
</root>
YAML
structures:
- root.structure1
- root.structure2
Collections
The collection key enables the parser to identify which XML entities describe collections (arrays, lists, dictionaries). In cases where the element is not mapped in the YAML file, the parser identifies an element as an array when all of its nested elements have the same name.
XML
<root>
<array>
<value>1</value>
</array>
</root>
YAML
collections:
- root.array
Full example
XML
<?xml version="1.0" encoding="UTF-8"?>
<EngineDocList>
<DocVersion DataType="String">1.0</DocVersion>
<EngineDoc>
<ContentType DataType="String">OrderFormDoc</ContentType>
<DocumentId DataType="String">5c14c9b3-1528-3000-0088-0003ba9896f7</DocumentId>
<Instructions>
<Pipeline DataType="String">PaymentFA</Pipeline>
</Instructions>
<OrderFormDoc>
<Consumer>
<PaymentMech>
<CreditCard>
<Expires DataType="ExpirationDate">01/05</Expires>
<Number DataType="String">4111111111111111</Number>
<Type DataType="S32">1</Type>
</CreditCard>
<Type DataType="String">CreditCard</Type>
</PaymentMech>
</Consumer>
<DateTime DataType="DateTime">1544892484336</DateTime>
<GroupId DataType="String">5c14c9b3-1529-3000-0088-0003ba9896f7</GroupId>
<Id DataType="String">5c14c9b3-1529-3000-0088-0003ba9896f7</Id>
<Mode DataType="String">Y</Mode>
<Transaction>
<ChargeTypeCode DataType="String">S</ChargeTypeCode>
<Currency DataType="String">840</Currency>
<CurrentTotals>
<Totals>
<Total DataType="Money" Currency="840">1000</Total>
</Totals>
</CurrentTotals>
<Id DataType="String">5c14c9b3-152a-3000-0088-0003ba9896f7</Id>
<Type DataType="String">Auth</Type>
<ZeroAuthToVerify DataType="S32">0</ZeroAuthToVerify>
</Transaction>
</OrderFormDoc>
</EngineDoc>
<TimeIn DataType="DateTime">1544892484133</TimeIn>
<TimeOut DataType="DateTime">1544892485272</TimeOut>
</EngineDocList>
YAML
collections:
primitives:
structures:
- EngineDocList
- EngineDocList.EngineDoc.Instructions
- EngineDocList.EngineDoc.OrderFormDoc
- EngineDocList.EngineDoc.OrderFormDoc.Consumer
- EngineDocList.EngineDoc.OrderFormDoc.Consumer.PaymentMech
- EngineDocList.EngineDoc.OrderFormDoc.Consumer.PaymentMech.CreditCard
- EngineDocList.EngineDoc.OrderFormDoc.Transaction.CurrentTotals
- EngineDocList.EngineDoc.OrderFormDoc.Transaction.CurrentTotals.Totals
typeAttribute: DataType
types:
StartDate: java.lang.String
Money: java.math.BigDecimal
Numeric: java.math.BigDecimal
S32: java.lang.Long
ExpirationDate: java.lang.String
String: java.lang.String
DateTime: java.util.Date
Updated 4 months ago