Deploying and Managing Apama Applications > Correlator-Integrated JMS Messaging > Mapping Apama events and JMS messages > Convention-based XML mapping > Convention-based JMS message mapping example
Convention-based JMS message mapping example
The following example shows how to parse a JMS message whose body contains an XML document and map it to an Apama event called MyEvent.
To parse a JMS whose body contains the following XML document:

<?xml version='1.0' encoding='UTF-8'?>
<myroot xmlns:p='http://www.myco.com/dummy-namespace'>
<myelement1>An element value</myelement1>
<myelement2 myattribute='123' myboolattribute='true'>456</myelement2>
<ignoredElement>XML content that is not included in the event definition
is ignored</ignoredElement>
<e1>Hello</e1>
<e1>there</e1>
<e-2 e2att='value1'><subElement>e2-sub-value1</subElement></e-2>
<e-2 e2att='value2'><subElement>e2-sub-value2</subElement></e-2>
<e1>world</e1>
<namespacedElement xmlns='urn:xmlns:foobar'>My namespaced
text</namespacedElement>
<p:namespacedElement>My namespaced text 2</p:namespacedElement>
<namespacedElement>My non-namespaced text 3</namespacedElement>
<return>Element whose name is an EPL keyword</return>
</myroot>
Define the Apama event MyEvent as follows:

event MyElement2
{
string _myattribute;
boolean _myboolattribute;
string xmlTextNode;

}

event E2
{
string _e2att;
string subElement;
}

event MyRoot
{
string myelement1;
MyElement2 myelement2;
sequence<string> e1;
sequence<string> namespacedElement;
string #return;
sequence<E2> e$002d2;
}

event MyEvent
{
string destination;
MyRoot myroot;
}
Note that the field names and types matter but the event type names do not.
The document above would be parsed to the following Apama event string:

MyEvent("queue:MyQueue",
MyRoot("An element value",
MyElement2("123",true,"456"),
["Hello","there","world"],
["My namespaced text","My namespaced text 2","My non-namespaced text 3"],
"Element whose name is an EPL keyword",
[E2("value1","e2-sub-value1"),E2("value2","e2-sub-value2")]
))
The exact same event definitions could be used in the other direction for creating an XML document, although the node order will be slightly different from that of the document shown above (based on the field order) and everything would be in the same XML namespace.
Copyright © 2013 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or Terracotta Inc., San Francisco, CA, USA, and/or Software AG (Canada) Inc., Cambridge, Ontario, Canada, and/or, Software AG (UK) Ltd., Derby, United Kingdom, and/or Software A.G. (Israel) Ltd., Or-Yehuda, Israel and/or their licensors.