Getting text value's out of XmlNodes makes D365 crash
Our procedure for getting text value's out of XmlNodes according to Github "How to get XmlText from XmlNode?" #556
local procedure getNodeValue(ParentXmlNode : XmlNode;Xpath : Text) : Text;
var
DataXmlNode : XmlNode;
NodeValue : Text;
begin
if(ParentXmlNode.SelectSingleNode(Xpath+'/text()',DataXmlNode)) then
begin
if(DataXmlNode.IsXmlText) then
begin
NodeValue := DataXmlNode.AsXmlText.Value;
if(NodeValue <> '') then
EXIT(DELCHR(NodeValue,'=', '"'))
else
EXIT('');
end;
end;
EXIT('');
end;
But the line 'NodeValue := DataXmlNode.AsXmlText.Value;' makes D365 crash and the eventviewer shows and null pointerexception, if the selected node does not have any value.
According to Github How do I use ISNULL? #554, this should not happen when using SelectSingleNode function for AL XML types.
XML example :
<keyvalueid>
<key>KEYNAME</key>
<value/>
</keyvalueid>
It is the nodename value that fails, because it does not have any text value. This is a major problem for us, because there can be many nodesnames without any textvalue.
You are right, the crash should not happen. I will investigate and get back to you