Author |
Message
|
fabyos |
Posted: Fri May 29, 2009 2:38 pm Post subject: CREATE ... PARSE XML Validation |
|
|
Apprentice
Joined: 15 May 2009 Posts: 37
|
Hi,
I'm started using WMB 6.1 4 weeks ago and I´m still new with ESQL.
I´ve a procedure that returns a CHAR result as a XML data. This result has a message set definition and I need to parse this data in order to validate the output.
So, until now, Im doing this, but no exception is thrown.
Code: |
DECLARE xml CHAR;
CALL MyProcedure(..., xml);
DECLARE xmlAsBlob BLOB CAST(xml AS BLOB CCSID 1208);
CREATE LASTCHILD OF OutputRoot DOMAIN('MRM') PARSE(
xmlAsBlob
OPTIONS parseOptions
ENCODING InputRoot.Properties.Encoding
CCSID 1208 -- 1208=UTF-8, 819=ISO-8859-1
SET 'PH4HRKS002001'
TYPE 'CADPES_OUTPUT'
FORMAT 'XML1');
|
and the MRM fails and have this message:
CHARACTER:ImbRecoverableException
but no exception is catched...
How do I validate a XML and if invalid throw an exception? |
|
Back to top |
|
 |
fjb_saper |
Posted: Sat May 30, 2009 1:15 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Validation happens in the parse options. You should also look at possibly wiring the error terminal to a trace terminal. Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
kimbert |
Posted: Sat May 30, 2009 1:32 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
|
Back to top |
|
 |
fabyos |
Posted: Mon Jun 01, 2009 5:34 am Post subject: |
|
|
Apprentice
Joined: 15 May 2009 Posts: 37
|
I forgot to follow this thread, I thought that I have no response...
@kimbert
You are right, Im using 6.1.0.3, what I mean is that I started using MB four weeks ago...
There was no error with my code, the problem was that I was debugging message flow, and this is causing that exception, when I turned off the debug I get my parse validation exception logged with trace as you said.
Thanks for response and links, some of them I´ve already read it. |
|
Back to top |
|
 |
kimbert |
Posted: Mon Jun 01, 2009 7:42 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
some of them I´ve already read it. |
XMLNSC is the recommended way to process XML in v6.1.0.3. Why did you decide to use the not-deprecated-but-not-exactly-strategic MRM XML parser? |
|
Back to top |
|
 |
fabyos |
Posted: Mon Jun 01, 2009 10:01 am Post subject: |
|
|
Apprentice
Joined: 15 May 2009 Posts: 37
|
kimbert wrote: |
Quote: |
some of them I´ve already read it. |
XMLNSC is the recommended way to process XML in v6.1.0.3. Why did you decide to use the not-deprecated-but-not-exactly-strategic MRM XML parser? |
There is not an exactly motive to use MRM, the primary decision was because of the test generator which bind the input node and easily create the request, but now i figure out that I can do the same thing with XMLNSC which is the proper choice to deal with XML.
I started to change my code to parse to XMLNSC but not getting success doing it.
Code: |
DECLARE xmlAsBlob BLOB CAST(xml AS BLOB CCSID 1208);
CREATE LASTCHILD OF OutputRoot DOMAIN('XMLNSC') PARSE(
xmlAsBlob
OPTIONS ValidateContentAndValue
ENCODING InputRoot.Properties.Encoding
CCSID 1208 -- 1208=UTF-8, 819=ISO-8859-1
--SET 'PH4HRKS002001'
TYPE 'CADPES_OUTPUT'
FORMAT 'XML1');
|
but Im receiving an exception with number 5028 and Insert 'PH4HRKS002001'.
I´m looking for an example but there isnt any in infocenter... |
|
Back to top |
|
 |
