I have my xml document as:
<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns="http://schemas.microsoft.com/dynamics/2011/01/documents/Message">
<Header>
<MessageId>{88031946-8E28-4054-834F-74608A9E7106}</MessageId>
<Action>http://tempuri.org/BankPositivePayService/find</Action>
</Header>
<Body>
<MessageParts xmlns="http://schemas.microsoft.com/dynamics/2011/01/documents/Message">
<header xmlns:Message="http://schemas.microsoft.com/dynamics/2011/01/documents/Message" xmlns:BankPositivePay="http://schemas.microsoft.com/dynamics/2008/01/documents/BankPositivePay" xmlns="">
<records>
<record>USA OPER</record>
<record1>34567</record1>
<record2>Rejected</record2>
<record3>1020</record3>
<record4>99.50</record4>
<record5>2013-08-28</record5>
<record6>1001</record6>
<record7>Earth Televisions</record7>
</records>
</header>
</MessageParts>
</Body>
</Envelope>
I am trying to get the value of the element record by using SelectingSingleNode moethod in dynamics ax. The code I am using is
/// <summary>
/// internal use only.
/// </summary>
/// <param name="filePath">
/// A String value.
/// </param>
/// <param name="gatewayMessage">
/// An instance of the <c>AifGatewayMessage</c> class.
/// </param>
private void writeFile(str filePath, AifGatewayMessage gatewayMessage)
{
System.Xml.Xsl.XslCompiledTransform managedTransform;
System.IO.StringReader stringReader;
System.IO.TextWriter textwriter;
System.Xml.XmlReader xmlReader;
System.Xml.XmlDocument doc;
System.Xml.XmlNode root;
System.Xml.XmlNamespaceManager nsmgr;
System.Xml.XmlNode node;
System.DateTime currentdatetime;
str bankAccountID;
str filename;
AifXml txml;
str xslFile = "C:\\test\\positivepay.xsl";
System.String ppFilePath;
// BP Deviation Documented
transportMessage.set_SubmittingUser('');
// BP Deviation Documentedxs
transportMessage.set_MessageXml(gatewayMessage.parmMessageXml());
// BP Deviation Documented
transportMessage.set_Encoding(gatewayMessage.parmEncoding());
if(gatewayMessage.parmMessageStream() != null)
{
// BP Deviation Documented
transportMessage.set_MessageStream(gatewayMessage.parmMessageStream());
}
managedTransform = new System.Xml.Xsl.XslCompiledTransform();
managedTransform.Load(xslFile);
txml=transportMessage.get_MessageXml();
//Finding bank name from txml
doc = new System.Xml.XmlDocument();
doc.LoadXml(txml);
root = doc.get_DocumentElement();
// Add the namespace.
nsmgr = new System.Xml.XmlNamespaceManager(doc.get_NameTable());
nsmgr.AddNamespace("ns1",strFmt("%1","http://schemas.microsoft.com/dynamics/2011/01/documents/Message"));
nsmgr.AddNamespace("ns2",strFmt("%1","http://schemas.microsoft.com/dynamics/2008/01/documents/BankPositivePay"));
node = root.SelectSingleNode("Envelope/Header/Body/MessageParts/header/records/record",nsmgr);
bankAccountID=node.get_InnerText();
stringReader = new System.IO.StringReader(txml);
xmlReader = System.Xml.XmlReader::Create(stringReader);
//Creating positive file name
currentDateTime= System.DateTime::get_UtcNow();
filename="AP"+bankAccountID+currentdatetime.ToString("yyyyMMddHHmm")+".txt";
ppFilePath=System.String::Format("{0}{1}","C:\\test\\",filename);
textwriter= new System.IO.StreamWriter(ppFilePath);
managedTransform.Transform(xmlReader,null,textwriter);
textwriter.Close();
try
{
// BP Deviation Documented
fileSystem.WriteFile(filePath, transportMessage);
}
catch (Exception::CLRError)
{
throw error(strfmt("@SYS95800", filePath,AifUtil::getClrErrorMessage()));
}
}
Why is the statement "node = root.SelectSingleNode("Envelope/Header/Body/MessageParts/header/records/record",nsmgr);" not working and always returning null? Is there any other way to navigate the document? I also tried "ns1:MessageParts/ns1:header/ns2:records/ns2:record".