Topic
  • 4 replies
  • Latest Post - ‏2013-02-05T08:29:53Z by sunnytech
SystemAdmin
SystemAdmin
4179 Posts

Pinned topic Storing a message's XML into an XML element as text

‏2005-10-11T11:32:19Z |
For error reporting, I need to store the input message into another XML element. Bascially, this requires me to convert the whole InputRoot.XML element into a text string (including) tags, etc.) and assign it to another element so that it is not picked up as an XML construct, but simply as a literal text string (I want to include it in the body of an e-mail message). Example of desired result follows ( are replaced by [] as this forum actual converts the XML in this message, and therefore omits important parts of the message text:

Message
SubjectError Message[/Subject]
Body
Line'TestMessageLevel1Some text[/Level1]TestMessage'[/Line]
[/Body]
[/Message]

Where the InputRoot.XML contains the TestMessage, and the OutputRoot.XML.Message.Body.Line contains that InputRoot.XML as a delimited string (delimited by single quotes ("'")).

Any input appreciated!

Thanks,

Jeff
Updated on 2013-02-05T08:29:53Z at 2013-02-05T08:29:53Z by sunnytech
  • SystemAdmin
    SystemAdmin
    4179 Posts

    Re: Storing a message's XML into an XML element as text

    ‏2005-10-11T14:52:59Z  
    Use ASBITSTREAM to serialze the input body and assign it to an element in the output tree
  • zhnupy
    zhnupy
    2 Posts

    Re: Storing a message's XML into an XML element as text

    ‏2010-06-16T01:04:01Z  
    Use ASBITSTREAM to serialze the input body and assign it to an element in the output tree
    Hello,
    I'm facing same requirement. I manage to write output, however I don't see it as text but as a sequence of codes (ascii codes it seems) of the string.
    So the question is, how to 'escape' that stream into actual characters?

    hope someone can help
  • kimbert@uk.ibm.com
    kimbert@uk.ibm.com
    515 Posts

    Re: Storing a message's XML into an XML element as text

    ‏2010-06-17T08:13:03Z  
    • zhnupy
    • ‏2010-06-16T01:04:01Z
    Hello,
    I'm facing same requirement. I manage to write output, however I don't see it as text but as a sequence of codes (ascii codes it seems) of the string.
    So the question is, how to 'escape' that stream into actual characters?

    hope someone can help
    ASBITSTREAM is not only for XML formats. It is a generic function that converts a message tree to a BLOB using a parser ( as specified in the DOMAIN clause ).

    If you want the result as a CHARACTER variable, you can just do this:
    DECLARE myBLOB BLOB ASBITSTREAM myRef DOMAIN 'XMLNSC' CCSID 1208
    DECLARE myXML CHARACTER CAST myBLOB AS CHARACTER CCSID 1208

    However, you should be able to do it in a single step.
    ( only possible because ASBITSTREAM detects the data type of the target variable )

    DECLARE myXML CHARACTER ASBITSTREAM myRef DOMAIN 'XMLNSC' CCSID 1208

    I expect the syntax is wrong, but you should get the idea.
  • sunnytech
    sunnytech
    11 Posts

    Re: Storing a message's XML into an XML element as text

    ‏2013-02-05T08:29:53Z  
    Thanks Kimbert, I was having the same problem and resolved it with your guide. Exact syntax is as:

    DECLARE options INTEGER BITOR(FolderBitStream, ValidateContent,ValidateValue); -- can be changed.

    SET Environment.Variables.EmailBitStreamAbStr = CAST(ASBITSTREAM (InputRoot.XMLNSC.EmailNotification,,1208,,,,options) as CHAR CCSID 1208);

    use Trace node to see the output Environment variable in one line xml string.

    Cheers