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 » Converting CDATA XML into encoded un-formatted string

Post new topic  Reply to topic Goto page 1, 2  Next
 Converting CDATA XML into encoded un-formatted string « View previous topic :: View next topic » 
Author Message
wmb_wps_soa
PostPosted: Mon Feb 11, 2013 8:38 am    Post subject: Converting CDATA XML into encoded un-formatted string Reply with quote

Acolyte

Joined: 19 Feb 2010
Posts: 65
Location: Detroit,Michigan,USA.

Hi All,

I am trying to put a solution for an unique requirement that i have. I want to convert the formatted XML in the CDATA section to un-formatted encoded string like below to send out in the soap response:

From: (without soap headers)
<TestResponse>
<TestResult>
<SampleMessage><![CDATA[<AddRequest><ApplicationArea><DocumentGUID>e5ad4a00-7465-11e2-8242-0a053d1e0000</DocumentGUID></ApplicationArea><DataArea></DataArea></AddRequest>]]></SampleMessage>
</TestResult>
</TestResponse>

TO : (without soap headers)
<TestResponse>
<TestResult> <SampleMessage>&lt;AddRequest&gt;&#xD;&lt;ApplicationArea&gt;&#xD;&lt;DocumentGUID&gt;e5ad4a00-7465-11e2-8242-0a053d1e0000&lt;/DocumentGUID&gt;&#xD;&lt;/ApplicationArea&gt;&#xD;&lt;DataArea&gt;&#xD;&lt;/DataArea&gt;&#xD;&lt;/AddRequest&gt;</SampleMessage>
</TestResult>
</TestResponse>

Is there any way in wmb 7.0.03 to achieve this? i know i can just do a substring to take the CDATA out from the response. But, it will still be a xml string within the response (between <SampleMessage> and </SampleMessage>), but not the encoded xml string which i wanted.

Please share your thoughts.

Thanks
Back to top
View user's profile Send private message
mqjeff
PostPosted: Mon Feb 11, 2013 8:40 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

The XMLNSC parser should automatically convert < and > in element content as needed, as long as it outside a CDATA Section.
Back to top
View user's profile Send private message
kimbert
PostPosted: Mon Feb 11, 2013 12:37 pm    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

mqjeff is correct. Just assign the value of 'SampleMessage' to OutputRoot.XMLNSC.<yourElement> and let us know how it goes.
Back to top
View user's profile Send private message
NealM
PostPosted: Mon Feb 11, 2013 1:42 pm    Post subject: Reply with quote

Master

Joined: 22 Feb 2011
Posts: 230
Location: NC or Utah (depends)

Just a question: If he really wants to retain the &#xD (end-of-line) whitespace that he shows, shouldn't he be using the XMLNS parser rather than XMLNSC? (I know his "from" doesn't show them, I assume for brevity, but his "to" sure does.)
Back to top
View user's profile Send private message
mqjeff
PostPosted: Mon Feb 11, 2013 1:46 pm    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

NealM wrote:
Just a question: If he really wants to retain the &#xD (end-of-line) whitespace that he shows, shouldn't he be using the XMLNS parser rather than XMLNSC? (I know his "from" doesn't show them, I assume for brevity, but his "to" sure does.)

he or she can set parser options on XMLNSC to retain whitespace.
Back to top
View user's profile Send private message
wmbv7newbie
PostPosted: Tue May 13, 2014 1:36 am    Post subject: Reply with quote

Centurion

Joined: 13 May 2014
Posts: 121

Hi,

I have a similar requirement wherein I need to embed an xml within an xml. Inside xml has to be inserted as String. The structure looks something like -

Code:
<soapenv:Envelope xmlns:soapenv="" xmlns:hris="">
  <soapenv:Header/>
  <soapenv:Body>
    <hris:Dispatch>
      <hris:HRXML>&lt;?xml version='1.0' encoding='utf-8'?&gt;
        &lt;Envelope version='1.0'&gt;
        &lt;Sender&gt;
        &lt;Id&gt;HRXMLEMPLID&lt;/Id&gt;
        &lt;Credential&gt;25297&lt;/Credential&gt;
        &lt;/Sender&gt;
        &lt;Recipient&gt;
        &lt;/Users&gt;]]&gt;
        &lt;/Payload&gt;
        &lt;/Packet&gt;
        &lt;/Envelope&gt;
      </hris:HRXML>
    </hris:Dispatch>
  </soapenv:Body>
</soapenv:Envelope>


