Author |
Message
|
mmksri |
Posted: Wed Aug 09, 2006 10:03 pm Post subject: Manipulating XML field having another XML |
|
|
 Newbie
Joined: 07 Jun 2006 Posts: 7
|
Hi All,
I need your kind help in resolving one of the issue I am facing here. I am getting a XML on the Broker with one of the field having another stringified ( all mark-ups repalced by their character entities ) xml. I need to convert it to normal XML mark-ups and apply transformation on those fields. I have a sample message below for your reference ( pls note that its not an actual msg. this is a msg I am using to do this POC before going for the actual implementation ).
Code: |
<?xml version="1.0" encoding="UTF-8"?>
<contact:Contact xsi:schemaLocation="http://www.ibm.com Contact.xsd " xmlns:contact="http://www.ibm.com" xmlns:xalan="http://xml.apache.org/xslt" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<contact:Name>ABC</contact:Name>
<contact:PostalAddress>
<contact:DeliverTo>ABC</contact:DeliverTo>
<contact:Street>XYZ</contact:Street>
<contact:payload><contact:City>Bangalore</contact:City></contact:payload>
<contact:State>Karnataka</contact:State>
<contact:PostalCode>560040</contact:PostalCode>
<contact:Country>India</contact:Country>
</contact:PostalAddress>
<contact:Email>abc@xyz.com</contact:Email>
</contact:Contact> |
pls note that the payload field having stringified XML tags. I need to convert them to regular XML markup and apply transformation.
I want to have it as below before applying transformation :
Code: |
<?xml version="1.0" encoding="UTF-8"?>
<contact:Contact xsi:schemaLocation="http://www.ibm.com Contact.xsd " xmlns:contact="http://www.ibm.com" xmlns:xalan="http://xml.apache.org/xslt" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
.
<contact:payload>
<contact:City>Bangalore</contact:City>
</contact:payload>
.
<contact:Email>abc@xyz.com</contact:Email>
</contact:Contact> |
I think we can apply ESQL REPLACE to convert those character entities to mark-up. But please note that character entities can also be part of the data that should not be considered as mark-up. For eg., payload can also have something like,
Code: |
<contact:payload><contact:City>Bangalore<Delhi</contact:City></contact:payload> |
In the above case < between Bangalore and Delhi should not be treated as mark-up. I am not understanding how to differentiate between character entity references which would form the mark-up and others would be part of the data.
Requesting you to guide me in achieving this. Thanks in advance. |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Aug 10, 2006 1:25 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
I think you want to use Create Field..Parse. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
kimbert |
Posted: Thu Aug 10, 2006 1:28 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
I would try solving a different problem. Why not encode the XML as base64 instead of mangling the markup? |
|
Back to top |
|
 |
mmksri |
Posted: Thu Aug 10, 2006 1:46 am Post subject: |
|
|
 Newbie
Joined: 07 Jun 2006 Posts: 7
|
Hi All,
Thanks for the response. Infact I have tried the create parse with no luck. pls find the ESQL I had for doing that.
Code: |
DECLARE newMsgBlob BLOB ;
DECLARE msgBlob BLOB ;
SET newMsgBlob = REPLACE ( InputRoot.BLOB.BLOB, CAST ('<' AS BLOB CCSID InputRoot.MQMD.CodedCharSetId), CAST ('<' AS BLOB CCSID InputRoot.MQMD.CodedCharSetId));
SET newMsgBlob = REPLACE ( newMsgBlob, CAST ('>' AS BLOB CCSID InputRoot.MQMD.CodedCharSetId), CAST ('>' AS BLOB CCSID InputRoot.MQMD.CodedCharSetId));
CREATE LASTCHILD OF OutputRoot DOMAIN 'XMLNS' PARSE(newMsgBlob); |
In this case its replacing the character entity < between the data also resulting in a invalid xml.
Any suggestions would really help..
kimbert - can you please elaborate bit more on the solution you suggested..
Thanks to both of you for your kind reply. |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Aug 10, 2006 1:53 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
I meant using Create Field .. Parse on the payload to turn it into XML.
Although now I'm not sure that it will work. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
kimbert |
Posted: Thu Aug 10, 2006 1:58 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
kimbert - can you please elaborate bit more on the solution you suggested.. |
I think the input format is poorly-designed. It's going to be tricky to correctly decode the character entities. The usual solution when embedding XML inside XML is to encode it as hexBinary or base64.
Having said that, you may not be able to change the input format. So you have to write a simple 'XML' parser which remembers which opening 'tags' you have seen, and leaves alone any < or > entities which are not expected. A Java Compute node might be the way to go. |
|
Back to top |
|
 |
|