XML Generation Examples
In the examples which follow, AM represents an attribute mark, VM a value mark and SVM a subvalue mark. The results are generated from a dynamic array containing the following data:
CognosVMNorthgate Public ServicesAMWesterly PointAM
Market StreetVMBoundary WayAM
BracknellSVMBerkshireVMHemel HempsteadSVMHertsAM
RG12 1QBVMHP2 7HU
Example 1 - Single parameter substitution
Template
<address>
<line2>svm2svm</line2>
</address>
Result
<address>
<line2>Westerly Point</line2>
</address>
Comments
Extracts attribute 2 from the array and inserts it as the value of the node
<line2>
.
Example 2 - Value extraction
Template
<address>
<line1>svm1,2svm</line1>
</address>
Result
<address>
<line1>Northgate Public Services</line1>
</address>
Comments
Extracts attribute 1, value 2 from the array and inserts it as the value of
the node <line1>
.
Example 3 - Subvalue extraction
Template
<address>
<line4>svm4,2,1svm</line4>
</address>
Result
<address>
<line4>Hemel Hempstead</line4>
</address>
Comments
Extracts attribute 4, value 2, subvalue 1 from the array and inserts it as
the value of the node <line4>
.
Example 4 - Multiple parameter substitution
Template
<address>
<line1>svm1,2svm</line1>
<line3>svm3,2svm</line3>
<line4>svm4,2,1svm</line4>
<postcode>svm5,2svm<postcode>
</address>
Result
<address>
<line1>Northgate Public Services</line1>
<line3>Boundary Way</line3>
<line4>Hemel Hempstead</line4>
<postcode>HP2 7HU</postcode>
</address>
Comments
Extracts value 2 from each of attributes 1, 3 and 5, and subvalue 1 from value 2 of attribute 4, and inserts them as the values of appropriate XML nodes.
Example 5 - Optional line included
Template
<address>
<line1>svm1,1svm</line1>
VM <line2>svm2,1svm</line2>VM
<line3>svm3,1svm</line3>
<line4>svm4,1,1svm</line4>
<postcode>svm5,1svm<postcode>
</address>
Result
<address>
<line1>Cognos</line1>
<line2>Westerly Point</line2>
<line3>Market Street</line3>
<line4>Bracknell</line4>
<postcode>RG12 1QB</postcode>
</address>
Comments
This is similar to Example 4,
but the <line2>
node has been added as optional data, referencing
attribute 2, value 1 of the array. Because this evaluates to the text "Westerly Point",
the <line2>
node is included in the result.
Example 6 - Optional line excluded
Template
<address>
<line1>svm1,2svm</line1>
VM <line2>svm2,2svm</line2>VM
<line3>svm3,2svm</line3>
<line4>svm4,2,1svm</line4>
<postcode>svm5,2svm<postcode>
</address>
Result
<address>
<line1>Northgate Public Services</line1>
<line3>Boundary Way</line3>
<line4>Hemel Hempstead</line4>
<postcode>HP2 7HU</postcode>
</address>
Comments
This is similar to Example 5, but in
this case, the optional node references attribute 2, value 2 of the array.
Because this evaluates to a null string, the <line2>
node is omitted
from the result.
Example 7 - Substitute parameters
Template
<address line1="svm1,1svm" vmline2="svm2,1svm" vmpostcode="svm5,1svm"> </address>
Result
<address line1="Cognos" line2="Westerly Point" postcode="RG12 1QB"> </address>
Comments
This shows how you can set the values of node attributes, rather than node
values. The line2
attribute is optional, but is included in the result
because attribute 2, value 1 of the array evaluates to the text "Westerly Point".
Example 8 - Exclude a parameter
Template
<address line1="svm1,2svm" vmline2="svm2,2svm" vmpostcode="svm5,2svm"> </address>
Result
<address line1="Northgate Public Services" postcode="HP2 7HU"> </address>
Comments
This is similar to Example 7, but the
optional line2
attribute is omitted from the result because attribute
2, value 1 of the array evaluates to a null string.
Example 9 - Alternate delimiters
Template
<__nis_cont paramDelim="%" optionalDelim="$"/> <address> <line1>%1,2%</line1> $ <line2>%2,2%</line2>$ <line3>%3,2%</line3> <line4>%4,2,1%</line4> <postcode>%5,2%<postcode> </address>
Result
<address>
<line1>Northgate Public Services</line1>
<line3>Boundary Way</line3>
<line4>Hemel Hempstead</line4>
<postcode>HP2 7HU<postcode>
</address>
Comments
This is similar to Example 6, but the delimiters have been changed to percent signs instead of subvalue marks, and dollar signs instead of value marks.