fabyos |
Posted: Mon Jun 01, 2009 10:44 am Post subject: |
|
|
Apprentice
Joined: 15 May 2009 Posts: 37
|
@kimbert
The validation is now working, I just simplified the code to
Quote: |
CREATE LASTCHILD OF OutputRoot DOMAIN('XMLNSC') PARSE(
xmlAsBlob); |
And changed the validation to 'content and value' on my Compute Node (ESQL) and it worked.
Is it correct? How the validations is processed? He checks based on namespace and root node using the dictionary generated by all my XSD files? |
|
Back to top |
|
 |
kimbert |
Posted: Mon Jun 01, 2009 11:30 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
I just simplified the code to
Code: |
CREATE LASTCHILD OF OutputRoot DOMAIN('XMLNSC') PARSE(
xmlAsBlob); |
And changed the validation to 'content and value' on my Compute Node (ESQL) and it worked.
Is it correct? |
Well, it is working as designed, but I don't blame you for asking.
The CREATE statement is just parsing the XML message. It is not doing any validation because you are not requesting validation using the Options parameter.
When the message leaves the Compute node, the OutputRoot tree is being validated by the Compute node because you have set the Validation property of the Compute node to 'Content and Value'. It just happens that OutputRoot is the target of your CREATE statement, so the net effect is that your XML gets validated.
This is not the most efficient way to do the job. Validating like this will cause OutputRoot to be serialized and reparsed. I recommend that you
- Set Validation on the Compute node to 'None'
- In the parameters of the CREATE statement, remove the TYPE and FORMAT clauses ( XMLNSC does not need them ) and ensure that the Options clause is requesting validation. |
|
Back to top |
|
 |
fabyos |
Posted: Mon Jun 01, 2009 12:10 pm Post subject: |
|
|
Apprentice
Joined: 15 May 2009 Posts: 37
|
well.. I tried to set the options but i keep getting this exception:
Code: |
(0x01000000:Name ):ParserException = (
(0x03000000:NameValue):File = 'F:\build\S610_P\src\MTI\MTIforBroker\GenXmlParser4\ImbXMLNSCParser.cpp' (CHARACTER)
(0x03000000:NameValue):Line = 785 (INTEGER)
(0x03000000:NameValue):Function = 'ImbXMLNSCParser::getCachedIRForMessageSet' (CHARACTER)
(0x03000000:NameValue):Type = 'ComIbmMQInputNode' (CHARACTER)
(0x03000000:NameValue):Name = '...' (CHARACTER)
(0x03000000:NameValue):Label = '...' (CHARACTER)
(0x03000000:NameValue):Catalog = 'BIPv610' (CHARACTER)
(0x03000000:NameValue):Severity = 3 (INTEGER)
(0x03000000:NameValue):Number = 5028 (INTEGER)
(0x03000000:NameValue):Text = 'Validation is enabled but pre-processed schemas cannot be located for the specified message set ' (CHARACTER)
(0x01000000:Name ):Insert = (
(0x03000000:NameValue):Type = 5 (INTEGER)
(0x03000000:NameValue):Text = 'PH4HRKS002001' (CHARACTER)
)
) |
I have setted the validation to none and inserted the parse properties as i have with MRM, but no success..
I´ve tried with this:
Code: |
CREATE LASTCHILD OF OutputRoot DOMAIN('XMLNSC') PARSE(
xmlAsBlob
OPTIONS ValidateContentAndValue
ENCODING InputRoot.Properties.Encoding
CCSID 1208 -- 1208=UTF-8, 819=ISO-8859-1
SET 'PH4HRKS002001'); |
and this:
Code: |
CREATE LASTCHILD OF OutputRoot DOMAIN('XMLNSC') PARSE(
xmlAsBlob
OPTIONS ValidateContentAndValue
SET 'PH4HRKS002001'); |
I´ve deployed and redeployed but the validation never runs... |
|
Back to top |
|
 |
