static
void ReadXml(Args _args)
{
XmlDocument xmlDoc;
XmlElement xmlRoot;
XmlElement xmlField;
XmlElement xmlRecord;
XmlNodeList xmlRecordList;
XmlNodeList xmlFieldList;
CarTable carTable;
DictTable dTable = new DictTable(tablenum(CarTable));
int i, j, fieldId;
#CarsXmlTags
// Create an XmlDocument object to hold the
// contents of the xml-file
xmlDoc = new XmlDocument();
// Load the content of the xml-file
// into the XmlDocument object
xmlDoc.load(@”c:\temp\cars.xml”);
// Get the root node
xmlRoot = xmlDoc.getNamedElement(#CarRootNode);
// Get all child nodes (records)
xmlRecordList = xmlRoot.childNodes();
// Loop through the list of records
for (i=0; i<xmlRecordList.length(); i++)
{
carTable.clear();
// Get the current record from the
// record list
xmlRecord = xmlRecordList.item(i);
// Get all child nodes (fields)
xmlFieldList = xmlRecord.childNodes();
// Loop through the list of fields
for (j=0; j<xmlFieldList.length(); j++)
{
// Get the current field from the
// field list
xmlField = xmlFieldList.item(j);
// Set the matching field in the carTable
// to be equal to the inner text
// (the text between the tag and end tag).
carTable.(dTable.fieldName2Id(xmlField.name())) =
xmlField.innerText();
}
// Insert the record into the carTable
carTable.insert();
}
} |