Author |
Message
|
broly |
Posted: Thu Jan 31, 2013 9:44 am Post subject: Convert an XML from the InputRoot, into a plain xml |
|
|
Newbie
Joined: 02 Aug 2012 Posts: 6
|
Hi Folks.
I've spent like 3 days trying to solve this problem.
My requirement is as follows: From the InputRoot I receive an XML,
but inside the body of the SOAP message, there's a part of XML
I want to extract.
Once I've extracted the part of the XML,
I need to transform it into a String to store it in a
Character variable to manipulate it.
What I have until this moment is the new xml using the "ASBITREAM" function but the xml result has converted some Attributes into elements.
Do you have any ideas about this???
This is the code I have:
Code: |
DECLARE contenidoXML CHARACTER '';
SET OutputRoot.XMLNSC.ws:getFileXMLResponse.cfd:Comprobante = Environment.getFileXMLResponse;
SET contenidoXML = CAST(ASBITSTREAM (OutputRoot.XMLNSC) AS CHARACTER CCSID 1208);
SET OutputRoot.XMLNSC = NULL;
|
Thanks[/code] |
|
Back to top |
|
 |
Vitor |
Posted: Thu Jan 31, 2013 9:50 am Post subject: Re: Convert an XML from the InputRoot, into a plain xml |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
broly wrote: |
but inside the body of the SOAP message, there's a part of XML
I want to extract. |
How is this stored? CData section? Or do you mean some subset of the SOAP message payload XML?
broly wrote: |
Once I've extracted the part of the XML,
I need to transform it into a String to store it in a
Character variable to manipulate it. |
Why? If it's XML, why do you want (or need) to manipulate it as a string? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
lancelotlinc |
Posted: Thu Jan 31, 2013 10:11 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
I think you are missing the RootBitStream parameter which is discussed extensively in the training class. _________________ http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER |
|
Back to top |
|
 |
broly |
Posted: Thu Jan 31, 2013 10:15 am Post subject: Re: Convert an XML from the InputRoot, into a plain xml |
|
|
Newbie
Joined: 02 Aug 2012 Posts: 6
|
Vitor wrote: |
How is this stored? CData section? Or do you mean some subset of the SOAP message payload XML?
|
I mean, it is a subset of the SOAP message payload XML
Vitor wrote: |
Why? If it's XML, why do you want (or need) to manipulate it as a string? |
Once this xml is in plain text, I need to convert it to base64 and send it to another web service. That's why I need this xml as a plain text
Do you have any ideas???
Thanks |
|
Back to top |
|
 |
lancelotlinc |
Posted: Thu Jan 31, 2013 10:22 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
If you would attend the required training class, you would be engaged by an instructor who would walk you through creating an Environment XMLNSC structure, which when complete, would be the XML you want. You then use RootBitStream to create a STRING that can be used in an OutputRoot to a file node to write the XML to disk (or a SoapRequest node to the web service if you prefer).
But since you have not attended that class.... _________________ http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Jan 31, 2013 11:28 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You certainly would never use RootBitstream to serialize a section of an input message.
There's no apparent need to move the message into environment in the first place.
There's no apparent need to write custom code to EXTRACT a SOAP body.
But given all that, as long as the message tree is properly stored in Environment to retain it's XMLNSC nature, there's no reason that ASBITSTREAM with the correct option won't work. |
|
Back to top |
|
 |
lancelotlinc |
Posted: Thu Jan 31, 2013 11:32 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
mqjeff wrote: |
You certainly would never use RootBitstream to serialize a section of an input message. |
I never said you would. What I said was, construct an XMLNSC tree in Environment, then use RootBitStream on that tree to create a CHARACTER STRING, as is the goal of the OP.
mqjeff wrote: |
There's no apparent need to move the message into environment in the first place. |
No one is moving anything. You are creating an entirely new tree, according to the format desired. The OP wants to edit the incoming data to a new tree format.
mqjeff wrote: |
But given all that, as long as the message tree is properly stored in Environment to retain it's XMLNSC nature, there's no reason that ASBITSTREAM with the correct option won't work. |
It works, and is an exercise from the class. For example, taking an InputRoot.SOAP.Body subset of elements and creating an output file with XML or PDF format. _________________ http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER |
|
Back to top |
|
 |
