Sponsored Content
Top Forums Programming [XQuery] How to Convert from JSON Message to XML Message with XQuery Post 302578613 by tien86 on Friday 2nd of December 2011 03:30:54 AM
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..
 

8 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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
SAXONB-XQUERY(1)														  SAXONB-XQUERY(1)

NAME
saxonb-xquery - command line XQuery processor SYNOPSIS
saxonb-xquery [OPTION...] QUERYFILE [NAME=VALUE...] DESCRIPTION
This manual page documents briefly the saxonb-xquery command. This page was written for the Debian(TM) distribution because the original program does not have a manual page. Still, it has HTML documentation which is shipped in the libsaxonb-java-doc package. saxonb-xquery is a command line wrapper around the Saxon-B XSLT and XQuery processor. Using saxonb-xquery you can evaluate XQuery queries directly from the command line. Internally, saxonb-xquery is a wrapper around the Java class net.sf.saxon.Query implemented by Saxon-B. saxonb-xquery should be invoked passing a (required) filename containing the XQuery query to be evaluated; the special filename "-" can be given to require reading the query from standard input. Before the query filename a list of options can be given, see below. Parameters At the end of the command line, a list of parameters can be given. Parameters are passed using the syntax NAME=VALUE, to specify parameters' names and values. A parameter name prefixed with "+" (plus sign) will be interpreted as a filesystem path parameter If the path points to a single file, that file will be parsed as XML and its document node will be passed as the parameter value. If the path points to a directory, all directly contained files will be parsed as XML files, and the sequence of their document nodes will be passed as the parameter value. A parameter name prefixed with "!" (exclamation mark) will be interpted as a output/serialization parameter. See the specifications of XQuery and XSLT 2.0 for more information on output/serialization parameters. To pass parameters belonging to the non-null namespace, the syntax {uri}localname=value is provided. Parameters will be visible as external variables during query evaluation, provided they have been declared in the query prolog. See the XQuery specification for more information on variables and their declarations. OPTIONS
A summary of supported options is included below. Options can be passed in any order. We first report the options which are shared by saxonb-xquery and saxonb-xslt, then those specific to saxonb-xquery (or which have a different semantics). Some options are flagged as "Saxon-SA only", such options work only if Saxon-SA is installed. Note that Saxon-SA is a commercial product, as such it is not available in Debian. Common options -cr:classname Specify a class to be used for processing collection URIs passed to the collection() function. The class must implement net.sf.saxon.CollectionURIResolver. -dtd: {[on] | [off]} Enable or disable DTD validation. Default: off. -expand: {[on] | [off]} When validation is enabled, expand default values in validated documents. This option enables or disables such an expansion. Default: on. -explain [:filename] Display an execution plan; the output is in XML format. If filename is not given it will be displayed on standard output. -ext: {[on] | [off]} Enable or disable the ability to invoke external Java functions from query files and stylesheets. Beware that enabling them is a potential security risk when processing untrusted files. Default: off. -l: {[on] | [off]} Keep (when on) or throw away (when off) line numbers in tress corresponding to source documents. When kept, line numbers can be accessed using the function saxon:line-number(). Default: off. -outval: {[recover] | [fatal]} When validation is required, set whether validation errors are fatal (when "fatal" is passed) or if they only trigger warnings (when "recover" is). Default: fatal. -p: {[on] | [off]} Enable or disable usage of the PTreeURIResolver. Saxon-SA only. -r:classname Specify a class to be used for resolving all URIs. -repeat:N Repeat the transformation N times. For benchmarking purposes. -sa Perform Schema-aware processing. Saxon-SA only. -strip: {[all] | [none] | [ignorable]} Specify whitespace stripping policy for source documents: strip all of them ("all"), strip none of them ("none"), strip ignorable whitespace only ("ignorable"). Default: none. -t Display version, timing, and other debugging information on standard error. -tree: {[tiny] | [linked]} Select the implementation of the internal tree model: tiny tree model ("tiny") or linked tree model ("linked"). See the Saxon documentation for more information on the internal tree model. Default: tiny. -T [:classname] Trace various aspect of the processing; an optional class name can be given to specify a user-chosen tracer. The class must implement net.sf.saxon.trace.TraceListener. The default is a system supplied tracer. This option implies -l. -TJ Enable tracing of external Java method invocation. See -ext. -u Force interpretation of source document names as URI. By default they are considered to be file names, unless they start with "file:" or "http:". -val: {[strict] | [lax]} When validation is enabled, choose among "strict" or "lax" validation. Saxon-SA only. -x:classname Specify a class to be used as SAX parser for input documents. The class must implement either org.xml.sax.Parser or org.xml.sax.XMLReader. -xi Apply XInclude processing to all input documents. -xmlversion: {[1.0] | [1.1]} Choose the XML version for processing input documents. "1.1" must be specified to process XML 1.1 and Namespaces 1.1 constructs. Default: 1.0. -? Display a help message and exit. Options specific to saxonb-xquery -mr:classname Use the specifed class as a ModuleURIResolver to resolve query module URIs. The class must implement net.sf.saxon.query.ModuleURIResolver. -o:filename Send the query output to the specified filename. If not specified the output will be sent to standard output. See also -wrap. -pipe: {[push] | [pull]} Internally, execute query in push or pull mode. Mainly for testing purposes. Push mode is usually faster when intermediate tree are constructed in memory. Default: push. -projection: {[on] | [off]} Enable or disable document projection, i.e. the ability to throw away tree parts which will not be accessed by a query. Saxon-SA only. -s: {[file] | [URI]} Read document input from the specified filename ("-" can be given to read from standard input). The read document will be available to the query as the context node. -u affects how filename is interpreted. -wrap: {[on] | [off]} Enable or disable wrapping of query result in a XML structure which makes explicit the kind of each output node or atomic value. For example free-standing attributes will be wrapped in an explicit XML element stating that they are attributes. When this is off, the query output will be wrapped only using a document node; in such a setting is possible that output parts, such as free-standing attributes, can't be serialized. Default: off. SEE ALSO
saxonb-xslt (1), XQuery 1.0: An XML Query Language (W3C Recommendation). This program is fully documented by the HTML documentation of Saxon, available in the libsaxon-java-doc Debian package. AUTHOR
This manual page was written by Stefano Zacchiroli <zack@debian.org> for the Debian(TM) system (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 3 or any later version published by the Free Software Foundation. On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. COPYRIGHT
Copyright (C) 2008 Stefano Zacchiroli February 2008 SAXONB-XQUERY(1)
All times are GMT -4. The time now is 07:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy