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 8062681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:45:10+00:00 2026-06-05T10:45:10+00:00

Using MarkLogic to pull in data from a web service with xdmp:http-get() or xdmp:http-post()

  • 0

Using MarkLogic to pull in data from a web service with xdmp:http-get() or xdmp:http-post(), I’d like to be able to check the headers that come back before I attempt to process the data. In DQ I can do this:

let $result := xdmp:http-get($query,$options) (: $query and $options are fine, I promise. :)
return $result

And the result I get back looks like this:

<v:results v:warning="more than one node">
       <response>
           <code>200</code>
            <message>OK</message>
            <headers>
              <server>(actual server data was here)</server>
              <date>Thu, 07 Jun 2012 16:53:24 GMT</date>
              <content-type>application/xml;charset=UTF-8</content-type>
              <content-length>2296</content-length>
              <connection>close</connection>
            </headers>
        </response>

followed by the actual response. the problem is that I can’t seem to XPath into this response node. If I change my return statement to return $result/response/code I get the empty sequence. If I could check that code to make sure I got a 200 back before attempting to process the actual data that came back it would be much better than using try-catch blocks to see if the data exists and is sane.

So, if anyone knows how to access those response codes I would love to see your solution.

For the record, I have tried xdmp:get-response-code(), but it doesn’t take any parameters, so I don’t don’t know what response code it’s looking at.

  • 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-05T10:45:13+00:00Added an answer on June 5, 2026 at 10:45 am

    You’re getting burned by two gotchas at once:

    • awareness of namespaces
    • awareness of document nodes

    First, the namespace. The XML output of the http-get function is in a namespace as seen by the top-level element:

    <response xmlns="xdmp:http-get">
    

    To successfully access elements in that namespace, you need to declare a prefix in your query bound to the correct namespace, and then use that prefix in your XPath expressions. For example:

    declare namespace h="xdmp:http-get";
    //h:code
    

    Now lets talk about document nodes. 🙂

    You’re trying to access $result as if it is a document node containing an element, but in actuality, it is a sequence of two root nodes (so they’re not siblings either). The first one (the one you’re interested in here) is a parentless <response> element—not a document containing a <response> element.

    This is a common gotcha: knowing when a document node is present or not. Document nodes are always invisible when serialized (hence the gotcha), and they’re always present on documents stored in the database. However, when you just use a bare element constructor in XQuery (as the http-get implementation does), you construct not a document node but an element node without a document node parent.

    For example, the following query will return the empty sequence, because it’s trying to get the <foo> child of <foo>:

    declare variable $foo := <foo>bar</foo>;
    $foo/foo
    

    On the other hand, the following does return <foo>, because it’s getting the <foo> child of the document node (which has to be explicitly constructed, in XQuery):

    $declare variable $doc := document{ <foo>bar</foo> };
    $doc/foo
    

    So you have to know how a given function’s API is designed (whether it returns a document containing an element or just an element).

    To solve your problem, don’t try to access $result/h:response/h:code (which is trying to get the <response> child of <response>). Instead, access $result/h:code (or more precisely $result[1]/h:code, since <response> is the first of a sequence of two nodes returned by the http-get function).

    For more information on document nodes, check out this blog article series: http://community.marklogic.com/blog/document-formats-part1

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

Sidebar

Related Questions

Using the http://www.ifans.com/forums/showthread.php?t=132024 post from another question i am allowing the user to enter
Using restlet, I want to make a post to android's c2dm service. I have
Using Java, how can I extract all the links from a given web page?
Using Android 2.1+. I have a service that gets killed from time to time
Using targetCurrent -- I am able to get the name of the MovieClip a
Using WebViewBrush I can render web page content (it's screen shot) to e.g. Rectangle
Using Jenkins or Hudson I would like to create a pipeline of builds with
Using Java,I have to fetch multiple sets of values from an XML file to
Using Yii, I want to delete all the rows that are not from today.
Using Rails 3.2.0 with haml and sass: I Would like to link an external

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.