I tried casting the inner xml to String and then using the XMLNSC parser as below -

Code:
DECLARE OutputMessageBlob BLOB;
SET OutputMessageBlob = ASBITSTREAM OutputRoot.XMLNSC.hris:Dispatch.hris:HRXML);
DECLARE OutputMessageChar CHARACTER CAST(OutputMessageBlob AS CHARACTER CCSID 1208);            
CREATE LASTCHILD OF Environment.Variable.Data DOMAIN ('XMLNSC') PARSE (OutputMessageChar CCSID 1208);
SET OutputRoot.XMLNSC.hris:Dispatch.hris:HRXML = Environment.Variable.Data;


This doesnt give me the encoded string as expected. I am missing the entities '&it' and '&gt' in the generated xml.

Any leads would help.

Thanks!
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue May 13, 2014 2:52 am    Post subject: Reply with quote

Grand High Poobah

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

wmbv7newbie wrote:

This doesnt give me the encoded string as expected. I am missing the entities '&it' and '&gt' in the generated xml.

Any leads would help.

Thanks!

Working as designed. Why would you be getting them? You'd have a fully parsed tree instead! And by the way no need for the ASBITSTREAM. What you have is already the bitstream represented as the char value of the element...

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
wmbv7newbie
PostPosted: Tue May 13, 2014 2:58 am    Post subject: Reply with quote

Centurion

Joined: 13 May 2014
Posts: 121

Thanks for the quick reply!

The SOAP request has to have the inner xml (inside HRXML tag) as encoded String with character entities (&it and &gt). I thought the CAST and PARSE would give me that.

If this is the expected behaviour of XMLNSC parser, can you please explain how do I achieve the String in encoded form, as expected.

Thanks!
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue May 13, 2014 3:04 am    Post subject: Reply with quote

Grand High Poobah

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

mqjeff and Kimbert already told you on this thread.
Now if the white space is not embedded in the CData you have 0 chance of displaying it like you showed.

Anyway nobody should need the new lines between the XML elements and nobody should care as this is supposed to be machine readable stuff.

If you really need the new line stuff, I guess you'll have to write a complex routine to introduce it yourself....

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
wmbv7newbie
PostPosted: Tue May 13, 2014 3:42 am    Post subject: Reply with quote

Centurion

Joined: 13 May 2014
Posts: 121

Oh.

The third-party expects us to embed the inner xml and replace all < and > with characters &it; &gt;.

Will there be no way in Broker to do this in a simpler way?

Thanks!
Back to top
View user's profile Send private message
kimbert
PostPosted: Tue May 13, 2014 4:21 am    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

You need to understand a couple of things - after that, the solution will be obvious. Before I try to explain, it would be helpful if you could

1. Post the exact XML that you want to get out of the flow.
2. Add a Trace node before the Compute node. Set the pattern to '${Root}'
3. Add another Trace node after the Compute node. Set the pattern to '${Root}'
4. Put your input message through the flow, and then post the resulting trace output from both Trace nodes ( only the relevant parts, please ).

After that you may well realize what is happening. If not, I will at least be able to explain the problem with reference to the material that you have posted.
_________________
Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too.
Back to top
View user's profile Send private message
wmbv7newbie
PostPosted: Tue May 13, 2014 6:00 am    Post subject: Reply with quote

Centurion

Joined: 13 May 2014
Posts: 121

Hi kimbert,

Thanks for your patience. I have captured all the requested elements.

1. Expected SOAP request (with headers):

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hris="http://trm.brassring.com/HRIS">
<soapenv:Header/>
<soapenv:Body>
<hris:Dispatch>
<hris:HRXML>
&lt;?xml version='1.0' encoding='utf-8'?&gt;
&lt;Envelope version='1.0'&gt;
&lt;Sender&gt;
&lt;Id&gt;HRXMLEMPLID&lt;/Id&gt;
&lt;Credential&gt;25297&lt;/Credential&gt;
&lt;Email&gt;austin.blakely@pearson.com&lt;/Email&gt;
&lt;/Sender&gt;
&lt;Recipient&gt;
&lt;Id&gt;&lt;/Id&gt;
&lt;/Recipient&gt;
&lt;TransactInfo transactType='data'&gt;
&lt;TransactId&gt;1&lt;/TransactId&gt;
&lt;TimeStamp&gt;2014-04-08&lt;/TimeStamp&gt;
&lt;/TransactInfo&gt;
&lt;/Envelope&gt;
</hris:HRXML>
</hris:Dispatch>
</soapenv:Body>
</soapenv:Envelope>

