[XQuery] How to Convert from JSON Message to XML Message with XQuery


 
Thread Tools Search this Thread
Top Forums Programming [XQuery] How to Convert from JSON Message to XML Message with XQuery
# 1  
Old 12-02-2011
[XQuery] How to Convert from JSON Message to XML Message with XQuery

Hi guys,

I'm in a job of converting a restful webservice to soap. Tool for convertation uses XQuery.

Now i need to convert a message like this:
{
"firstName": "John",
"midName": null,
"lastName": "Smith",
"married": false,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": 10021
},
"phoneNumbers": [ "212 555-1234", "646 555-4567" ]
}
is equivalent to the following XML representation:

<pair name="firstName" type="string">John</pair>
<pair name="midName" type="null"/>
<pair name="lastName" type="string">Smith</pair>
<pair name="married" type="boolean">false</pair>
<pair name="address" type="object">
<pair name="streetAddress" type="string">21 2nd Street</pair>
<pair name="city" type="string">New York</pair>
<pair name="state" type="string">NY</pair>
<pair name="postalCode" type="number">10021</pair>
</pair>
<pair name="phoneNumbers" type="array">
<item type="string">212 555-1234</item>
<item type="string">646 555-4567</item>
</pair>



I guest this a general case so there must be an example for this somewhere on the internet but i haven't found it yet. So i put on forum and hope someone already knows this.

Thank for u help.

Regards,
Tien86.

Last edited by tien86; 12-02-2011 at 05:01 AM..
# 2  
Old 12-02-2011
Re: [XQuery] How to Convert from JSON Message to XML Message with XQuery

You can use an example distributed with Sausalito (28msec.com). Install the coresdk and execute:

Code:
sausalito create template -n json

then you can see and play with some json conversions in json/handlers/doublesearch.xq (online:28msec.com/source/show/json/handlers/doublesearch.xq) and json/lib/controller/search.xq (online:28msec.com/source/show/json/lib/controller/search.xq).

In particular, what you need is the parse function from this module 28msec.com/api/reference/datatypes/json#parse-1

Sorry, for posting that many links, but I hope it helps.
# 3  
Old 12-05-2011
hi, but my environment is OSB, it looks like it just offer only xquery to parse the message, i don't know whether i can reference to another source Smilie
# 4  
Old 12-06-2011
Mmmh...

Is the restful webservice you are trying to integrate on the web?

Then you could use sausalito to do the transformation job as you can deploy it in the cloud. You could then access the SOAP wrapped app in the cloud like any other service on the web.

there is a user group where you could post that question if this might be a solution: groups.google.com/group/sausalito-users

hope that helps. I am not familiar with OSB, so, I am sorry if this doesn't help...
# 5  
Old 12-06-2011
well i will do it in easier way for my hurry job...

Now, in above example, i can make a loop to get the value column.

John
null
Smith
false
21 2nd Street
....
//in here $string is the restful input message

for $c in fn:tokenize($string, ",") where fn:string-length($c) != 0
let $cut := fn:tokenize($c, ":")[last()]
let $value := fn:replace($cut,"\{|\}","")
let $seq1 := fn:insert-before($seq1,1,$value)
return <param value="{ $value }" />

====================================

So what i want to do now is : create a $seq with value is ("John", "null", "Smith" .... ) . This code is not work. Would you please take a look at my code?

Tien86
# 6  
Old 12-12-2011
hi all thank you for watching, OSB provide a method using java callout. So i have solved this problem by java insted of using XQuery
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert json to xml

Hello everyone, I have created a workflow that will pull down data via a RESTful API in JSON, then my code parses and modifies said data. The problem I have is that these APIs I am working with only accept XML to PUT/POST data, and I am looking for an easy way to convert my JSON file to XML. ... (2 Replies)
Discussion started by: Zaphod_B
2 Replies

2. Programming

[Xquery] How to do a increment in a For loop

Hello men. How can i build a simple increment for $a by Xquery such as ? let $a := 0 for $i in (1 to 10) let $a := $a + 1 return $a why a in this loop always is '1' Thank you for reading, its will really helpful for my job if i can solve this problem :D:D (3 Replies)
Discussion started by: tien86
3 Replies

3. Shell Programming and Scripting

Extract XML message from a log file using awk

Dear all I have a log file and the content like this file name: temp.log <?xml version="1.0" encoding="cp850"?> <!DOCTYPE aaabbb SYSTEM '/dtdpath'> <aaabbb> <tranDtl> <msgId>000001</msgId> </tranDtl> ..... </aaabbb> ... ... (1 Reply)
Discussion started by: on9west
1 Replies

4. Programming

Validate queries XQUERY

Hi! I am working in an application jsp-java-xml , and i need to validate queries in xquery. For example If I put (in a text field) "for $x in XXX/yyy return data($x/tittle)" I need a bean(class) that show if the text is correct or not. And, if were posible, show the syntax error too. ... (2 Replies)
Discussion started by: avatarrr
2 Replies

5. UNIX for Dummies Questions & Answers

Unable to extract a tag from a very long XML message

Hi I have a log file which contain XML message. I want to extract the value between the tag : <businessEventId>13201330</businessEventId> i.e., 13201330. I tried the following commands but as the message is very long, unable to do it. Attached is the log file. Please provide inputs. --... (3 Replies)
Discussion started by: Sapna_Sai
3 Replies

6. Shell Programming and Scripting

Move xml files from unix to message queue.

Hi, I need to move the XML files from the UNIX to the message queue. Please help me out to write the code.. Thanks, Mohana Krishnan (0 Replies)
Discussion started by: krishnan_6015@y
0 Replies

7. Shell Programming and Scripting

Need to extract XML message from log

I need help to extract a following SOAP-ENV:Header XML message from the log. XML message need to be extracted: *************************** <SOAP-ENV:Header> <ServiceGatewayHeader> <SourceApplicationId>OXL</SourceApplicationId> <Version>1.0</Version> <UserId>TEST</UserId>... (4 Replies)
Discussion started by: tjshankar
4 Replies

8. Programming

How to limit max no of message in a posix message queue

Hii can anyone pls tell how to limit the max no of message in a posix message queue. I have made changes in proc/sys/fs/mqueue/msg_max But still whenever i try to read the value of max. message in the queue using attr.mq_curmsgs (where struct mq_attr attr) its giving the default value as 10.... (0 Replies)
Discussion started by: mohit3884
0 Replies
Login or Register to Ask a Question