This is the Codeunit I have so far:
{
[ServiceEnabled]
procedure saveCustVend(_custVendDC: Text): Text
var
RootNode: XmlNode;
AccountNum: Text[20];
Name: Text[100];
begin
// Load XML from text
if not LoadXMLNodeFromText(_custVendDC, RootNode) then
Error('Failed to load XML document.');
AccountNum := FindNodeTextWithNameSpace(RootNode, 'd4p1:AccountNum', 'd4p1', 'http://schemas.datacontract.org/2004/07/Dynamics.AX.Application');
if AccountNum = '' then
Error('AccountNum node not found.');
Name := FindNodeTextWithNameSpace(RootNode, 'd4p1:Name', 'd4p1', 'http://schemas.datacontract.org/2004/07/Dynamics.AX.Application');
if Name = '' then
Error('Name node not found.');
exit('AccountNum: ' + AccountNum + ', Name: ' + Name);
end;
procedure LoadXMLNodeFromText(pXMLText: Text; var pXMLRootNode: XmlNode): Boolean
var
lXmlDocument: XmlDocument;
begin
LoadXMLDocumentFromText(pXMLText, lXmlDocument);
pXMLRootNode := lXmlDocument.AsXmlNode;
exit(not pXMLRootNode.AsXmlElement().IsEmpty);
end;
procedure LoadXMLDocumentFromText(pXMLText: Text; var pXMLDocument: XmlDocument)
begin
if pXMLText = '' then
exit;
XmlDocument.ReadFrom(pXMLText, pXMLDocument);
end;
procedure FindNodeTextWithNameSpace(pXMLRootNode: XmlNode; pNodePath: Text; pPrefix: Text; pNamespace: Text): Text
var
lXmlNode: XmlNode;
lXmlNsMgr: XmlNamespaceManager;
begin
if pXMLRootNode.AsXmlElement.IsEmpty then
exit('');
lXmlNsMgr.NameTable(pXMLRootNode.AsXmlDocument.NameTable);
lXmlNsMgr.AddNamespace(pPrefix, pNamespace);
exit(lXmlNode.AsXmlElement.InnerText);
exit('');
end;
}
With this codeunit I get this response:
<s:Body>
<s:Fault>
<faultcode xmlns:a="urn:microsoft-dynamics-schemas/error">a:Microsoft.Dynamics.Nav.Types.Exceptions.NavNCLXmlException</faultcode>
<faultstring xml:lang="en-US">The following exception was encountered when processing XML data: 'Data at the root level is invalid. Line 2, position 3.' at line 2 and position 3.</faultstring>
<detail>
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">The following exception was encountered when processing XML data: 'Data at the root level is invalid. Line 2, position 3.' at line 2 and position 3.</string>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>