|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
validating XMLNSC subtree in ESQL |
« View previous topic :: View next topic » |
Author |
Message
|
omikron |
Posted: Tue Mar 19, 2013 5:56 am Post subject: validating XMLNSC subtree in ESQL |
|
|
Newbie
Joined: 18 Mar 2013 Posts: 3
|
Hello,
I'm coding in WMB version 7.0.0.4 and I'm having some trouble validating a XMLNSC subtree against a message set in an esql function. I am trying to avoid using the Validate node, because I need to validate multiple subtrees (result of an aggregation) as if they were individual messages and constructing and propagating each message separately into a Validate node would not be as efficient.
The infocenter has a topic on validation which says:
Quote: |
Alternatively, use a Validate node to validate a message tree at a particular place in your message flow, or use the ESQL ASBITSTREAM function in a Compute, Filter, or Database node. |
There's an example in ASBITSTREAM function docs:
Code: |
DECLARE options INTEGER BITOR(FolderBitStream, ValidateContent,
ValidateValue);
SET result = ASBITSTREAM(cursor OPTIONS options CCSID 1208);
SET Result = ASBITSTREAM(Environment.Variables.MQRFH2.Data,,1208
,,,,options); |
In my case I would like an exception thrown if the subtree is not valid. This is what I tried:
Code: |
DECLARE options INTEGER BITOR(FolderBitStream, ValidateValue, ValidateContent, ValidateException);
DECLARE tmp BLOB ASBITSTREAM(msgref OPTIONS options CCSID 1208 SET 'My_MessageSet'); |
Looks just like the example, but it doesn't work. No exception is thrown even if the bitstream is definitely not valid.
I don't even get any error if I specify a nonexistent message set to validate against:
Code: |
DECLARE options INTEGER BITOR(FolderBitStream, ValidateValue, ValidateContent, ValidateException);
DECLARE tmp5 BLOB ASBITSTREAM(msgref OPTIONS options CCSID 1208 SET 'xxx'); |
It deploys and runs, no errors, but apparently doesn't even try to validate anything despite the options.
I tried passing all kinds of other options I found in the infocenter and on the forums:
Code: |
DECLARE options INTEGER BITOR(FolderBitStream, ValidateContentAndValue, ValidateException);
DECLARE options2 INTEGER BITOR(FolderBitStream, ValidateValue, ValidateContent, ValidateException, ValidateComplete, ValidateFullConstraints);
DECLARE tmp BLOB ASBITSTREAM(msgref,,1208,'My_MessageSet',,,options);
DECLARE tmp7 BLOB ASBITSTREAM(msgref,,1208,,,,options);
DECLARE tmp3 BLOB ASBITSTREAM(msgref OPTIONS options CCSID 1208 SET 'My_MessageSet');
DECLARE tmp4 BLOB ASBITSTREAM(msgref OPTIONS options2 CCSID 1208 SET 'My_MessageSet');
DECLARE tmp5 BLOB ASBITSTREAM(msgref OPTIONS options CCSID 1208 SET 'xxx');
DECLARE tmp6 BLOB ASBITSTREAM(msgref OPTIONS options2 CCSID 1208 SET 'yyy');
DECLARE tmp8 BLOB ASBITSTREAM(msgref,,1208,,,,BITOR(FolderBitStream, ValidateContentAndValue, ValidateException));
DECLARE tmp9 BLOB ASBITSTREAM(msgref OPTIONS BITOR(FolderBitStream, ValidateContentAndValue, ValidateException) CCSID 1208); |
All of these create an invalid bitstream silently.
What am I missing? |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Mar 19, 2013 6:04 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Excellent first post!
The XMLNSC parser associates the message model by matching the root tag of the document against a structure in the xsd.
If that structure is not at least a global element (and possibly an element that is marked as a "message" rather than just a global element) then it may merely be validating it as well-formed, rather than as matching the schema.
I haven't looked at the nitty-gritty details here in a while, but I suspect you do require the ValidateFullConstraints option to make sure that schema types are used.
You may also have better luck getting an exception thrown trying to PARSE the bitstream after you've serialized it, rather than merely serializing it. But again, it's been a while since I've looked at the nitty gritty details. |
|
Back to top |
|
 |
