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 Index » WebSphere Message Broker (ACE) Support » Unable to TRIM spaces/tabs/newlines on either sides of a tag

Post new topic  Reply to topic Goto page Previous  1, 2
 Unable to TRIM spaces/tabs/newlines on either sides of a tag « View previous topic :: View next topic » 
Author Message
Vitor
PostPosted: Thu Jan 13, 2011 9:28 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

Diwakar wrote:
So, the above 2 lines of code should do what I need ?


I'd have done it the other way (include all the acceptable characters) and saved a cast. Easier to read, less chance you're going to accidently omit something (or a new kind of rubbish will one day turn up) and more efficient when you have a large number of fields to clean.

But the principle is sound.

I'd also code it as a user-defined function to save some typing.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
Diwakar
PostPosted: Thu Jan 13, 2011 9:35 am    Post subject: Reply with quote

Apprentice

Joined: 06 Apr 2005
Posts: 33

Thanks Vitor,

But how do I use TRANSLATE with acceptable chars ? TRANSLATE is used to remove unwanted chars as per the syntax.

Also, the list of acceptable characters might be huge.

thanks
_________________
Diwakar.
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Jan 13, 2011 10:12 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

Diwakar wrote:
the list of acceptable characters might be huge


It's not huge, it's 200-odd possible printable characters and a one-time cost in typing them if you use a function.

Diwakar wrote:
But how do I use TRANSLATE with acceptable chars ?


You do something like this:

Code:

CREATE FUNCTION CleanseString(IN dirtyString CHARACTER) RETURNS CHARACTER
BEGIN

DECLARE cTemp CHARACTER;
SET cTemp = TRANSLATE(dirtyString,'!@#$%*()0987654321AaBb and so forth','');
RETURN TRANSLATE(dirtyString,cTemp,'');
END;


Code given is an untested example, supplied as is with no warranty express or implied accepted, etc, etc.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Thu Jan 13, 2011 10:33 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

So do we think two translates is more performant than one cast and one translate?
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Jan 13, 2011 10:37 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

mqjeff wrote:
So do we think two translates is more performant than one cast and one translate?


We think that. We have some experimental evidence to demonstrate that.

We also think that a string of readable characters that is the set of all characters we could ever want is better and easier to maintain than a list of all the hex values we don't want. Especially with a double byte character set.

We also think other people may have a different view and would want to code it the other way. We think that would work too.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
Diwakar
PostPosted: Thu Jan 13, 2011 10:52 am    Post subject: Reply with quote

Apprentice

Joined: 06 Apr 2005
Posts: 33

Vitor,

My question was the same as mqjeff's : is two translates bettwr than a cast and a translate ? That's why I asked how you'd translate it with acceptable characters.

Since you said you have some evidence, I take it as authentic.

Translate would remove characters from inside the string too, not just leading/trailing. So, I wonder what the consequences would be.

thanks
_________________
Diwakar.
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Jan 13, 2011 11:03 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

Diwakar wrote:
Translate would remove characters from inside the string too, not just leading/trailing. So, I wonder what the consequences would be.


Using spaces in this method, probably fatal.

As I've said, it's an example, coding the hex should work. Though as with spaces, if you have legitimate tab characters (for instance) in the string that's going to be a problem.

If there's a sporting change that this could happen then yes you need to code 30 odd TRIM statements and accept this is a consequence of the awkward situation you find yourself in where the schema doesn't describe the document properly. Even if the schema describes everything as a string of length 255 you can restrict the contents to valid values. Or even use something like <xs:whitespace value="replace"/> so you only have spaces to deal with.

Or just get the upstream application fixed not to put all this rubbish in the tags in the first place.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
mgk
PostPosted: Thu Jan 13, 2011 1:01 pm    Post subject: Reply with quote

Padawan

Joined: 31 Jul 2003
Posts: 1642

I have checked and the following code will do what you seem to be asking for:

Code:
DECLARE input1 CHARACTER 'testmgktest';
SET OutputRoot.XMLNSC.Top.Out1 = TRIM( 'ste' FROM input1);
                           
