Author |
Message
|
newtobroker |
Posted: Sat Feb 06, 2010 2:26 pm Post subject: ASBITSTREAM for XMLNSC |
|
|
Novice
Joined: 04 Feb 2010 Posts: 23
|
Hi,
I have an XML in string format as below
Code: |
<o:Test xmlns:o="http://abcd.com/service/testing"><o:Name>Carol</o:Name><o:Addr>Addr123</o:Addr></o:Test>
|
I have to attach this XML to the Envelope Tag which is
Code: |
<Envelope>
<ID>A123</ID>
<Company>ABC</Company>
</Envelope>
|
So the output should finally look like
Code: |
<Envelope>
<ID>A123</ID>
<Company>ABC</Company>
<o:Test xmlns:o="http://abcd.com/service/testing"><o:Name>Carol</o:Name><o:Addr>Addr123</o:Addr></o:Test>
</Envelope>
|
Im using XMLNSC parser in my code.
I tried the below way
Code: |
--- Environment.Variables.TestXML contains the TestXML
SET OutputRoot.XMLNSC.Envelope.(XMLNSC.AsisElementContent)Orch = Environment.Variables.TestXML;
DECLARE blobOrcMsg BLOB;
-- Converting the retrieved Message Content to bitstream for parsing with XML Parser.
SET blobOrcMsg = ASBITSTREAM(OutputRoot.XMLNSC.Envelope.Orch ENCODING InputRoot.Properties.Encoding
CCSID InputRoot.Properties.CodedCharSetId SET '' TYPE '' FORMAT '' OPTIONS FolderBitStream);
SET blobOrcMsg = SUBSTRING(blobOrcMsg FROM 7 FOR ((LENGTH(blobOrcMsg) - 13)));
SET OutputRoot.XMLNSC.RPEnvelope.Orch = NULL;
CREATE LASTCHILD OF OutputRoot.XMLNSC.Envelope DOMAIN 'XMLNSC'
PARSE (blobOrcMsg, InputRoot.Properties.Encoding, InputRoot.Properties.CodedCharSetId,
'', '', 'XMLNSC');
-- Pointing Reference variables to required elements/tags
DECLARE RefEnvIFXMsg REFERENCE TO OutputRoot.XMLNSC.Envelope.XMLNSC.Orch;
Detach RefEnvIFXMsg;
SET OutputRoot.XMLNSC.Envelope.XMLNSC = NULL;
ATTACH RefEnvIFXMsg TO OutputRoot.XMLNSC.Envelope AS LASTCHILD;
|
But I'm getting an error at
Code: |
SET blobOrcMsg = ASBITSTREAM(OutputRoot.XMLNSC.Envelope.Orch ENCODING InputRoot.Properties.Encoding
CCSID InputRoot.Properties.CodedCharSetId SET '' TYPE '' FORMAT '' OPTIONS FolderBitStream);
|
The Error is
Code: |
<Text>XML Writing Errors have occurred</Text>
- <ParserException>
<File>/build/S610P/src/MTI/MTIforBroker/GenXmlParser4/ImbXMLNSCWriter.cpp</File>
<Line>229</Line>
<Function>ImbXMLNSCWriter::writeBuffer</Function>
<Type />
<Name />
<Label />
<Catalog>BIPv610</Catalog>
<Severity>3</Severity>
<Number>5907</Number>
<Text>Invalid target for folder bitstream</Text>
- <Insert>
<Type>5</Type>
<Text>Orch</Text>
</Insert>
- <Insert>
<Type>2</Type>
<Text>50333184</Text>
</Insert>
- <Insert>
<Type>5</Type>
<Text><o:Test xmlns:o="http://abcd.com/service/testing"><o:Name>Carol</o:Name><o:Addr>Addr123</o:Addr></o:Test></Text>
</Insert>
|
What can be going wrong here ? This code was working when it was XML, now i changed to XMLNSC and it breaks. |
|
Back to top |
|
 |
kimbert |
Posted: Mon Feb 08, 2010 4:41 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Please can you post the entire error message. The exception list is not very useful on its own.
You can get the full text from Windows Event Viewer, or by taking a user trace if you're not using Windows. |
|
Back to top |
|
 |
