Author |
Message
|
KoGor |
Posted: Fri Mar 12, 2010 9:18 am Post subject: Easy way to convert HTML entities (< etc ) to tags |
|
|
Voyager
Joined: 09 Nov 2005 Posts: 81 Location: Moscow,Russia.
|
Hi All!
I have a message flow that receives response from web-service in such way:
Code: |
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Header>
<m:BRANCH_CODE xmlns:m="http://new.webservice.namespace">0000</m:BRANCH_CODE>
<m:REF_IDF xmlns:m="http://new.webservice.namespace">123456712345678123456789012345</m:REF_IDF>
<m:IDF xmlns:m="http://new.webservice.namespace">123456712345678123456789012345</m:IDF>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<m:COMM_REPORT_REPLY xmlns:m="http://new.webservice.namespace">
<m:ACCOUNT>40817810700000022222</m:ACCOUNT>
<m:BEG_DATE>26/02/2009</m:BEG_DATE>
<m:END_DATE>26/02/2010</m:END_DATE>
<m:REPORT_TYPE>REPORT_XML</m:REPORT_TYPE>
<m:RESULT>
<m:RESULT_DATA>
<?xml version="1.0" encoding="WINDOWS-1251"?>
<!-- edited with XMLSpy v2008 rel. 2 sp2 (http://www.altova.com) by ruaora1 (Raiffeisen Informatik Consulting GmbH) -->
<AccountStatements>
<Header>
<StatementID/>
<StatementNumber/>
<Account>40817810700000022222</Account>
.
.
<SenderAcc>42305978500000002222</SenderAcc>
</Statement>
</Statements>
</AccountStatements>
</m:RESULT_DATA>
</m:RESULT>
</m:COMM_REPORT_REPLY>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
|
I need to re-parse the SOAP body and change HTML entities into valid symbols. Then I want to transform this string to a message body with ASBITSTREAM command and resend as MQ message. I have not found the solution still except search through array of entities anr replace them manually. But I'm afraid that it will be slow solution and not efficient. Is there other way to solve this problem?
Thank you in advance! |
|
Back to top |
|
 |
smdavies99 |
Posted: Fri Mar 12, 2010 11:14 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
It looks like the bits that need to be sorted out should be inside a CDATA statement. AFAIK, that should sort it out. PErhaps the incoming message is wrong in this part. _________________ 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 |
|
 |
kimbert |
Posted: Sat Mar 13, 2010 11:59 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
All XML parsers should automatically translate character entities into the corresponding character. All the broker's XML parsers do.
Please insert a Trace node and post the contents of the <m:RESULT_DATA> tag as seen in the Trace node ouput. |
|
Back to top |
|
 |
KoGor |
Posted: Tue Mar 30, 2010 12:29 pm Post subject: |
|
|
Voyager
Joined: 09 Nov 2005 Posts: 81 Location: Moscow,Russia.
|
Sorry for the late answer but I was out of this project.
In debug mode I've got this string from my response
XM = \n<?xml version="1.0" encoding="WINDOWS-1251"?>\n<AccountStatements>\n\t<Header>\n\t\t<StatementID/>\n\t\t<StatementNumber/>\n\t\t<Account>40817810700000022222</Account>\n .... etc.
As I understand now I should parse this variable so I can access to the XML fields. I tried this command but failed:
Code: |
SET Environment.Variables.XM = InputRoot.XMLNSC.senv:Envelope.senv:Body.m:COMM_REPORT_REPLY.m:RESULT.m:RESULT_DATA; -- Just to check it is not empty, next command tries to parse the string
CREATE LASTCHILD OF Environment.Variables DOMAIN('XMLNSC') PARSE(InputRoot.XMLNSC.senv:Envelope.senv:Body.m:COMM_REPORT_REPLY.m:RESULT.m:RESULT_DATA,
InputProperties.Encoding,
InputProperties.CodedCharSetId); |
I tried different combinations but always get the error: XML Parsing Errors have occurred
Also I've tried to encode this string as BLOB and then PARSE:
Code: |
DECLARE xmlstring BLOB cast(InputRoot.XMLNSC.senv:Envelope.senv:Body.m:COMM_REPORT_REPLY.m:RESULT.m:RESULT_DATA as BLOB CCSID 1251);
CREATE LASTCHILD OF Environment.Variables DOMAIN('XMLNSC') PARSE(xmlstring, InputProperties.Encoding, 1251);
|
But anyway the parser failed. What do I wrong? Could be the problem because of CCSID is not 1208 but Windows 1251? |
|
Back to top |
|
 |
kimbert |
Posted: Tue Mar 30, 2010 2:01 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
I tried different combinations but always get the error: XML Parsing Errors have occurred |
Please answer all of the following questions:
Q1: Where did you see this error?
Q2: Did you attempt to get a more useful error message?
Q3: What is the code page of the string that you are attempting to parse? |
|
Back to top |
|
 |
KoGor |
Posted: Tue Mar 30, 2010 11:40 pm Post subject: |
|
|
Voyager
Joined: 09 Nov 2005 Posts: 81 Location: Moscow,Russia.
|
I build simple message flow to test this issue: MQInput->Trace->Compute .
Q1: This error I can see only while I'm debugging message flow. After executing the command CREATE ... PARSE ... in compute node
Q2: I put trace node before compute node to look content of an element RESULT_DATA. In an input message this element contains string with HTML Entities and looks like this: '\n<AccountStatements> \n<Header>... etc' After MQInputNode it is parsed in XMLNSC domain and in trace node it seems that parser replace input HTML entities correctly except the element '"'
Code: |
(0x01000000:Folder):XMLNSC = ( ['xmlnsc' : 0xae7090]
(0x01000000:Folder)http://schemas.xmlsoap.org/soap/envelope/:Envelope = (
(0x03000102:NamespaceDecl)http://www.w3.org/2000/xmlns/:SOAP-ENV = 'http://schemas.xmlsoap.org/soap/envelope/' (CHARACTER)
(0x03000102:NamespaceDecl)http://www.w3.org/2000/xmlns/:SOAP-ENC = 'http://schemas.xmlsoap.org/soap/encoding/' (CHARACTER)
(0x03000102:NamespaceDecl)http://www.w3.org/2000/xmlns/:xsi = 'http://www.w3.org/2001/XMLSchema-instance' (CHARACTER)
(0x03000102:NamespaceDecl)http://www.w3.org/2000/xmlns/:xsd = 'http://www.w3.org/2001/XMLSchema' (CHARACTER)
(0x01000000:Folder )http://schemas.xmlsoap.org/soap/envelope/:Header = (
(0x03000000:PCDataField)http://new.webservice.namespace:BRANCH_CODE = '0000' (CHARACTER)
(
(0x03000102:NamespaceDecl)http://www.w3.org/2000/xmlns/:m = 'http://new.webservice.namespace' (CHARACTER)
)
(0x03000000:PCDataField)http://new.webservice.namespace:REF_IDF = '123456712345678123456789012345' (CHARACTER)
(
(0x03000102:NamespaceDecl)http://www.w3.org/2000/xmlns/:m = 'http://new.webservice.namespace' (CHARACTER)
)
(0x03000000:PCDataField)http://new.webservice.namespace:IDF = '123456712345678123456789012345' (CHARACTER)
(
(0x03000102:NamespaceDecl)http://www.w3.org/2000/xmlns/:m = 'http://new.webservice.namespace' (CHARACTER)
)
)
(0x01000000:Folder )http://schemas.xmlsoap.org/soap/envelope/:Body = (
(0x01000000:Folder)http://new.webservice.namespace:COMM_REPORT_REPLY = (
(0x03000102:NamespaceDecl)http://www.w3.org/2000/xmlns/:m = 'http://new.webservice.namespace' (CHARACTER)
(0x03000000:PCDataField )http://new.webservice.namespace:ACCOUNT = '40817810700000022222' (CHARACTER)
(0x03000000:PCDataField )http://new.webservice.namespace:BEG_DATE = '26/02/2009' (CHARACTER)
(0x03000000:PCDataField )http://new.webservice.namespace:END_DATE = '26/02/2010' (CHARACTER)
(0x03000000:PCDataField )http://new.webservice.namespace:REPORT_TYPE = 'REPORT_XML' (CHARACTER)
(0x01000000:Folder )http://new.webservice.namespace:RESULT = (
(0x03000000:PCDataField)http://new.webservice.namespace:RESULT_DATA = '
<?xml version="1.0" encoding="WINDOWS-1251"?>
<!-- edited with XMLSpy v2008 rel. 2 sp2 (http://www.altova.com) by ruaora1 -->
<AccountStatements>
<Header>
<StatementID/>
<StatementNumber/>
<Account>40817810700000022222</Account>
<AccountInfo>РТБФД ИВАНОВ ИВАН ИВАНОВИЧ</AccountInfo>
<Operator>СИДОРОВА Е.С.</Operator>
<BranchBankPhone>258-32-00</BranchBankPhone>
<BranchBankName>СМОЛЕНСКАЯ 28</BranchBankName>
<BranchBankAddress>СМОЛЕНСКАЯ,Д.28</BranchBankAddress>
<ShortClientName>ИВАНОВ ИВАН ИВАНОВИЧ</ShortClientName>
.
.
<RecipientName>ИВАНОВ ИВАН ИВАНОВИЧ</RecipientName>
<RecipientAcc>40817810700000022222</RecipientAcc>
<SenderAcc>42305978500000002222</SenderAcc>
</Statement>
</Statements>
</AccountStatements>
' (CHARACTER)
)
)
)
)
)
)
|
Q3: An MQ message has CCSID set to 1251 and the message body itself is in Windows 1251 code page. I've checked it several times. |
|
Back to top |
|
 |
