ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum IndexWebSphere Message Broker SupportHow to set a field as more XML rather than character text

Post new topicReply to topic
How to set a field as more XML rather than character text View previous topic :: View next topic
Author Message
simonalexander2005
PostPosted: Thu Aug 17, 2017 7:57 am Post subject: How to set a field as more XML rather than character text Reply with quote

Apprentice

Joined: 13 Jun 2016
Posts: 28

I am noticing some interesting behaviour, and was wondering if anyone can shed some light on it?

Say I create a message like this:

Code:

-- in compute node #1
SET ENVIRONMENT.LOG.OutMessage = '<test>testing</test>';

-- in compute node #2, which I can't change
-- snip namespace definitions - nm1 and xsi
SET OutputRoot.XMLNSC.nm1:OutMessage.(XMLNSC.NamespaceDecl)xmlns = nm1;
DECLARE outRef REFERENCE TO OutputRoot.XMLNSC.nm1:OutMessage;
SET outRef.(XMLNSC.NamespaceDecl)xmlns:xsi = 'http://www.w3.org/2001/XMLSchema-instance';
SET outRef.(XMLNSC.Attribute)classification = 'confidential';
-- snip some other attributes
SET outRef.nm1:OutMessageDetails.nm1:LongDescription.nm1:Detail = ENVIRONMENT.LOG.OutMessage;
RETURN TRUE; -- write to queue


so I've got some CHARACTER text that looks to the naked eye like XML; and I've put it into a field (element text) in an XML message; that gives something like this:

Code:
<OutMessage xmlns="...." classification="confidential" ...><OutMessageDetails><LongDescription><Detail><test>testing</test></Detail></LongDescription></OutMessageDetails></OutMessage>


When the message is browsed by MQ Explorer, it sees that the <test>testing</test> is not XML because it escapes that text with &lt; etc - but RFHUtil doesn't; it shows the text with < and > as above.

From this, I am assuming that when I do
Code:
SET outRef.nm1:OutMessageDetails.nm1:LongDescription.nm1:Detail = ENVIRONMENT.LOG.OutMessage;
, it's actually escaping the characters at that point.

So I then tried changing the first compute node as follows:

Code:

-- in compute node #1
SET ENVIRONMENT.LOG.OutMessage.test = 'testing';


i.e. creating the sub-xml element as a field in the environment, rather than using a character string.

This then leads the second compute node to throw an error:

