This example shows how you can import records from an XML document that may be nested in other tags. If the XML you're importing is created by another program and nested in some other tags, then you can use the xmldatasetlevel specifier to declare how deep the dataset tag is.
With the following schema:
xml
table accounts
xmldatasetlevel 3
field acctno varchar export/personnel/accounts/account@acctno ''
field first varchar export/personnel/accounts/account/firstName ''
field last varchar export/personnel/accounts/account/lastName ''
field balance float export/personnel/accounts/account/balance 0
Importing the following XML document:
<?xml version="1.0" encoding="utf-8"?>
<export>
<personnel>
<accounts>
<account acctno="12345">
<firstName>John</firstName>
<lastName>Smith</lastName>
<balance>1532.43</balance>
</account>
<account acctno="67890">
<firstName>Jane</firstName>
<lastName>Doe</lastName>
<balance>1.32</balance>
</account>
<account acctno="13579">
<firstName>Mike</firstName>
<lastName>Schmidt</lastName>
</account>
</accounts>
</personnel>
</export>
Will get you the same data as before. Instead of the 1st tag (<export>
)
being regarded as the dataset and seeing a single record (<personnel>
),
it will instead see the 3-deep tag as the dataset (accounts
) and three
<account>
records (which is what we want).