Author |
Message
|
venkat_chekka |
Posted: Wed Aug 12, 2015 9:07 am Post subject: Get Data type 'FIELDTYPE' in Runtime using ESQL |
|
|
Apprentice
Joined: 14 Apr 2006 Posts: 37
|
Hi,
I need to check field value type in run time using ESQL function.
My service input is XML message and using XSD message definition file also to validate incoming message.
Some part in my XSD:
<xs:element name="title" type="xs:string"/>
<xs:element name="note" type="xs:string" minOccurs="0"/>
<xs:element name="quantity" type="xs:positiveInteger"/>
<xs:element name="price" type="xs:decimal"/>
I want to get above XML element type in broker run time using ESQL. That means need to get these values : String, Integer, Decimal, Boolean etc..
I have seen ESQL function called 'FILEDTYPE' but it is returning some integer value like this '50331648' not data type.
Can we achieve my requirement using ESQL coding?
Thanks in Advance,
Venkat |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Aug 12, 2015 9:11 am Post subject: Re: Get Data type 'FIELDTYPE' in Runtime using ESQL |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
venkat_chekka wrote: |
That means need to get these values : String, Integer, Decimal, Boolean etc.. |
Why? |
|
Back to top |
|
 |
Vitor |
Posted: Wed Aug 12, 2015 9:56 am Post subject: Re: Get Data type 'FIELDTYPE' in Runtime using ESQL |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
venkat_chekka wrote: |
My service input is XML message and using XSD message definition file also to validate incoming message. |
This is a very reasonable thing to do.
venkat_chekka wrote: |
I want to get above XML element type in broker run time using ESQL. That means need to get these values : String, Integer, Decimal, Boolean etc.. |
This is not. Why are you doing this in ESQL?
venkat_chekka wrote: |
I have seen ESQL function called 'FILEDTYPE' but it is returning some integer value like this '50331648' not data type. |
2 points: it's not returning "some integer value", it's returning a very specific integer value indicating the field type. Secondly, as indicated here, the "field type" is that - the type of the field, not the data type.
venkat_chekka wrote: |
Can we achieve my requirement using ESQL coding? |
No, and I'd be interested to hear a valid use case when you'd need to do so rather than the more convention means of validating XML against an XSD. I'd especially like to hear how you'd extend the validation from data types to include the minOccurs clause in your example. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
venkat_chekka |
Posted: Wed Aug 12, 2015 10:11 am Post subject: |
|
|
Apprentice
Joined: 14 Apr 2006 Posts: 37
|
My requirement is XML to JSON transformation.
I am uisng this statement to send entire XML message into JSON message.
SET OutputRoot.JSON.DATA=InputRoot.XMLNSC;
Using above statement, all the values are going as String values in JSON message.
So I need to change value type in JSON message for other than String data types.
I want to identify the incoming message element data type. |
|
Back to top |
|
 |
Vitor |
Posted: Wed Aug 12, 2015 10:23 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
venkat_chekka wrote: |
I am uisng this statement to send entire XML message into JSON message.
SET OutputRoot.JSON.DATA=InputRoot.XMLNSC; |
Why?
I would also point out that your original post talked about validating the inbound XML. Badly phrased question, badly phrased advice.
venkat_chekka wrote: |
Using above statement, all the values are going as String values in JSON message. |
Yes, because that's what you've coded.
venkat_chekka wrote: |
So I need to change value type in JSON message for other than String data types. |
So (and pardon my dubious JSON ) you're getting:
Code: |
{name: "Trump", networth : "100000000000", sane : "false"} |
and you want:
Code: |
{name: "Trump", networth : 100000000000, sane : false} |
but you don't want to code for that. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
akil |
Posted: Wed Aug 12, 2015 10:36 am Post subject: |
|
|
 Partisan
Joined: 27 May 2014 Posts: 338 Location: Mumbai
|
Did you enable 'Build tree using XML schema data types' when you parse the message. ?
If you don't enable that , the message tree has all strings , and then the Json will also be only strings,
If you enable it, the tree has correct data types, and so will the Json. _________________ Regards |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Aug 12, 2015 10:51 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
akil wrote: |
Did you enable 'Build tree using XML schema data types' when you parse the message. ?
If you don't enable that , the message tree has all strings , and then the Json will also be only strings,
If you enable it, the tree has correct data types, and so will the Json. |
 |