kimbert |
Posted: Wed Mar 31, 2010 12:53 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Those answers are not correct. Here are the correct answers:
Quote: |
Q1: This error I can see only while I'm debugging message flow. After executing the command CREATE ... PARSE ... in compute node |
Message broker writes every error to the following places
- the ExceptionList ( this is what the debugger is displaying )
- the system event log ( Windows Event Viewer on Windows )
- user trace
If your job is to write and debug message flows then you must learn how to fix problems in your message flows. And you cannot fix problems unless you know how to get the full error message.
Quote: |
After MQInputNode it is parsed in XMLNSC domain and in trace node it seems that parser replace input HTML entities correctly except the element '"' |
I have looked at the Trace node output, and the " has been replaced correctly. I think you must have been looking at your earlier post.
Quote: |
Q3: An MQ message has CCSID set to 1251 and the message body itself is in Windows 1251 code page. I've checked it several times. |
You are describing your input message. The CHARACTER field in the message tree is in code page 1200 - just like all CHARACTER fields in the message tree. You should be able to parse your REFDATA field like this:
Code: |
CREATE LASTCHILD OF Environment.Variables DOMAIN('XMLNSC') PARSE xmlstring; |
Note that I am using an undocumented feature here - if you specify a BLOB field then you have to specify the encoding and ccsid. But you are allowed to specify a CHARACTER field.
Finally...if this does not work *please* post the full text of any error messages. |
|
Back to top |
|
 |
