1

I'm using the MarkLogic 7 REST API to build an AngularJS application on top of an XML document database. My documents are in NEWSML-G2 format. I've configured custom query options to return only the title and the creation date for each document that matches the search string. The problem is this.

I have a title element in my XML.

<nitf version="-//IPTC//DTD NITF 3.6//EN" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:newzmeta="http://newz.nl/metadata/" xmlns="http://iptc.org/std/NITF/2006-10-18/">
<head>
<title newz:origin="Generated" xmlns:newz="http://newz.nl/">Test Article</title>
....
</nitf>

In my custom query options, I've used the following line.

<extract-metadata>
  <qname elem-ns="http://iptc.org/std/NITF/2006-10-18/" elem-name="title"/>
  ....
</extract-metadata>

Now, the problem is that when I hit the REST interface to make a query and ask for results in JSON format, I get the following in the response

"metadata":[{"{http://iptc.org/std/NITF/2006-10-18/}title":"Obama assumes the office of the President of the United States","metadata-type":"element"},{"  {http://iptc.org/std/nar/2006-10-01/}firstCreated":"2009-01-20T05:00:09","metadata-type":"element"}]

How do I retrieve the title value on the UI side? I get a syntax error if I ask for

 result.metadata.{http://iptc.org/std/NITF/2006-10-18/}title

Is there a way specifically to access this value, or to somehow change the name of the element that's returned from the MarkLogic side?

2 Answers 2

4

You can do this:

result.metadata.['{http://iptc.org/std/NITF/2006-10-18/}title']

The bracket notation is used to access properties whose names are not valid JavaScript identifiers, preventing you from using the dot notation.

Sign up to request clarification or add additional context in comments.

Comments

1

For completeness, an alternative approach would be to write and install a transform for the search response that generates either metadata elements in the empty namespace or a JSON representation that's tuned to your requirements.

But, the simplest way is just to use the bracket notation as Dave suggests.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.