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

  • SEARCH
  • Home
  • 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 9284869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:00:23+00:00 2026-06-18T19:00:23+00:00

Given the following document, I want to extract tns:EchoResponse . (Original document prettified for

  • 0

Given the following document, I want to extract tns:EchoResponse. (Original document prettified for readability.)

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <tns:EchoResponse 
          xmlns:tns="http://www.apis-it.hr/fin/2012/types/f73" 
          xsi:schemaLocation="http://www.apis-it.hr/fin/2012/types/f73 FiskalizacijaSchema.xsd "
          >
            hello
         </tns:EchoResponse>
    </soap:Body>
</soap:Envelope>

I’ve parsed the document, I’ve created an XPath context, I’ve registered the namespaces soap and tns, and then I’ve run the query using the following XPath expression.

//soap:Envelope[1]/soap:Body[1]/tns:EchoResponse[1]

Unfortunately, only lookup that ignores namespaces and uses only the local name seems to work:

//*[local-name(.) = 'Envelope']/*[local-name(.) = 'Body'][1]/*[local-name(.) = 'EchoResponse'][1]

So… what did I do wrong? What did I assume incorrectly? Here’s the snippet of the code that deals with this document.

    xmlDocPtr xmldoc = xmlReadMemory(databuffer, datasize, ISFEndpointURL(), NULL, 0);
    if(!xmldoc)
    {
        err = -1;
        goto finalize;
    }

    xmlXPathContextPtr xpathCtx = xmlXPathNewContext(xmldoc);
    if(!xpathCtx)
    {
        err = -1;
        xmlFreeDoc(xmldoc);
        goto finalize;
    }

    xmlXPathRegisterNs(xpathCtx, BAD_CAST "soap", BAD_CAST "http://schemas.xmlsoap.org/soap/envelope");
    xmlXPathRegisterNs(xpathCtx, BAD_CAST "tns", BAD_CAST "http://www.apis-it.hr/fin/2012/types/f73");

    // //soap:Envelope[1]/soap:Body[1]/*[local-name(.) = 'EchoResponse']
    xmlXPathObjectPtr xpathObj = xmlXPathEvalExpression(BAD_CAST "./*[local-name(.) = 'Envelope']/*[local-name(.) = 'Body'][1]/*[local-name(.) = 'EchoResponse'][1]", xpathCtx);
    if(!xpathObj)
    {
        err = -1;
        xmlXPathFreeContext(xpathCtx);
        xmlFreeDoc(xmldoc);
        goto finalize;
    }
    if(xmlXPathNodeSetIsEmpty(xpathObj->nodesetval)){
        err = -1;
        xmlXPathFreeObject(xpathObj);
        xmlXPathFreeContext(xpathCtx);
        xmlFreeDoc(xmldoc);
        printf("%s: No XPath result\n", __FUNCTION__);
        goto finalize;
    }


    if(strcmp((char *)xmlXPathCastNodeSetToString(xpathObj->nodesetval), echoText))
    {
        err = 1;
        xmlXPathFreeObject(xpathObj);
        xmlXPathFreeContext(xpathCtx);
        xmlFreeDoc(xmldoc);
        printf("%s: Incorrect echo result: %s\n", __FUNCTION__, xpathObj->stringval);
        goto finalize;
    }

    xmlXPathFreeObject(xpathObj);
    xmlXPathFreeContext(xpathCtx);
  • 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-18T19:00:25+00:00Added an answer on June 18, 2026 at 7:00 pm

    The soap prefix in the XML document is bound to the namespace URI

    http://schemas.xmlsoap.org/soap/envelope/
    

    whereas your code binds the soap prefix in the XPath context to a different URI

    http://schemas.xmlsoap.org/soap/envelope
    

    The XPath doesn’t match anything because it is looking for the wrong namespace.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following XML: <?xml version=1.0 encoding=UTF-8 ?> <?xml-stylesheet type=text/xsl href=form.xsl?> <Document> <Translations> <Translation
Given the following XML file: <?xml version=1.0 encoding=UTF-8?> <process name=TestSVG2 xmlns=http://www.example.org targetNamespace=http://www.example.org xmlns:xsd=http://www.w3.org/2001/XMLSchema> <sequence>
Given this XML in data.xml <?xml version=1.0 encoding=utf-8?> <data> <bar>100</bar> </data> I want to
Given the following XML (basic.xml): <rdr> <details> <detail> <name>version</name> <value>15.0</value> </detail> <detail> <name>resolution</name> <value>1080X1920</value>
Given the following partial XML document: <section> <entry typeCode=DRIV> <act classCode=AT moodCode=DEF> <statusCode code=completed/>
Given the following XML: <Contact> <ContactID>41111-f15a-4fa1-b643-47877608f557</ContactID> <ContactStatus>ACTIVE</ContactStatus> <Name>ABC Ltd</Name> <EmailAddress>xxx@xxx.co</EmailAddress> <SkypeUserName>xxxdemo</SkypeUserName> <Addresses> <Address> <AddressType>STREET</AddressType>
I'm looking for a good approach to do the following : Given a document
Given the following xml file with the knowledge that the structure and contents can
Given a document {'foo', 'bar', 'baz'}, I want to match using SpanNearQuery with the
Given the following document: {classes:3, people : [ {name:John, age:20, city:London} {name:Alice, age:56, city:Dublin}

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.