|
Back to top |
|
 |
Vitor |
Posted: Wed Aug 12, 2015 11:09 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
akil wrote: |
Did you enable 'Build tree using XML schema data types' when you parse the message. ?
If you don't enable that , the message tree has all strings , and then the Json will also be only strings,
If you enable it, the tree has correct data types, and so will the Json. |
Ooo..... Good catch!
I'd gone for the more technical "start from the root and it serializes as a string" but that's another highly plausible problem. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
venkat_chekka |
Posted: Wed Aug 12, 2015 11:48 am Post subject: |
|
|
Apprentice
Joined: 14 Apr 2006 Posts: 37
|
This option is working fine "'Build tree using XML schema data types' when you parse the message. "
But still we have issues.
JSON Data types: String, number, Boolean, null.
1) Cannot define null field in XML message. If there is no value at xml field like "<a></a>". This one going as String data type instead of Null type.
Going as ' "a": "" '
2) Need to convert manually JSON Array types. |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Aug 12, 2015 12:01 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
venkat_chekka wrote: |
This option is working fine "'Build tree using XML schema data types' when you parse the message. "
But still we have issues.
JSON Data types: String, number, Boolean, null.
1) Cannot define null field in XML message. If there is no value at xml field like "<a></a>". This one going as String data type instead of Null type.
Going as ' "a": "" '
2) Need to convert manually JSON Array types. |
Your null value in XML is typically defined as
Code: |
<alpha xsi:nil="true"/> |
 _________________ MQ & Broker admin |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Aug 12, 2015 12:32 pm Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
To comment on F.J.'s response. XML has values that are null, values that are empty, and values that are missing.
<a xsi:nil=true/> is a null value
<a></a> or <a/> is an empty value
Not having any <a> tags at all is a missing value.
The XMLNSC parser handles these in the correct way according to the XML parsing standards. It assigns an empty value to an empty tag. So <a></a> produces "". |
|
Back to top |
|
 |
venkat_chekka |
Posted: Thu Aug 13, 2015 5:12 am Post subject: |
|
|
Apprentice
Joined: 14 Apr 2006 Posts: 37
|
Yes, Its not going as Null JSON type value for Blank/Null XML field values.
Here I have one more question. Below option is working if enable validation ' content and value/ at MQ Input node level.
"Build tree using XML schema data types"
As per my requirement, I am reading message as BLOB and doing transformation and parsing later in Compute node.
How can I use above feature in Compute node using ESQL instead of at MQInput node? |
|
Back to top |
|
 |
Vitor |
Posted: Thu Aug 13, 2015 5:21 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
venkat_chekka wrote: |
As per my requirement, I am reading message as BLOB and doing transformation and parsing later in Compute node. |
What requirement? What is causing you to take this line?
How are you parsing through ESQL and (again) why this rather than the other faster and more efficient means available? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Aug 13, 2015 5:50 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You should be able to tell the CREATE FIELD that you use to do your parsing that it should also Build the Tree Using XML Schema Data Types. |
|
Back to top |
|
 |
akil |
Posted: Thu Aug 13, 2015 7:31 am Post subject: |
|
|
 Partisan
Joined: 27 May 2014 Posts: 338 Location: Mumbai
|
There is really no way for the parser to 'guess' which elements are to be arrays. You can expect the following behavior
1. in case of a repeated element in the XMLNSC tree, a JSON array will be created
2. in case of a single element in the XMLNSC tree (but with the schema specifying maxOccurs > 0), you'll see a simple JSON element.
This is one reason why , the XML2JSON.java that is generated by the broker, requires an explicit indication of which fields are arrays ..
We use the convention of specifying arrays to have names ending with either 'Array' or 'List' , example CustomersList, CustomersArray ..
You'll get other surprises for floats / ints too .. so this really needs to be hand-wired with some conventions .. _________________ Regards |
|
Back to top |
|
 |
|