XML Iterator in AX
static void XMLIteratorTest(Args _args)
{
str sourceXMLFile, sNumber, sName, sClass;
XmlDocument xmlDocument;
XmlNodeList nodeList;
XmlNode node;
XMLNodeListIterator xmlNodeListIterator;
Counter counter;
;
sourceXMLFile = "<SCHOOL>" +
"<STUDENT>" +
"<NUMBER>001</NUMBER>" +
"<NAME>Stud_A</NAME>" +
"<CLASS>8</CLASS>" +
"</STUDENT>" +
"<STUDENT>" +
"<NUMBER>002</NUMBER>" +
"<NAME>Stud_B</NAME>" +
"<CLASS>9</CLASS>" +
"</STUDENT>" +
"<STUDENT>" +
"<NUMBER>003</NUMBER>" +
"<NAME>Stud_C</NAME>" +
"<CLASS>7</CLASS>" +
"</STUDENT>" +
"</SCHOOL>";
xmlDocument = XmlDocument::newXml(sourceXMLFile);
nodeList = xmlDocument.selectNodes('//STUDENT');
xmlNodeListIterator = new xmlNodeListIterator(nodeList);
while(xmlNodeListIterator.moreValues())
{
counter++;
node = xmlNodeListIterator.value();
if(node.selectSingleNode('NUMBER'))
sNumber = node.selectSingleNode('NUMBER').text();
if(node.selectSingleNode('NAME'))
sName = node.selectSingleNode('NAME').text();
if(node.selectSingleNode('CLASS'))
sClass = node.selectSingleNode('CLASS').text();
info(strFmt("Record %1: Number - %2, Name - %3, Class - %4",
counter,
sNumber,
sName,
sClass));
xmlNodeListIterator.nextValue();
}
}
static void XMLIteratorTest(Args _args)
{
str sourceXMLFile, sNumber, sName, sClass;
XmlDocument xmlDocument;
XmlNodeList nodeList;
XmlNode node;
XMLNodeListIterator xmlNodeListIterator;
Counter counter;
;
sourceXMLFile = "<SCHOOL>" +
"<STUDENT>" +
"<NUMBER>001</NUMBER>" +
"<NAME>Stud_A</NAME>" +
"<CLASS>8</CLASS>" +
"</STUDENT>" +
"<STUDENT>" +
"<NUMBER>002</NUMBER>" +
"<NAME>Stud_B</NAME>" +
"<CLASS>9</CLASS>" +
"</STUDENT>" +
"<STUDENT>" +
"<NUMBER>003</NUMBER>" +
"<NAME>Stud_C</NAME>" +
"<CLASS>7</CLASS>" +
"</STUDENT>" +
"</SCHOOL>";
xmlDocument = XmlDocument::newXml(sourceXMLFile);
nodeList = xmlDocument.selectNodes('//STUDENT');
xmlNodeListIterator = new xmlNodeListIterator(nodeList);
while(xmlNodeListIterator.moreValues())
{
counter++;
node = xmlNodeListIterator.value();
if(node.selectSingleNode('NUMBER'))
sNumber = node.selectSingleNode('NUMBER').text();
if(node.selectSingleNode('NAME'))
sName = node.selectSingleNode('NAME').text();
if(node.selectSingleNode('CLASS'))
sClass = node.selectSingleNode('CLASS').text();
info(strFmt("Record %1: Number - %2, Name - %3, Class - %4",
counter,
sNumber,
sName,
sClass));
xmlNodeListIterator.nextValue();
}
}
Comments
Post a Comment