DECLARE whiteSpace CONSTANT CHARACTER CAST( X'090D0A20' AS CHAR CCSID 1208); /* tab, cr, lf, space */
DECLARE input2 CHARACTER 'foo';
                           
SET input2 = whiteSpace || input2 || whiteSpace;
SET OutputRoot.XMLNSC.Top.Out2 = TRIM( whiteSpace FROM input2);


The above code produces this output:
Code:
<Top><Out1>mgk</Out1><Out2>foo</Out2></Top>


This works because the TRIM function accepts a list of characters for the "singleton" argument, that are processed can be given any order (see example 1). I agree that this is not well documented, and so I have added the above as an example to the docs...

I hope this helps,

Kind Regards,
_________________
MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions.


Last edited by mgk on Thu Jan 13, 2011 1:13 pm; edited 1 time in total
Back to top
View user's profile Send private message
fatherjack
PostPosted: Thu Jan 13, 2011 1:08 pm    Post subject: Reply with quote

Knight

Joined: 14 Apr 2010
Posts: 522
Location: Craggy Island

Diwakar wrote:
I can't change the 'Awakward situation' for now, as I am not allowed to change all the code written already. So, I'll have to live with TRANSLATE I guess.

DECLARE invisibleCharList CHAR CAST(x'0d0a09 .....' AS CHAR ccsid 1208); -- all the invisible chars go in here
Declare outString CHAR TRANSLATE(sourceString, invisibleCharList);

So, the above 2 lines of code should do what I need ?

thanks.


Except when you get something else that you weren't expecting !
_________________
Never let the facts get in the way of a good theory.
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Jan 13, 2011 1:45 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

mgk wrote:
This works because the TRIM function accepts a list of characters for the "singleton" argument, that are processed can be given any order (see example 1). I agree that this is not well documented, and so I have added the above as an example to the docs...


Oooooooooo....................
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
Diwakar
PostPosted: Thu Jan 13, 2011 5:48 pm    Post subject: Reply with quote

Apprentice

Joined: 06 Apr 2005
Posts: 33

MGK,

Thanks for the post, and that's exactly what I needed.

I tried TRIM the way you suggested, and it worked for me.

TRANSLATE is messy, and may cause problems in my case because I need only the leading/trailing non-printable characters (including space) removed from an XML tag's value.

They are just 32 characters starting with hexadecimal x'01' upto x'20'. So, my nonPrintableCharsList string is x'010203...08090a0b...0e0f101112...1718191a1b...1e1f20'.

My code is like(for the benefit of others who are facing similar issues):

---------------------------------------------------------------
Declare nonPrintableCharsList CHAR CAST(x'010203...08090a0b...0e0f101112...1718191a1b...1e1f20' AS CHAR ccsid 1208); -- 32 hexadecimal values inside the string

SET OutputRoot.XMLNSC.Message.Header.price = TRIM(nonPrintableCharsList FROM InputRoot.XMLNSC.Message.Header.price);
---------------------------------------------------------------

Just curious, any idea how long it takes for the infocenter updates you made to be available to the rest of the world ? Everyone may not search this forum (may not find this thread so easily even if they search) for missing documentation.

Thanks.
_________________
Diwakar.
Back to top
View user's profile Send private message
smdavies99
PostPosted: Thu Jan 13, 2011 10:28 pm    Post subject: Reply with quote

Jedi Council

Joined: 10 Feb 2003
Posts: 6076
Location: Somewhere over the Rainbow this side of Never-never land.

Diwakar wrote:

Just curious, any idea how long it takes for the infocenter updates you made to be available to the rest of the world ? Everyone may not search this forum (may not find this thread so easily even if they search) for missing documentation.


I'll leave the IBM guys to answer the time for the on-line Inforcentre but it will be at least the next fix pack for one that is installed locally on your PC's HDD.
_________________
WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995

Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Goto page Previous  1, 2 Page 2 of 2

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Unable to TRIM spaces/tabs/newlines on either sides of a tag
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.