Code:
      (0x01000000:Name     ):ParserException = (
        (0x03000000:NameValue):File     = 'F:\build\slot1\S900_P\src\MTI\MTIforBroker\GenXmlParser4\ImbXMLNSCWriter.cpp' (CHARACTER)
        (0x03000000:NameValue):Line     = 674 (INTEGER)
        (0x03000000:NameValue):Function = 'ImbXMLNSCWriter::writeElement' (CHARACTER)
        (0x03000000:NameValue):Type     = '' (CHARACTER)
        (0x03000000:NameValue):Name     = '' (CHARACTER)
        (0x03000000:NameValue):Label    = '' (CHARACTER)
        (0x03000000:NameValue):Catalog  = 'BIPmsgs' (CHARACTER)
        (0x03000000:NameValue):Severity = 3 (INTEGER)
        (0x03000000:NameValue):Number   = 5014 (INTEGER)
        (0x03000000:NameValue):Text     = 'Element must have a namespace specified if there is a default namespace in scope' (CHARACTER)
        (0x01000000:Name     ):Insert   = (
          (0x03000000:NameValue):Type = 5 (INTEGER)
          (0x03000000:NameValue):Text = 'test' (CHARACTER)


Is there any way to get this to recognise the <test> tags as XML rather than a character, or know to use the default namespace; all in the first compute node?
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Aug 17, 2017 8:42 am Post subject: Re: How to set a field as more XML rather than character tex Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 24448
Location: Ohio, USA

simonalexander2005 wrote:
When the message is browsed by MQ Explorer, it sees that the <test>testing</test> is not XML because it escapes that text with &lt; etc - but RFHUtil doesn't; it shows the text with < and > as above.


Both are correct. Those characters are not allowed in the XML content so must be escaped (as shown by Explorer). Helpful XML viewers interpret these escapes as their representative characters (like RFHUtil).

simonalexander2005 wrote:
From this, I am assuming that when I do
Code:
SET outRef.nm1:OutMessageDetails.nm1:LongDescription.nm1:Detail = ENVIRONMENT.LOG.OutMessage;
, it's actually escaping the characters at that point.


No - they're escaped on serialization.

simonalexander2005 wrote:
So I then tried changing the first compute node as follows:

Code:

-- in compute node #1
SET ENVIRONMENT.LOG.OutMessage.test = 'testing';


i.e. creating the sub-xml element as a field in the environment, rather than using a character string.


That doesn't create a sub XML element. Despite the fact the Environment is displayed in the same format as the XMLNSC tree, the XMLNSC domain is not associated with the Environment tree unless you associate it with code.


simonalexander2005 wrote:
Is there any way to get this to recognise the <test> tags as XML rather than a character, or know to use the default namespace; all in the first compute node?


Associate the XMLNSC domain with the Environment tree, and use CREATE .... FROM rather than SET.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Thu Aug 17, 2017 8:25 pm Post subject: Re: How to set a field as more XML rather than character tex Reply with quote

Grand Poobah

Joined: 18 Nov 2003
Posts: 19246
Location: LI,NY

Vitor wrote:

Associate the XMLNSC domain with the Environment tree, and use CREATE .... FROM rather than SET.

And don't forget that there is no default namespace in the broker.
Therefore each element that falls into a default namespace must have that namespace associate to it explicitly.

Hope it helps
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
simonalexander2005
PostPosted: Fri Aug 18, 2017 1:46 am Post subject: Re: How to set a field as more XML rather than character tex Reply with quote

Apprentice

Joined: 13 Jun 2016
Posts: 28

fjb_saper wrote:
Vitor wrote:

Associate the XMLNSC domain with the Environment tree, and use CREATE .... FROM rather than SET.

And don't forget that there is no default namespace in the broker.
Therefore each element that falls into a default namespace must have that namespace associate to it explicitly.

Hope it helps


OK, I've changed my computeNode1 code from:

Code:
SET Environment.LOG.OutMessage = '<test>testing</test>';


to

Code:
CREATE FIRSTCHILD OF Environment.LOG.OutMessage DOMAIN 'XMLNSC' NAMESPACE nm1 NAME 'test';
SET Environment.LOG.OutMessage.nm1:test = 'testing';


And that seems to be enough to get it to work - my output is
Quote:
<OutMessage><LongDescription><Detail><test>testing</test></Detail></LongDescription></OutMessage>


But I haven't followed your advice to use
Code:
CREATE ... FROM
- to use FROM it seems you need to already have the tree somewhere to copy it. What am I missing here?
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Fri Aug 18, 2017 3:44 am Post subject: Re: How to set a field as more XML rather than character tex Reply with quote

Grand Poobah

Joined: 18 Nov 2003
Posts: 19246
Location: LI,NY

simonalexander2005 wrote:

But I haven't followed your advice to use
Code:
CREATE ... FROM
- to use FROM it seems you need to already have the tree somewhere to copy it. What am I missing here?

Code:
CREATE...PARSE

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
Vitor
PostPosted: Fri Aug 18, 2017 5:07 am Post subject: Re: How to set a field as more XML rather than character tex Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 24448
Location: Ohio, USA

simonalexander2005 wrote:
But I haven't followed your advice to use
Code:
CREATE ... FROM
- to use FROM it seems you need to already have the tree somewhere to copy it. What am I missing here?


If you have something more extensive than one element, you might find:

Code:

CREATE outRef.nm1:OutMessageDetails.nm1:LongDescription.nm1:Detail FROM Environment.LOG.OutMessage;


is more efficient.

But whatever works.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
Vitor
PostPosted: Fri Aug 18, 2017 5:08 am Post subject: Re: How to set a field as more XML rather than character tex Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 24448
Location: Ohio, USA

fjb_saper wrote:
Code:
CREATE...PARSE

Have fun




Skin the cat in whatever way you feel is best for you.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
simonalexander2005
PostPosted: Fri Aug 18, 2017 6:21 am Post subject: Re: How to set a field as more XML rather than character tex Reply with quote

Apprentice

Joined: 13 Jun 2016
Posts: 28

Vitor wrote:
simonalexander2005 wrote:
But I haven't followed your advice to use
Code:
CREATE ... FROM
- to use FROM it seems you need to already have the tree somewhere to copy it. What am I missing here?


If you have something more extensive than one element, you might find:

Code:

CREATE outRef.nm1:OutMessageDetails.nm1:LongDescription.nm1:Detail FROM Environment.LOG.OutMessage;


is more efficient.

But whatever works.


Aha I see - sorry, I thought you meant in the first compute node where I'm setting the Environment values. Unfortunately I can't edit that second compute node where the outRef is set - so I have to use what I've got (the first one) - the
Code:
SET outRef.nm1:OutMessageDetails.nm1:LongDescription.nm1:Detail = ENVIRONMENT.LOG.OutMessage;
won't change.

So given that, is there a way to do this that also allows attributes to copy without turning them into elements?

Also as an aside, wouldn't your sample copy the "OutMessage" field inside the "Detail" field (which isn't what I want)?
Back to top
View user's profile Send private message
Vitor
PostPosted: Fri Aug 18, 2017 8:08 am Post subject: Re: How to set a field as more XML rather than character tex Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 24448
Location: Ohio, USA

simonalexander2005 wrote:
So given that, is there a way to do this that also allows attributes to copy without turning them into elements?


Assuming you've set the XMLNSC domain and specified the attributes as attributes not elements (by using the correct XMLNSC field type) then they should be preserved. I do it with a CREATE but it should work with a SET. Probably. Almost certainly. Unless it doesn't.

simonalexander2005 wrote:
Also as an aside, wouldn't your sample copy the "OutMessage" field inside the "Detail" field (which isn't what I want)?


