Author |
Message
|
angka |
Posted: Wed Sep 03, 2008 2:25 am Post subject: Manipulating XML |
|
|
Chevalier
Joined: 20 Sep 2005 Posts: 406
|
Hi,
Below my xml
<Message>
<MessageHeader>
<MsgID/>
.....
</MessageHeader>
<MessageBody ServiceID = "123">
<Payload xmlns:xsd ....>
............
</Payload>
</MessageBody>
</Message>
I parsed the incoming message as XML and i need to set the <Payload> to OutputRoot.XML. below my code
Set OutputRoot.XML = InputRoot.XML.Message.MessageBody;
using this code, i got the ServiceID too, how to i set only the <Payload> child to OutputRoot.XML?
Thanks |
|
Back to top |
|
 |
kimbert |
Posted: Wed Sep 03, 2008 3:01 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Please do not use the XML domain because
a) it is deprecated.
b) your input XML contains namespaces
Code: |
SET OutputRoot.XMLNSC.Payload = InputRoot.XMLNSC.Message.MessageBody.Payload; |
|
|
Back to top |
|
 |
angka |
Posted: Wed Sep 03, 2008 3:44 am Post subject: |
|
|
Chevalier
Joined: 20 Sep 2005 Posts: 406
|
Hi,
i can't use this
SET OutputRoot.XMLNSC.Payload = InputRoot.XMLNSC.Message.MessageBody.Payload;
because the <Payload> tag is unknown.. i.e. it is another xml schema? the <Payload> tag is an example, it could be any element name. What i need is to retrieve everything after tag <MessageBody> but not it attributes.
Thank you |
|
Back to top |
|
 |
kimbert |
Posted: Wed Sep 03, 2008 4:22 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
So you want the child tag under <MessageBody>?
XMLNSC makes this a little more difficult than it should, but that is being corrected. For now, I suggest that you switch to the XMLNS domain, and use this:
Code: |
SET OutputRoot.XMLNS.Payload = InputRoot.XMLNS.Message.MessageBody.(XML.Element)*[1]; |
|
|
Back to top |
|
 |
Gaya3 |
Posted: Wed Sep 03, 2008 4:26 am Post subject: |
|
|
 Jedi
Joined: 12 Sep 2006 Posts: 2493 Location: Boston, US
|
is this possible on XMLNSC (i didnt test this)
SET OutputRoot.XMLNSC.Payload = InputRoot.XMLNSC.Message.MessageBody.[>]; _________________ Regards
Gayathri
-----------------------------------------------
Do Something Before you Die |
|
Back to top |
|
 |
Gemz |
Posted: Wed Sep 03, 2008 5:06 am Post subject: |
|
|
 Centurion
Joined: 14 Jan 2008 Posts: 124
|
I have used in my code like
SET OutputRoot.XMLNSC.Payload = InputRoot.XMLNSC.Message.MessageBody.*[<];
So I hope that ll also work. |
|
Back to top |
|
 |
kimbert |
Posted: Wed Sep 03, 2008 5:08 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Gaya3: You need to make sure that you are selecting the tag, rather than some whitespace which might have occurred before or after the tag. That's why I'm testing for XML.Element.
By default XMLNSC discards whitespace before and after tags ( mixed content ) so your code is probably safe. |
|
Back to top |
|
 |
angka |
Posted: Wed Sep 03, 2008 7:21 am Post subject: |
|
|
Chevalier
Joined: 20 Sep 2005 Posts: 406
|
Hi,
Can I set it this way without the .Payload as shown below:
SET OutputRoot.XMLNS = InputRoot.XMLNS.Message.MessageBody.(XML.Element)*[1];
this is because the tag <Payload> can be <a>, <b> or <c>. i wanna assigned the whole of the child tag under <MessageBody> minus the attributes to OutputRoot.XMLNS therefore my MQ body would only contend the whole <a>
Thanks |
|
Back to top |
|
 |
kimbert |
Posted: Wed Sep 03, 2008 8:00 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Of course you can. If you do it this way, the result with either be an empty output message ( so you should be careful of that ), or an output message in which the first child tag under MessageBody is the root tag of the output message. |
|
Back to top |
|
 |
angka |
Posted: Wed Sep 03, 2008 8:03 am Post subject: |
|
|
Chevalier
Joined: 20 Sep 2005 Posts: 406
|
Hi,
it will not be empty because the payload is the application data. ya that is wat i wan the first child tag under MessageBody is the root tag of my output message. i will try it tmr.
Thanks |
|
Back to top |
|
 |
angka |
Posted: Wed Sep 03, 2008 7:46 pm Post subject: |
|
|
Chevalier
Joined: 20 Sep 2005 Posts: 406
|
Hi,
I tried the below code:
SET OutputRoot.XMLNS = InputRoot.XMLNS.Message.MessageBody.(XML.Element)*[1];
the InputRoot.XMLNS.Message.MessageBody is returning null value. why is this so? i tried (parsing to XMLNS)
SET charTest = InputRoot.XMLNS.Message.MessageBody.ServiceId;
and i got null also. but when i tried (parsing to XML)
SET charTest = InputRoot.XML.Message.MessageBody.ServiceId;
i got the value. What is wrong?
Thanks |
|
Back to top |
|
 |
marko.pitkanen |
Posted: Wed Sep 03, 2008 9:54 pm Post subject: |
|
|
 Chevalier
Joined: 23 Jul 2008 Posts: 440 Location: Jamsa, Finland
|
Hi angka,
Perhaps you could try Trace -node before your CN with pattern ${Root} to see how your message have been parsed to the message tree.
And use debug trace(mqsichangetrace, mqsireadlog & mqsiformatlog) for you EG and search the detailed information about you code execution.
Marko |
|
Back to top |
|
 |
angka |
Posted: Wed Sep 03, 2008 10:15 pm Post subject: |
|
|
Chevalier
Joined: 20 Sep 2005 Posts: 406
|
Hi,
Ok.. i will retrieve the trace later.
BTW, is there a way to specify the tag as a variable for e.g,
SET OutputRoot.XMLNS.{variable} = InputRoot.....
Thanks. |
|
Back to top |
|
 |
Gaya3 |
Posted: Wed Sep 03, 2008 10:27 pm Post subject: |
|
|
 Jedi
Joined: 12 Sep 2006 Posts: 2493 Location: Boston, US
|
angka wrote: |
BTW, is there a way to specify the tag as a variable for e.g,
SET OutputRoot.XMLNS.{variable} = InputRoot.....
|
yes, you can do like this, you have to define the variable in advance _________________ Regards
Gayathri
-----------------------------------------------
Do Something Before you Die |
|
Back to top |
|
 |
angka |
Posted: Wed Sep 03, 2008 11:23 pm Post subject: |
|
|
Chevalier
Joined: 20 Sep 2005 Posts: 406
|
Hi,
you mean as below?
SET charTest = 'PayLoad1';
SET OutputRoot.XMLNS.{charTest} = InputRoot.XMLNS.Message.MessageBody.(XML.Element)*[1];
Thanks |
|
Back to top |
|
 |
|