newtobroker |
Posted: Wed Feb 10, 2010 12:51 pm Post subject: |
|
|
Novice
Joined: 04 Feb 2010 Posts: 23
|
Hi Kimbert,
The broker is on z/os so i dont know how to get you the dump of the trace. Anyhow in my trace, i can see that the env variable is populated with the xml, but its giving the error while attaching it to XMLNSC.
In short the question is how to attach an XML that has a namespace to another XML that doesnt have a namespace and using XMLNSC parser?
Input XML1
Code: |
<o:Test xmlns:o="http://abcd.com/service/testing"><o:Name>Carol</o:Name><o:Addr>Addr123</o:Addr></o:Test>
|
Input XML2
Code: |
<Envelope>
<ID>A123</ID>
<Company>ABC</Company>
</Envelope>
|
The final output should look like
Code: |
<Envelope>
<ID>A123</ID>
<Company>ABC</Company>
<o:Test xmlns:o="http://abcd.com/service/testing"><o:Name>Carol</o:Name><o:Addr>Addr123</o:Addr></o:Test>
</Envelope>
|
Thank,
c* |
|
Back to top |
|
 |
kimbert |
Posted: Wed Feb 10, 2010 3:40 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
I think this is your requirement:
- there is an XML subtree stored as a CHARACTER field in Environment.XML.TestXML.
- You want to add it as the last child of OutputRoot.XMLNSC.Envelope.
I suggest this:
Code: |
DECLARE testXMLasBLOB BLOB CAST Environment.XML.testXML AS BLOB CCSID 1208;
CREATE LASTCHILD OF OutputRoot.XMLNSC.Envelope PARSE testXMLasBLOB CCSID 1208; |
Normally you need a DOMAIN clause when using CREATE...PARSE, but I think in this case it will inherit the domain from InputRoot.XMLNSC.Envelope. mgk is welcome to correct me on that.
btw, I don't recommend the use of XMLNSC.AsIsElementContent. The docs make clear that it should only be used if nothing else will do the job. |
|
Back to top |
|
 |
newtobroker |
Posted: Wed Feb 10, 2010 8:08 pm Post subject: |
|
|
Novice
Joined: 04 Feb 2010 Posts: 23
|
Kimbert, this is cool.. it worked.. Thanks !!
I'm not using XMLNSC.AsIsElementContent. |
|
Back to top |
|
 |
kimbert |
Posted: Thu Feb 11, 2010 7:23 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
This should also work, and is even simpler:
Code: |
CREATE LASTCHILD OF OutputRoot.XMLNSC.Envelope PARSE Environment.XML.testXML CCSID 1208; |
I didn't realize that CREATE...PARSE can take a CHARACTER or BIT field instead of a BLOB. |
|
Back to top |
|
 |
newtobroker |
Posted: Thu Feb 11, 2010 6:10 pm Post subject: |
|
|
Novice
Joined: 04 Feb 2010 Posts: 23
|
Kimbert,
One thing that i noticed today is that there is an XMLNSC tag getting added extra to the xml. The output now looks like
Code: |
<Envelope>
<ID>A123</ID>
<Company>ABC</Company>
<XMLNSC>
<o:Test xmlns:o="http://abcd.com/service/testing"><o:Name>Carol</o:Name><o:Addr>Addr123</o:Addr></o:Test>
</XMLNSC>
</Envelope>
|
whereas it should be something like below
Code: |
<Envelope>
<ID>A123</ID>
<Company>ABC</Company>
<o:Test xmlns:o="http://abcd.com/service/testing"><o:Name>Carol</o:Name><o:Addr>Addr123</o:Addr></o:Test>
</Envelope>
|
How to remove this extra XMLNSC ?
Thanks,
C* |
|
Back to top |
|
 |
kimbert |
Posted: Fri Feb 12, 2010 12:34 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Like this:
Code: |
CREATE LASTCHILD OF OutputRoot.XMLNSC.Envelope PARSE Environment.XML.testXML CCSID 1208 OPTIONS FolderBitStream; |
|
|
Back to top |
|
 |
newtobroker |
Posted: Fri Feb 12, 2010 11:10 pm Post subject: |
|
|
Novice
Joined: 04 Feb 2010 Posts: 23
|
Kimbert,
Thanks, I will try this option and let you know. Meanwhile im enjoying htis forum. This site has great SME's.
Thanks
C* |
|
Back to top |
|
 |
|