Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8850145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:49:55+00:00 2026-06-14T12:49:55+00:00

Can anyone explain why ChildNodes.FindNode(”) ( 1 ) fails but ChildNodes[”] ( 2 )

  • 0

Can anyone explain why ChildNodes.FindNode(”) (1) fails but ChildNodes[”] (2) succeeds? ==>

Code:

const
   cNodeSOAPEnvelope  = 's:Envelope';
   cNodeSOAPBody      = 's:Body';
   cNodeSOAPBodyFault = 's:Fault';
   cNodeSOAPHeader    = 's:Header';
   cNodeFaultCode     = 'faultcode';
   cNodeFaultString   = 'faultstring';

procedure TFrmXMLParsingTests.BtnTestClick(Sender: TObject);
var
   SoapBodyNode,
   SoapBodyFaultNode,
   SoapHeaderNode,
   FaultCodeNode,
   FaultTextNode,
   RootNode: IXmlNode;
begin
   RootNode := XMLDoc.DocumentElement;
   Assert(RootNode.NodeName = cNodeSOAPEnvelope,'Root node is not SOAP envelope');
   SoapBodyNode := RootNode.ChildNodes[cNodeSOAPBody];
   SoapBodyFaultNode := SoapBodyNode.ChildNodes[cNodeSOAPBodyFault];
   if SoapBodyFaultNode <> nil then
   begin
//      FaultCodeNode := SoapBodyFaultNode.ChildNodes.FindNode(cNodeFaultCode);     (*1*)
//      FaultTextNode := SoapBodyFaultNode.ChildNodes.FindNode(cNodeFaultString);   (*1*)
      FaultCodeNode := SoapBodyFaultNode.ChildNodes[cNodeFaultCode];                (*2*) 
      FaultTextNode := SoapBodyFaultNode.ChildNodes[cNodeFaultString];              (*2*) 
      Exit; // Nothing more to do
   end; { fault in body }
   SoapHeaderNode := RootNode.ChildNodes.FindNode(cNodeSOAPHeader);
   Assert(SoapHeaderNode <> nil,'SOAP Header not found');
end;

XML:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <s:Fault>
         <faultcode xmlns:a="http://schemas.microsoft.com/exchange/services/2006/types">a:ErrorSchemaValidation</faultcode>
         <faultstring xml:lang="nl-NL">The [snip] value.</faultstring>
         <detail>
            <e:ResponseCode xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">ErrorSchemaValidation</e:ResponseCode>
            <e:Message xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">The request failed schema validation.</e:Message>
            <t:MessageXml xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
               <t:LineNumber>10</t:LineNumber>
               <t:LinePosition>30</t:LinePosition>
               <t:Violation>The [snip] value.</t:Violation>
            </t:MessageXml>
         </detail>
      </s:Fault>
   </s:Body>
</s:Envelope>