omikron |
Posted: Tue Mar 19, 2013 6:42 am Post subject: |
|
|
Newbie
Joined: 18 Mar 2013 Posts: 3
|
Thanks!
mqjeff wrote: |
The XMLNSC parser associates the message model by matching the root tag of the document against a structure in the xsd.
If that structure is not at least a global element (and possibly an element that is marked as a "message" rather than just a global element) then it may merely be validating it as well-formed, rather than as matching the schema. |
The structures I'm trying to validate are marked as messages in the message set. But it seems to me that the broker doesn't even look at the message set, since no error is issued if I specify nonexistent message set to validate against (in the ASBITSTREAM call).
mqjeff wrote: |
You may also have better luck getting an exception thrown trying to PARSE the bitstream after you've serialized it, rather than merely serializing it. But again, it's been a while since I've looked at the nitty gritty details. |
I tried this and it works! Doing CREATE .. PARSE on the bitstream does finally validate and throws the expected exception. This also notices if the specified message set doesn't exist and throws an exception as I would expect.
Working code:
Code: |
DECLARE options INTEGER BITOR(FolderBitStream, ValidateContentAndValue, ValidateException);
-- this doesn't actually validate:
DECLARE tmp BLOB ASBITSTREAM(msgref OPTIONS options CCSID 1208 SET 'My_MessageSet');
DECLARE tmprow ROW;
-- this validates:
CREATE LASTCHILD OF tmprow DOMAIN('XMLNSC')
PARSE(tmp, InputProperties.Encoding, InputProperties.CodedCharSetId, 'My_MessageSet',,,options); |
I'm not very happy about having to serialize and parse the subtree again just to validate it though. I wonder if it would still be more efficient than propagating the subtree into a Validate node, which is what I'm doing now. I guess I will modify the flow to work with BLOBs at the start and parse+validate manually as needed.
In any case, the docs are very confusing here -- they explicitly say "use ASBITSTREAM to validate", which clearly doesn't work and the example on ASBITSTREAM page is misleading.
Anyway, thank you for your help  |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Mar 19, 2013 6:46 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Again, it sounds like the ASBITSTREAM doesn't know that the right message definition is associated with the logical tree and it's only validating it for wellformedness.
This may in fact be because of FolderBitstream. You might have better luck getting full validation if you use RootBitStream and either temporarily assign the submessage to OutputRoot.XMLNSC or create an XMLNSc parser in Environment or LocalEnvironment and make sure the sub message is the whole tree under the parser. |
|
Back to top |
|
 |
omikron |
Posted: Tue Mar 19, 2013 7:16 am Post subject: |
|
|
Newbie
Joined: 18 Mar 2013 Posts: 3
|
Oh I see what you mean now. I got it to work with ASBITSTREAM with your suggestion:
Code: |
DECLARE tmprow ROW;
CREATE LASTCHILD OF tmprow DOMAIN 'XMLNSC';
CREATE LASTCHILD OF tmprow.XMLNSC FROM msgref;
DECLARE options INTEGER BITOR(RootBitStream, ValidateContentAndValue, ValidateException);
-- validates as expected:
DECLARE tmp BLOB ASBITSTREAM(tmprow.XMLNSC OPTIONS options CCSID 1208 SET 'My_MessageSet'); |
Thanks again  |
|
Back to top |
|
 |
Raki verem |
Posted: Thu Jul 24, 2014 6:59 am Post subject: How to validate the same against a Message Model |
|
|
Newbie
Joined: 23 Jul 2014 Posts: 2
|
Hi
Can we validate the the xml against the message model without message set
If yes please post the sample
Thanks |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Jul 24, 2014 7:36 am Post subject: Re: How to validate the same against a Message Model |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Raki verem wrote: |
Hi
Can we validate the the xml against the message model without message set
If yes please post the sample
Thanks |
You can't validate XML without an XML schema.
You can't validate XML in Broker without importing that XML schema into a deployable container.
Some levels of Broker call that deployable container a "message set".
Newer versions don't call it that.
So, yes, you can validate XML against a message model without creating a message set.
But you can't validate against a message model without creating a message model! |
|
Back to top |
|
 |
Raki verem |
Posted: Thu Jul 24, 2014 3:27 pm Post subject: Re: How to validate the same against a Message Model |
|
|
Newbie
Joined: 23 Jul 2014 Posts: 2
|
mqjeff wrote: |
Raki verem wrote: |
Hi
Can we validate the the xml against the message model without message set
If yes please post the sample
Thanks |
You can't validate XML without an XML schema.
You can't validate XML in Broker without importing that XML schema into a deployable container.
Some levels of Broker call that deployable container a "message set".
Newer versions don't call it that.
So, yes, you can validate XML against a message model without creating a message set.
But you can't validate against a message model without creating a message model! |
Agreed! I created a message model but not sure about the syntax to validate against the message model, can you help me with a sample code?? Thanks. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|