Yes. So sue me.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
simonalexander2005
PostPosted: Mon Aug 21, 2017 12:13 am Post subject: Re: How to set a field as more XML rather than character tex Reply with quote

Apprentice

Joined: 13 Jun 2016
Posts: 28

Vitor wrote:
simonalexander2005 wrote:
So given that, is there a way to do this that also allows attributes to copy without turning them into elements?


Assuming you've set the XMLNSC domain and specified the attributes as attributes not elements (by using the correct XMLNSC field type) then they should be preserved. I do it with a CREATE but it should work with a SET. Probably. Almost certainly. Unless it doesn't.

simonalexander2005 wrote:
Also as an aside, wouldn't your sample copy the "OutMessage" field inside the "Detail" field (which isn't what I want)?


Yes. So sue me.


It doesn't get preserved with a SET, at least not as far as I can see.

Sorry, I wasn't trying to sound attacking; I was just clarifying a point. No suing required
Back to top
View user's profile Send private message
timber
PostPosted: Mon Aug 21, 2017 2:43 am Post subject: Reply with quote

Yatiri

Joined: 25 Aug 2015
Posts: 654

I haven't read the entire thread, so this might not be relevant, but...

If you use SET, you are responsible for specifying the TYPE attribute for any elements that get created by the SET. If you use FROM, the TYPE attributes will be copied from the source message tree.
Back to top
View user's profile Send private message
Display posts from previous:
Post new topicReply to topic Page 1 of 1

MQSeries.net Forum IndexWebSphere Message Broker SupportHow to set a field as more XML rather than character text
Jump to:



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
Protected by Anti-Spam ACP


Theme by Dustin Baccetti
Powered by phpBB 2001, 2002 phpBB Group

Copyright MQSeries.net. All rights reserved.