Thanks
Jan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:49:57+00:00Added an answer on June 14, 2026 at 12:49 pm

    Read the documentation. When you access the ChildNodes[] property asking for a non-existant node, a new node will automatically be created if the doNodeAutoCreate flag is enabled in the parent XMLDocument’s Options property, otherwise an EXMLDocError exception will be raised instead.

    Update: since your document contains multiple XML namespaces in it, you need to take the namespaces into account when using the ChildNodes[] property and the FindNode() method. The reason your code is not finding the <faultcode> and <faultstring> nodes correctly is because they have a different namespace (actually, they don’t have any namespace at all) than the <Fault> tag has, but the ChildNodes[] property and the 1-parameter FindNode() method expects them to have the same namespace as their parent node. When you search a namespaced node for a child node that has a different namespace, you have to include the child’s namespace in the search in order to find the child node correctly.

    Try this:

    uses
      ..., XmlIntf, XMLDom, XmlDoc;
    
    const
      cSoapEnvelopeNS    = 'http://schemas.xmlsoap.org/soap/envelope/';
      cExchangeErrorsNS  = 'http://schemas.microsoft.com/exchange/services/2006/errors';
      cExchangeTypesNS   = 'http://schemas.microsoft.com/exchange/services/2006/types';
    
      cNodeSOAPEnvelope  = 'Envelope';
      cNodeSOAPBody      = 'Body';
      cNodeSOAPBodyFault = 'Fault';
      cNodeSOAPHeader    = 'Header';
      cNodeFaultCode     = 'faultcode';
      cNodeFaultString   = 'faultstring';
      cNodeDetail        = 'detail';
      cNodeResponseCode  = 'ResponseCode';
      cNodeMessage       = 'Message';
      cNodeMessageXml    = 'MessageXml';
      cNodeLineNumber    = 'LineNumber';
      cNodeLinePosition  = 'LinePosition';
      cNodeViolation     = 'Violation';
    
    procedure TFrmXMLParsingTests.BtnTestClick(Sender: TObject);
    var
       RootNode,
       SoapBodyNode,
       SoapBodyFaultNode,
       SoapHeaderNode,
       FaultCodeNode,
       FaultTextNode,
       DetailNode,
       ResponseCodeNode,
       MessageNode,
       MessageXmlNode,
       LineNumberNode,
       LinePositionNode,
       ViolationNode: IXMLNode;
    begin
       RootNode := XMLDoc.DocumentElement;
       Assert(NodeMatches(RootNode.DOMNode, cNodeSOAPEnvelope, cSoapEnvelopeNS), 'Root node is not SOAP envelope');
    
       // these have the same namespace as <Envelope>
       SoapBodyNode := RootNode.ChildNodes[cNodeSOAPBody];
       SoapBodyFaultNode := SoapBodyNode.ChildNodes.FindNode(cNodeSOAPBodyFault);
    
       if SoapBodyFaultNode <> nil then
       begin
          // these have a different namespace than <Fault>!
          FaultCodeNode := SoapBodyFaultNode.ChildNodes.FindNode(cNodeFaultCode, '');
          FaultTextNode := SoapBodyFaultNode.ChildNodes.FindNode(cNodeFaultString, '');
          DetailNode := SoapBodyFaultNode.ChildNodes.FindNode(cNodeDetail, '');
    
          if DetailNode <> nil then
          begin
            // these have different namespaces than <detail>!
            ResponseCodeNode := DetailNode.ChildNodes.FindNode(cNodeResponseCode, cExchangeErrorsNS);
            MessageNode := DetailNode.ChildNodes.FindNode(cNodeMessage, cExchangeErrorsNS);
            MessageXmlNode := DetailNode.ChildNodes.FindNode(cNodeMessageXml, cExchangeTypesNS);
    
            if MessageXmlNode <> nil then
            begin
              // these have the same namespace as <MessageXml>
              LineNumberNode := MessageXmlNode.ChildNodes.FindNode(cNodeLineNumber);
              LinePositionNode := MessageXmlNode.ChildNodes.FindNode(cNodeLinePosition);
              ViolationNode := MessageXmlNode.ChildNodes.FindNode(cNodeViolation);
            end;
          end;
          Exit;
       end;
    
       // this has the same namespace as <Envelope>
       SoapHeaderNode := RootNode.ChildNodes.FindNode(cNodeSOAPHeader);
       Assert(SoapHeaderNode <> nil,'SOAP Header not found');
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone explain to me why, in VBA code for a button on a
Can anyone explain this code to me? Whats the meaning and how to use
Can anyone explain why this code: {% form_theme form _self %} {% block avo_gallery_upload_widget
Can anyone explain why the alert() in the following JavaScript code is firing? It
Can anyone explain me what is a difference between these lines of code char
Can anyone explain why I get the following errors when compiling the code shown
Can anyone explain why mysql_close() fails when called from a class destructor? mysql_error() reports
Can anyone explain this code to me var ParentClass = function(){ } var ChildClass
Can anyone explain the meaning of this code? if (data.result) { $('ul#intlist').append(data.content); }
Can anyone explain to me why this code below does not work? #include opencv/cv.h

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.