Hello experts. I am trying to do this logic:
XMLNodeL := XMLDocInP.SelectSingleNode('/soap12:Envelope/soap12:Body/GetRequest',XMLNamespaceMgrL);
IF NOT ISNULL(XMLNodeL) THEN
EXIT(Rec."Get record");
on this XML file:
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="
http://www.w3.org/2001/XMLSchema" xmlns:soap12="
http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetRequest xmlns="
http://wa.dms.webservice/GetRequest">
<TransactionHeader>
<CountryID>string</CountryID>
<DistributorID>string</DistributorID>
</TransactionHeader>
<DealerID>string</DealerID>
<EmployeeNo>string</EmployeeNo>
<LastModifiedDateTimeFromUTC>dateTime</LastModifiedDateTimeFromUTC>
<LastModifiedDateTimeToUTC>dateTime</LastModifiedDateTimeToUTC>
</GetRequest>
</soap12:Body>
</soap12:Envelope>
But it doesn't initialize XMLNodeL and returns nothing.
Have I defined string in SelectSingleNode wrong?
Thank you!
Answers
IF ISNULL(XMLNamespaceMgrP) THEN
XMLNamespaceMgrP := XMLNamespaceMgrP.XmlNamespaceManager(XMLDocInP.NameTable);
XMLNamespaceMgrP.AddNamespace('soap12','http://www.w3.org/2003/05/soap-envelope');
XMLNodeL := XMLDocInP.SelectSingleNode('/soap12:Envelope',XMLNamespaceMgrP);
IF NOT ISNULL(XMLNodeL) THEN BEGIN
XMLAttributeL := XMLNodeL.Attributes.GetNamedItem('xmlns');
IF NOT ISNULL(XMLAttributeL) THEN
NsNamespaceL := FORMAT(XMLAttributeL.Value);
IF NsNamespaceL = '' THEN BEGIN
XMLNodeL := XMLDocInP.SelectSingleNode('/soap12:Envelope/soap12:Body',XMLNamespaceMgrP);
IF NOT ISNULL(XMLNodeL) THEN BEGIN
XMLChildNodeL := XMLNodeL.FirstChild;
IF NOT ISNULL(XMLChildNodeL) THEN BEGIN
XMLAttributeL := XMLChildNodeL.Attributes.GetNamedItem('xmlns');
IF NOT ISNULL(XMLAttributeL) THEN
NsNamespaceL := FORMAT(XMLAttributeL.Value);
END;
END;
END;
END;
XMLNodeL := XMLDocInP.SelectSingleNode('/soap12:Envelope/soap12:Body/GetRequest');
instead of
XMLNodeL := XMLDocInP.SelectSingleNode('/soap12:Envelope/soap12:Body/GetRequest',XMLNamespaceMgrL);
because you've already definded the full xPath and don't need the Manager.
Hope, it helps