broly |
Posted: Thu Jan 31, 2013 11:39 am Post subject: |
|
|
Newbie
Joined: 02 Aug 2012 Posts: 6
|
mqjeff wrote: |
But given all that, as long as the message tree is properly stored in Environment to retain it's XMLNSC nature, there's no reason that ASBITSTREAM with the correct option won't work. |
Mqjeff, what is the correct option I have to specify using ASBITSTREAM?. What I worry about all of this is that given this xml.
Code: |
<custom-xml id="temporal" data="ok">
<some-tag>some value</some-tag>
</custom-xml>
|
After the transformation to text, becomes:
Code: |
<custom-xml>
<id>temporal</id>
<data>ok</data>
<some-tag>some value</some-tag>
</custom-xml>
|
All the attributes are converted to elements. What is the correct option to avoid this behavior. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Jan 31, 2013 11:46 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
broly wrote: |
mqjeff wrote: |
But given all that, as long as the message tree is properly stored in Environment to retain it's XMLNSC nature, there's no reason that ASBITSTREAM with the correct option won't work. |
Mqjeff, what is the correct option I have to specify using ASBITSTREAM?. What I worry about all of this is that given this xml. |
It's the option that is not RootBitstream.
broly wrote: |
All the attributes are converted to elements. What is the correct option to avoid this behavior. |
Don't stick it in Environment. Use InputRoot directly. |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Jan 31, 2013 1:14 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
@ broly
mqjeff wrote: |
But given all that, as long as the message tree is properly stored in Environment to retain it's XMLNSC nature, there's no reason that ASBITSTREAM with the correct option won't work. |
And remember that by default the Environment tree has no parser attached.
So unless you defined one to the branch you're attaching your stuff, moving your stuff to the Environment will change your attributes...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
broly |
Posted: Thu Jan 31, 2013 1:57 pm Post subject: |
|
|
Newbie
Joined: 02 Aug 2012 Posts: 6
|
Thanks to all.
It works, I moved the message from Environment to InputRoot and now the attributes are not converted to elements anymore.
.  |
|
Back to top |
|
 |
kash3338 |
Posted: Thu Jan 31, 2013 4:47 pm Post subject: |
|
|
Shaman
Joined: 08 Feb 2009 Posts: 709 Location: Chennai, India
|
broly wrote: |
It works, I moved the message from Environment to InputRoot and now the attributes are not converted to elements anymore. |
It is more clear when you say, you never moved your InputRoot to Environment and had directly used your InputRoot in the ASBITSTREAM function. You can never move/populate stuff into InputRoot object/reference. |
|
Back to top |
|
 |
lancelotlinc |
Posted: Fri Feb 01, 2013 5:21 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
fjb_saper wrote: |
mqjeff wrote: |
But given all that, as long as the message tree is properly stored in Environment to retain it's XMLNSC nature, there's no reason that ASBITSTREAM with the correct option won't work. |
And remember that by default the Environment tree has no parser attached.
So unless you defined one to the branch you're attaching your stuff, moving your stuff to the Environment will change your attributes...  |
If you read my post carefully, you will notice I initialize my Environment assigments under the XMLNSC parser attribute.
How is the OP supposed to edit the InputRoot structure to modify its format?
Are you suggesting its easier to edit a character string to format XML data rather than have the data in a proper tree structure and let the XMLNSC parser create the proper XML structure to send to the web service?
As per the documentation:
Quote: |
RootBitStream, the algorithm that generates the bit stream is the same as that used by an output node. In this mode, a meaningful result is obtained only if the element pointed to is at the head of a subtree with an appropriate structure. |
For example:
Code: |
DECLARE options INTEGER BITOR( ValidateNone, RootBitStream );
SET InputMessageData = ASBITSTREAM( Environment.Root.XMLNSC OPTIONS options ); |
_________________ http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER
Last edited by lancelotlinc on Fri Feb 01, 2013 6:15 am; edited 3 times in total |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Feb 01, 2013 5:31 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
lancelotlinc wrote: |
If you read my post carefully, you will notice I initialize my Environment assigments under the XMLNSC parser attribute.
How is the OP supposed to edit the InputRoot structure to modify its format? |
Didn't know your new nickname was broly! Thanks for clearing that up.  _________________ MQ & Broker admin |
|
Back to top |
|
 |
|