How to convert HDS to other types e.g. JSON, XML

Poster Content
nk4um Moderator
Posts: 898
October 31, 2011 17:01

Yep - that's one of the important properties of HDS - you can seamlessly pass it to anything that's expecting XML. So you can use the result from the DB query straight into an XSLT etc.

Like · Post Reply
nk4um User
Posts: 28
October 31, 2011 16:53

Any chance you can give an HDS to XML

Like · Post Reply
nk4um Moderator
Posts: 898
October 30, 2011 18:35

You beat me to it. But it was worth while looking into this since it looks like by coincidence there's a missing doc in json:core module for that accessor. Glad you worked it out - we'll post an update of the module to the repos with the correct doc for active:JSONFromHDS.

Like · Post Reply
nk4um User
Posts: 28
October 30, 2011 18:26Light Dawns

//from prev request
hds = context.issueRequest(request)
//convert to JSON
request = context.createRequest("active:JSONFromHDS")
request.addArgumentByValue("operand", hds)
def jsonArray = context.issueRequest(request)
context.createResponseFrom(jsonArray.toString())
Like · Post Reply
nk4um User
Posts: 28
October 30, 2011 17:50How to convert HDS to other types e.g. JSON, XML

I am looking at the JSON core book (/book/view/book:json:core/) and would like to know how you use things like active:JSONFromHDS.

Currently i am doing the following rather clunky code:

//hds is a sql result
hds = context.issueRequest(request)

//process db request and turn it into json array
def nodes = hds.getNodes("/resultset/row/*")
def jsonArray = new JSONArray()

def it = nodes.iterator()
def jo  = new JSONObject()
while(it.hasNext()){
  def node = it.next()
  jo.put(node.getName(),node.getValue())
    
}
 jsonArray.put(jo)

Would be much nicer to be able to do that in one line. Thanks

Like · Post Reply