Hi All,
I am facing issue while reading a specific TAG in XML. Below is my XML in AX 2012. I am trying to read the XML which is in AIFQueueManager from in Dynamics AX (Table\AIFDocumentLog).
<?xml version="1.0" encoding="UTF-16"?>
-<TrvPBSMaindataServiceCreateRequest xmlns="schemas.microsoft.com/.../services">
-<TrvPBSMaindata xmlns="schemas.microsoft.com/.../TrvPBSMaindata">
-<TrvPBSMaindata class="entity">
<AmountCurr>15.84</AmountCurr>
<AmountLocal>15.84</AmountLocal>
<BusinessName>Subway</BusinessName>
<CardNumber>6677</CardNumber>
<CardType>PCARD</CardType>
<CatCode>1122</CatCode>
<CatCodesDesc>Subway</CatCodesDesc>
<ExchCode>USD</ExchCode>
<ExchCodeLocal>USD</ExchCodeLocal>
<Name>"Craft, Tamaria L"</Name>
<TransDate>2015-11-05</TransDate>
<UserField1/>
<UserField2>TX</UserField2>
<UserField3>TX</UserField3>
</TrvPBSMaindata>
</TrvPBSMaindata>
</TrvPBSMaindataServiceCreateRequest>
I need to read different XML TAG Values like "AmountCurr", CardNumber", "
Name". etc,
Is there any way that I can directly find the name of a TAG like "AmountCurr" and get the value from above XML.
I tried the below code but it was giving error in the red lines- XmlNode object not initialized.
str sourceXMLFile, sNumber, sName, sClass;
XmlDocument xmlDocument;
XmlNodeList nodeList;
XmlNode node;
XMLNodeListIterator xmlNodeListIterator;
Counter counter;
AifDocumentLog messageLog;
XmlElement element;
;
select firstOnly messageLog where messageLog.RecId == 5637146860 ;//5637147013;
sourceXMLFile = messageLog.DocumentXml;
xmlDocument = XmlDocument::newXml(sourceXMLFile);
nodeList = xmlDocument.selectNodes('//TrvPBSMainData');
xmlNodeListIterator = new xmlNodeListIterator(nodeList);
node = xmlNodeListIterator.value();
if(node.selectSingleNode('AmountCur'))
sNumber = node.selectSingleNode('AmountCur').text();
while(xmlNodeListIterator.moreValues())
{
counter++;
// node = xmlNodeListIterator.value();
if(node.selectSingleNode('AmountCur'))
sNumber = node.selectSingleNode('AmountCur').text();
if(node.selectSingleNode('CardNumber'))
sName = node.selectSingleNode('CardNumber').text();
if(node.selectSingleNode('Name'))
sClass = node.selectSingleNode('Name').text();
info(strFmt("Record %1: AmountCur - %2, CardNumber - %3, Name - %4",
counter,
sNumber,
sName,
sClass));
xmlNodeListIterator.nextValue();
Can anyone please help ?
*This post is locked for comments