Author |
Message
|
wmb61_user |
Posted: Tue May 20, 2008 7:08 pm Post subject: Add namespace to XML output using XML. |
|
|
Novice
Joined: 08 May 2008 Posts: 18
|
Can some one help me with defining namespaces in ESQL.
I currently have an output from comput lieke this.
<OrderHeader>
<OrderIdentifier>ABC123<OrderIdentifier>
<OrderType>3<OrderType>
<CustomerDistributionCenter>02<CustomerDistributionCenter>
</OrderHeader>
I would like to look add namespace information in my compue node.
i.e Add the XML tag and define name space lfob
<?xml version="1.0" encoding="UTF-8"?>
<lfob:OrderInventory xmlns:lfob="http://www.xyz.com/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.xyz.com/namespace OrderInventory.xsd ">
<lfob:OrderHeader>
<lfob:OrderIdentifier>ABC123</lfob:OrderIdentifier>
<lfob:OrderType>3</lfob:OrderType>
<lfob:CustomerDistributionCenter>02</lfob:CustomerDistributionCenter>
</lfob:OrderHeader> |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue May 20, 2008 7:41 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
You need to use XMLNS and you should use XMLNSC.
As well define the namespace:
DECLARE myns NAMESPACE 'http://mynamespace';
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
kimbert |
Posted: Wed May 21, 2008 1:34 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
It's a little more work than that. In your Compute node, you need to set the namespace on every element in your message tree ( defining and using an ESQL namespace prefix is the best way to do that, as fjp_saper says ).
That will produce an output XML document with XML namespace prefixes 'NS1', 'NS2' etc. If you want to choose your own XML namespace prefixes, you will need to add namespace declarations into the message tree.
http://publib.boulder.ibm.com/infocenter/wmbhelp/v6r1m0/topic/com.ibm.etools.mft.doc/ac67194_.htm |
|
Back to top |
|
 |
wmb61_user |
Posted: Wed May 21, 2008 12:23 pm Post subject: Adding XML namespace |
|
|
Novice
Joined: 08 May 2008 Posts: 18
|
Kimbert, Thanks for the response. However I am still not getting it.
Can some post a snippet of code please. I want to know how to apply namespace prefix to the entire message tree. |
|
Back to top |
|
 |
kimbert |
Posted: Wed May 21, 2008 12:45 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
I want to know how to apply namespace prefix to the entire message tree. |
Sorry - not possible. The message tree is not an XML document. It is more like a DOM tree. Each node has its own namespace.
If you want to change the namespace for each and every node in the message tree, you need to explicitly set the namespace on each and every node. That means walking the tree recursively.
This has been discussed before - the code snippet in this thread may help, but treat it with care, because I think is contains a defect: http://www.mqseries.net/phpBB2/viewtopic.php?t=25039&postdays=0&postorder=asc&start=15 |
|
Back to top |
|
 |
wmb61_user |
Posted: Thu May 22, 2008 8:30 am Post subject: Adding XML namespace |
|
|
Novice
Joined: 08 May 2008 Posts: 18
|
Kimbert,
Thanks for the direction so far. I am using the following code and getting a new namspace for each of the elements. How do I get the name space of lfob for all the elements. Thanks a lot for you help.
ECLARE lfob NAMESPACE 'http://www.lfob.com/namespace';
MOVE FieldRefPtr FIRSTCHILD;
IF LASTMOVE(FieldRefPtr) THEN
IF FIELDTYPE(FieldRefPtr) IN (0x01000000 , 0x03000000) THEN
SET FieldRefPtr.(XMLNSC.NamespaceDecl)xmlns:lfob= 'http://www.lfob.com/namespace';
SET FieldRefPtr NAMESPACE = lfob; |
|
Back to top |
|
 |
kimbert |
Posted: Thu May 22, 2008 12:49 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
How do I get the name space of lfob for all the elements |
I said:
Quote: |
you need to explicitly set the namespace on each and every node. That means walking the tree recursively. |
I also provided a link to a code snippet showing how to recursively walk a tree and set namespaces. |
|
Back to top |
|
 |
wmb61_user |
Posted: Thu May 22, 2008 12:52 pm Post subject: |
|
|
Novice
Joined: 08 May 2008 Posts: 18
|
|
Back to top |
|
 |
wmb61_user |
Posted: Thu May 22, 2008 1:07 pm Post subject: |
|
|
Novice
Joined: 08 May 2008 Posts: 18
|
I am almost there. Can some one tell me how to add teh xmlns:xsi and
xsi:schemaLocation to the namespace declaration.
Thanks |
|
Back to top |
|
 |
kimbert |
Posted: Thu May 22, 2008 1:53 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
xmlns:xsi is just another namespace declaration. So you use XMLNSC.NamespaceDecl as before.
xsi:schemaLocation is an attribute in the xsi namespace. So you have to
- create the field using XMLNSC.Attribute
- set its namespace to the xsi namespace ( not 'xsi' ) |
|
Back to top |
|
 |
|