0

Is it possible to add something like that:

<?xml version="1.0" encoding="UTF-8"?>

to WSO2 XML Formatter in inline section? I see that tag is always added before tag "eventFormatter", but when I pass the event through CEP and I get the answer in my queue, the output XML doesn't have this tag.

If I want add it in inline section I get this error:

Failed to update event formatter, Exception: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[7,10] Message: The processing instruction target matching "[xX][mM][lL]" is not allowed.

//Udpate

My Formatter looks like:

<?xml version="1.0" encoding="UTF-8"?>
<eventFormatter name="Formatter_XML_Out" statistics="disable"
  trace="disable" xmlns="http://wso2.org/carbon/eventformatter">
    <from streamName="Test_stream_out_xml" version="1.0.0"/>
    <mapping customMapping="enable" type="xml">
        <inline>
            <Event>
                <Name>{{Name}}</Name>
                <Surname>{{Surname}}</Surname>
            </Event>
        </inline>
    </mapping>
    <to eventAdaptorName="ActiveMQ_Output" eventAdaptorType="jms">
        <property name="transport.jms.Destination">myQueue</property>
    </to>
</eventFormatter>

I get this in output message:

<Event>
    <Name>XXXX</Name>
    <Surname>YYYYY</Surname>
</Event>

Why this tag <?xml version="1.0" encoding="UTF-8"?> is gone?

Community
  • 1
  • 1
Kacu
  • 438
  • 4
  • 23

2 Answers2

1

It seems that WSO2CEP 3.x cannot format the message when using an XML mapping with the <?xml version="1.0" encoding="UTF-8"?> tag.

A workaround is to use Text mapping instead as follows

<?xml version="1.0" encoding="UTF-8"?>
<eventFormatter name="Formatter_XML_Out" statistics="disable"
  trace="disable" xmlns="http://wso2.org/carbon/eventformatter">
    <from streamName="Test_stream_out_xml" version="1.0.0"/>
    <mapping customMapping="enable" type="text">
        <inline>
          <![CDATA[
            <?xml version="1.0" encoding="UTF-8"?>
            <Event>
                <Name>{{Name}}</Name>
                <Surname>{{Surname}}</Surname>
            </Event>
          ]]>
        </inline>
    </mapping>
    <to eventAdaptorName="ActiveMQ_Output" eventAdaptorType="jms">
        <property name="transport.jms.Destination">myQueue</property>
    </to>
</eventFormatter>

use type="text" here.

suho
  • 912
  • 6
  • 12
0

No. The ?xml text declaration must appear at the beginning of the document:

The text declaration MUST NOT appear at any position other than the beginning of an external parsed entity.

This is enforced by XML parsers.

From your edit, it looks like you want your output document to include a declaration. The only way to control this would be through the outer eventFormatter configuration. The documentation doesn't show a way to do this.

However, there's no need for it - UTF-8 is already the default in the absence of a declaration, so it can be omitted.

Joe
  • 29,416
  • 12
  • 68
  • 88
  • Thx, for your replay. I know that this tag must be first, and it is in my CEP formatter, but in output XML message this tag is gone, and I don't know why. Maybe someone knows why? Maybe there is a workaround to get this tag in my output XML message? – Kacu Apr 20 '15 at 13:49
  • Yes, I know that this CEP documentation doesn't show how to do this, so I'm looking for some workaround how to do this (if this could be possible at all). Thx for help. – Kacu Apr 23 '15 at 22:11
  • Note that "there's no need for it" -- if you think you need it, add an explanation to your question as there may be an alternatice. – Joe Apr 24 '15 at 09:53