Options

SelectSingleNode not working?

TiwazTiwaz Member Posts: 98
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&quot; xmlns:xsd="http://www.w3.org/2001/XMLSchema&quot; xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"&gt;
<soap12:Body>
<GetRequest xmlns="http://wa.dms.webservice/GetRequest"&gt;
<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

  • Options
    TiwazTiwaz Member Posts: 98
    P.S. I am using this logic to add namespace to XMLDocInP before the above:

    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;
  • Options
    okioki Member Posts: 46
    Please try
    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
Sign In or Register to comment.