kimbert |
Posted: Mon Jun 01, 2009 12:17 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Aha!
In old versions of message broker ( pre v5.0, I think) you were *forced* to use the message set identifier in the SET parameter.
From vX.Y ( can't remember which ) you were able to use the message set name as an alternative.
The XMLNSC parser is thoroughly modern, and it insists that you do it the easy way. You *must* use the message set name and not the identifier. |
|
Back to top |
|
 |
fabyos |
Posted: Mon Jun 01, 2009 1:10 pm Post subject: |
|
|
Apprentice
Joined: 15 May 2009 Posts: 37
|
kimbert wrote: |
Aha!
In old versions of message broker ( pre v5.0, I think) you were *forced* to use the message set identifier in the SET parameter.
From vX.Y ( can't remember which ) you were able to use the message set name as an alternative.
The XMLNSC parser is thoroughly modern, and it insists that you do it the easy way. You *must* use the message set name and not the identifier. |
Hum.. didnt work... well that exceptions doesnt happen anymore, but no validation is done too... the message with errors is created successfully with the parse... |
|
Back to top |
|
 |
kimbert |
Posted: Mon Jun 01, 2009 1:36 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
Hum.. didnt work... well that exceptions doesnt happen anymore |
Hey, c'mon! We fixed one problem. Now we've uncovered a new one. That's standard problem solving.
Quote: |
no validation is done too... the message with errors is created successfully with the parse |
Details please. |
|
Back to top |
|
 |
fabyos |
Posted: Mon Jun 01, 2009 1:54 pm Post subject: |
|
|
Apprentice
Joined: 15 May 2009 Posts: 37
|
The message is sent with a char value instead of short (defined in XSD).
After running, the parsed tree is created with the char...
I´ve tried to create an alias to message set but it isnt founded... (response on event viewer)
Code: |
CREATE LASTCHILD OF OutputRoot DOMAIN('XMLNSC') PARSE(
xmlAsBlob
OPTIONS ValidateContentAndValue
ENCODING InputRoot.Properties.Encoding
CCSID 1208 -- 1208=UTF-8, 819=ISO-8859-1
SET 'Person_Registry'); |
I´ve tried w/o ENCODING, CCSID...
Searching on info center i found this type of syntax
Code: |
CREATE LASTCHILD OF OutputRoot.XMLNSC
PARSE(X DOMAIN XMLNSC
NAME discardComments
OPTIONS XMLNSC.CommentsRetainNone);[quote]
what is NAME attribute for?
On this link it says to use the validation property on node..
[url]http://publib.boulder.ibm.com/infocenter/wmbhelp/v6r1m0/index.jsp?topic=/com.ibm.etools.mft.doc/ad67020_.htm[/url]
There is no log since the message is tree is created...[/quote] |
|
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Jun 01, 2009 1:56 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Wouldn't you expect to create the message as last child of OutputRoot.XMLNSC instead of as last child of OutputRoot ?
The NAME attribute allows you to specify the name of your XML root tag.
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
kimbert |
Posted: Mon Jun 01, 2009 2:27 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
I´ve tried w/o ENCODING, CCSID... |
Don't remove those - they're absolutely required.
Quote: |
I´ve tried to create an alias to message set but it isnt founded |
No need for an alias here - it's finding the message set OK.
Quote: |
On this link it says to use the validation property on node |
That page is explaining the basics. Most users will select the XMLNSC parser on their input node, and set the validation options there as well. You have a different requirement because your message is coming from a database as a CLOB. So you have to use CREATE...PARSE, with validation enabled via the OPTIONS parameter.
Quote: |
The message is sent with a char value instead of short (defined in XSD). |
Some char values are valid shorts as well...but I'll trust you
I suggest the following steps:
a) Make sure that your input XML really is invalid.
b) Take a user trace, and look carefully at the lines which happen around the setup of the XMLNSC parser. You should see validation options being read, and afterwards you should see a message about the message set being looked up.
c) try parsing this message the standard way, using an MQInput or FileInput node with Validation set to 'Content and Value'. Just to prove that it *can* work. |
|
Back to top |
|
 |
|