KoGor |
Posted: Thu Apr 01, 2010 4:27 am Post subject: |
|
|
Voyager
Joined: 09 Nov 2005 Posts: 81 Location: Moscow,Russia.
|
There is no exception or error in none of the locations you listed. Only this message "XML Parsing Errors have occurred" while I'm debugging a flow. I post the screen-shot below:
Actually I've solved the problem partly. The element RESULT_DATA is containing at the begginnig the XML Declaration.
Code: |
<?xml version="1.0" encoding="WINDOWS-1251"?>
<AccountStatements>
<Header>
<StatementID/>
<StatementNumber/>
<Account>40817810700000022222</Account>
|
I removed the XML Declaration :
Code: |
<?xml version="1.0" encoding="WINDOWS-1251"?> |
And after that broker had managed to parse this element with the command:
Code: |
CREATE LASTCHILD OF OutputRoot DOMAIN('XMLNSC') PARSE (InputRoot.XMLNSC.env:Envelope.env:Body.m:COMM_REPORT_REPLY.m:RESULT.m:RESULT_DATA ENCODING InputRoot.Properties.Encoding CCSID InputRoot.Properties.CodedCharSetId); |
And even " is parsed correctly. Now I'm trying to fix this XML Declaration issue. Has anybody idea how to fix it?
Quote: |
Finally...if this does not work *please* post the full text of any error messages. |
I would post it with pleasure if I have any  |
|
Back to top |
|
 |
kimbert |
Posted: Thu Apr 01, 2010 5:05 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
There is no exception or error in none of the locations you listed. |
One of the locations that I listed was 'user trace'. Please post the user trace that you took. |
|
Back to top |
|
 |
|