2. Trace log extract before Compute node :

( ['MQROOT' : 0xc42e248]
(0x01000000:Name ):Properties = ( ['MQPROPERTYPARSER' : 0xcaa0b30]
(0x03000000:NameValue):MessageSet = '' (CHARACTER)
(0x03000000:NameValue):MessageType = '' (CHARACTER)
(0x03000000:NameValue):MessageFormat = '' (CHARACTER)
(0x03000000:NameValue):Encoding = 273 (INTEGER)
(0x03000000:NameValue):CodedCharSetId = 0 (INTEGER)

(0x01000000:Name ):MQMD = ( ['MQHMD' : 0xc52c3b0]
(0x03000000:NameValue):SourceQueue = 'A.PPL.KENEXA.USERFOUNDATION.IN' (CHARACTER)
(0x03000000:NameValue):Transactional = TRUE (BOOLEAN)
(0x03000000:NameValue):Encoding = 273 (INTEGER)
(0x03000000:NameValue):CodedCharSetId = 1208 (INTEGER)
(0x03000000:NameValue):Format = 'MQHRF2 ' (CHARACTER)

(0x01000000:Folder):XMLNSC = ( ['xmlnsc' : 0xc5e5768]
(0x01000000:Folder)http://tempuri.org/:vUserImportResponse = (
(0x03000102:NamespaceDecl)http://www.w3.org/2000/xmlns/:ns1 = 'http://tempuri.org/' (CHARACTER)
(0x01000000:Folder )http://tempuri.org/:Report_Data = (
(0x01000000:Folder)http://tempuri.org/:Report_Entry = (
(0x03000000:PCDataField)http://tempuri.org/:First_Name = 'FN' (CHARACTER)
(0x03000000:PCDataField)http://tempuri.org/:Last_Name = 'Sanjeev' (CHARACTER)

3. Trace log extract after Compute node :

( ['MQROOT' : 0xc42f0b8]
(0x01000000:Name ):Properties = ( ['MQPROPERTYPARSER' : 0xca9fa20]
(0x03000000:NameValue):MessageSet = 'XML' (CHARACTER)
(0x03000000:NameValue):MessageType = '' (CHARACTER)
(0x03000000:NameValue):MessageFormat = 'XML' (CHARACTER)
(0x03000000:NameValue):Encoding = 273 (INTEGER)
(0x03000000:NameValue):CodedCharSetId = 1208 (INTEGER)

(0x01000000:Folder):XMLNSC = ( ['xmlnsc' : 0xc5e5c78]
(0x01000000:Folder)http://trm.brassring.com/HRIS:Dispatch = (
(0x03000102:NamespaceDecl)xmlns:ns2 = 'http://trm.brassring.com/HRIS' (CHARACTER)
(0x01000000:Folder )http://trm.brassring.com/HRIS:HRXML = (
(0x01000000:Folder)http://trm.brassring.com/HRIS:Envelope = (
(0x01000000:Folder)http://trm.brassring.com/HRIS:Sender = (
(0x03000000:PCDataField):Id = 'HRXMLEMPLID' (CHARACTER)
(0x03000000:PCDataField):Credential = '25297' (CHARACTER)
(0x03000000:PCDataField):Email = '' (CHARACTER)

(0x03000001:CDataField )http://trm.brassring.com/HRIS:HRXML = '<NS1:Envelope xmlns:NS1="http://trm.brassring.com/HRIS"><NS1:Sender><Id>HRXMLEMPLID</Id><Credential>25297</Credential><Email></Email></NS1:Sender><NS1:Recipient><Id></Id></NS1:Recipient><NS1:TransactInfo transactType="data"><TransactId>3bc8d73e-94fc-4003-b950-ba55b62e6404</TransactId><TimeStamp>2014-05-13 19:21:35</TimeStamp></NS1:TransactInfo><NS1:Packet><PacketInfo packetType="data"><PacketId>1</PacketId><Action>SET</Action><Manifest>FOUNDATION_WSE_JOBCODE</Manifest></PacketInfo><NS1:Payload version=""><NS1:Foundation_Data NS1:Asynchronous=""><NS1:Foundation_Item><NS1:Code>FIN013</NS1:Code><NS1:Description NS1:language="">Cashier</NS1:Description><NS1:Status>A</NS1:Status><NS1:Code_Access_Groups>WSE China</NS1:Code_Access_Groups></NS1:Foundation_Item></NS1:Foundation_Data></NS1:Payload></NS1:Packet></NS1:Envelope>' (CHARACTER)

Hope I havent given much unnecessary detail.

Thanks!
Back to top
View user's profile Send private message
kimbert
PostPosted: Tue May 13, 2014 11:20 am    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

Thanks for the details. I still have questions, though.
1. Why do you care about having the &lt; &gt; entities in the output message? It would be neater ( and easier to debug ) if you used a CDATA section to contain the embedded XML document. The receiver will not care either way.
2. Your Compute node is adding namespaces into the document. Was that intentional?
3. Are you just trying to pass on the received XML document without any modification? If not, what exactly are you trying to do with it before passing it on?
_________________
Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too.
Back to top
View user's profile Send private message
wmbv7newbie
PostPosted: Tue May 13, 2014 10:13 pm    Post subject: Reply with quote

Centurion

Joined: 13 May 2014
Posts: 121

Hi kimbert,

Again thanks for your reply. Answers below:

1. I discussed this with the 3rd party and they are sure that the embedded XML, if sent completely as CDATA will fail at parsing. Although I am doubtful about this but now we are stuck with this structure to have &lt; and &gt; in the embedded XML.

2. Yes. The namespaces are intentionally added.

3. No. We are receiving an XML request, extracting some information and mapping it to the output expected structure. Some of the incoming details are being used in the compute node. We cannot just pass the received XML document becuase the Source and Target systems have very different structures.

Was the trace of any help in understanding the issue?

Do you think if no other option is available, I should replace all < and > with &lt; and &gt; in the embedded String (although I know that would be the lamest solution)?

Thanks!
Back to top
View user's profile Send private message
wmbv7newbie
PostPosted: Wed May 14, 2014 4:24 am    Post subject: Reply with quote

Centurion

Joined: 13 May 2014
Posts: 121

Hi,

After much discussion with the target system, we were able to convince them that CDATA would work. We tried with a part of the message and it worked, luckily.

But the complete message again gave errors because it would be a CDATA section within another CDATA section. Sample structure below -

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hris="http://trm.brassring.com/HRIS">
<soapenv:Header/>
<soapenv:Body>
<hris:Dispatch>
<!--Optional:-->
<hris:HRXML><![CDATA[<?xml version='1.0' encoding='utf-8'?>
<Envelope version='1.0'>
<Sender>
<Id>HRXMLEMPLID</Id>
<Credential>25297</Credential>
</Sender>
<Recipient>
<Id></Id>
</Recipient>
<TransactInfo transactType='data'>
<TransactId>1</TransactId>
<TimeStamp>2014-04-08</TimeStamp>
</TransactInfo>
<Packet>
<PacketInfo packetType='data'>
<PacketId>1</PacketId>
<Action>SET</Action>
<Manifest>WSE_USER</Manifest>
</PacketInfo>
<Payload>
<![CDATA[<?xml version="1.0"?>
<Users>
<User>
<FirstName>FN</FirstName>
<LastName>Sanjeev</LastName>
<EmployeeID>40005161</EmployeeID>
<UserName>PWEA@test.com</UserName>
<Password>password</Password>
<Email>email@email.com</Email>
<Expressuser>0</Expressuser>
<Manager>1</Manager>
<Recruiter>0</Recruiter>
<UserType>WSE - Hiring Manager</UserType>
<Status>A</Status>
<UserGroup>Standard Group</UserGroup>
<OrgGroup>
</OrgGroup>
<Country>China</Country>
<Localeid>1033</Localeid>
<Phone>13052187377</Phone>
<Fax>
</Fax>
<Title>JPN</Title>
<Dept>
</Dept>
<SUPERVISORID>
</SUPERVISORID>
<ROLE>
</ROLE>
<SignatureImage>
</SignatureImage>
<UserSignature>
</UserSignature>
<Language>EN</Language>
<ApprovalGroups>
<Group>WSE Approver 1</Group>
</ApprovalGroups>
<CodeAccessGroups>
<Group>WSE China</Group>
</CodeAccessGroups>
</User>
</Users>]]]]>><![CDATA[
</Payload>
</Packet>
</Envelope>]]></hris:HRXML>
</hris:Dispatch>
</soapenv:Body>
</soapenv:Envelope>

Any hints on how to escape the CDATA end tags for inside CDATA section? Otherwise it is giving me invalid xml (as expected).

Thanks!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Converting CDATA XML into encoded un-formatted string
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.