Author |
Message
|
satya2481 |
Posted: Mon Jan 05, 2009 8:30 am Post subject: |
|
|
Disciple
Joined: 26 Apr 2007 Posts: 170 Location: Bengaluru
|
Hi
Quote: |
Did you think that XMLNS would be easier? ( it will not ). Was there another reason? |
The main reason why I am trying to use XMLNS domain is that I will be able to create the root element without any namespace prefix, seondly I will be able to create the XML header (I mean XML version, encoding etc).
I thought of using XMLNSC as it validates the constrcucted message against the message set. but here also I will not be able to create the root element of my message without any namespace prefix. Because as I understand when we say OutputRoot.XMLNS it refers to the output message including the root tag, hence I will not get a chance to alter the root element.
I want to create the ouput message something like
Code: |
<?xml version="1.0" encoding="UTF-8"?>
<SyncPurchaseOrder xmlns="default namespace no prefix" xmlns:oa="oagis namespace" xmlns:xsi="xml schema">
<oa:PurchaseOrder>
Elements----------
</oa:PurchaseOrder>
</SyncPurchaseOrder>
|
Quote: |
Why not simply take a User Trace? Just as easy, and provides more info. Or simply look at the system error log or Windows Event Viewer, depending on your development platform. |
Yes, you are right I could have used these other options, but I used to the RCD node and debugging options....
Quote: |
child elements do not 'inherit' the default namespace ( or any other namespace ) from their parents. |
Does this means it is not possible to define a default namespace in the root element and then create its child elements withoout namespace so that the parser will consider these elements under the default namespace? I dont think this is correct....
Thanks
Satya _________________ IBM Certified Solution Developer WebSphere Message Broker V6.0
IBM Certified System Administrator WebSphere MQ V6.0 |
|
Back to top |
|
 |
kimbert |
Posted: Mon Jan 05, 2009 3:42 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
The main reason why I am trying to use XMLNS domain is that I will be able to create the root element without any namespace prefix, seondly I will be able to create the XML header (I mean XML version, encoding etc). |
You are getting confused between MRM and XMLNSC. A message tree built for the MRM domain does not have a node representing the root tag. But a message tree built for the XMLNSC domain does.
FYI, XMLNSC is very similar to XMLNS in the way that it works. It simply has more features, and is the 'strategic' choice.
Quote: |
Does this means it is not possible to define a default namespace in the root element and then create its child elements withoout namespace so that the parser will consider these elements under the default namespace? I dont think this is correct.... |
I know that many users get confused about this, and I do agree that it is difficult to understand at first. However, it is correct, and it is consistent. Every node has an explicit namespace ( which may be empty, of course ). That rule applies whether or not you have placed a namespace declaration on one of its ancestor elements. Imagine the confusion if adding a default namespace to element 'parent' caused the namespace of element 'child' to change. ESQL/Java/Mapping node field references might suddenly stop working for no apparent reason. |
|
Back to top |
|
 |
satya2481 |
Posted: Mon Jan 05, 2009 7:57 pm Post subject: |
|
|
Disciple
Joined: 26 Apr 2007 Posts: 170 Location: Bengaluru
|
Hi,
Does this mean it is not possible to create a message with default namespace from Broker. How to meet customer requirements...even though I can understand that processing of the message will not change either by adding the default namespace or by adding a specific namspace prefix.
I can see that in ESQL we can create the default namespace, how to implement the same thing in Java? is this not supported in JCN? or any of the IBM Mb API?
Thank You
Satya _________________ IBM Certified Solution Developer WebSphere Message Broker V6.0
IBM Certified System Administrator WebSphere MQ V6.0 |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Jan 05, 2009 8:01 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
You have to realize that creating a message with a default namespace and not having to prefix each node with the namespace in the tree are 2 different things.  _________________ MQ & Broker admin |
|
Back to top |
|
 |
satya2481 |
Posted: Mon Jan 05, 2009 8:56 pm Post subject: |
|
|
Disciple
Joined: 26 Apr 2007 Posts: 170 Location: Bengaluru
|
Quote: |
You have to realize that creating a message with a default namespace and not having to prefix each node with the namespace in the tree are 2 different things |
Hi fjb_saper,
Could you please provide some more detailed explanation on the point you havev mentioned...
Thank You
Satya |
|
Back to top |
|
 |
kimbert |
Posted: Tue Jan 06, 2009 1:33 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Jan 06, 2009 2:06 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
See Kimbert's post (just above this one). Especially the last line of it.  _________________ MQ & Broker admin |
|
Back to top |
|
 |
satya2481 |
Posted: Tue Jan 06, 2009 3:59 am Post subject: |
|
|
Disciple
Joined: 26 Apr 2007 Posts: 170 Location: Bengaluru
|
Hi saper and kimbert,
I have checked your reply and the provided link...
I would like to know how to set the default namespace in JCN node using java coding not using ESQL...  |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Jan 06, 2009 5:58 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
The "default" namespace is just another namespace declaration, without a prefix.
Every element in a MB message tree must have a namespace specifically assigned to it.
So create a namespace declaration that doesn't have a prefix, and then attach that namespace to every element under that declaration.
 |
|
Back to top |
|
 |
kimbert |
Posted: Tue Jan 06, 2009 6:54 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
I agree that this is not simple to do in Java. Here's the code to produce the output which you posted earlier in this thread:
Code: |
MbElement messageRoot = outMessage.getRootElement();
MbElement outRoot = messageRoot.createElementAsLastChild("XMLNSC");
//Create the XML declaration. No need to give it a name.
MbElement xmlDecl = outRoot.createElementAsFirstChild(MbXMLNSC.XML_DECLARATION);
//Note the leading caps on the names of these attributes.
xmlDecl.createElementAsFirstChild(MbXMLNSC.ATTRIBUTE, "Version", "1.0");
xmlDecl.createElementAsFirstChild(MbXMLNSC.ATTRIBUTE, "Encoding", "utf-8");
xmlDecl.createElementAsFirstChild(MbXMLNSC.ATTRIBUTE, "Standalone", "yes");
//Declare these because we need to use them in two places.
String oagisNamespace = "http://www.openapplications.org/oagis/9";
String volvoNamespace = "http://www.volvo.com/3P/Purchasing/2008/10";
//Declare this because we need it for the xmlns attribute.
String xmlnsNamespace = "http://www.w3.org/2000/xmlns/";
MbElement spo = outRoot.createElementAsLastChild(MbXMLNSC.FOLDER, "SyncPurchaseOrder", null);
//Next line is very important. The tag 'SyncPurchaseOrder' is in the volvo namespace, because the default namespace
//declaration applies to its parent element.
//If this line is omitted, you will get BIP5014.
spo.setNamespace(volvoNamespace);
MbElement nsDecl = spo.createElementAsLastChild(MbXMLNSC.NAMESPACE_DECLARATION, "oa", oagisNamespace);
nsDecl.setNamespace(xmlnsNamespace); //The xmlns attribute must be in the correct namespace.
//nsDecl.setNamespace("xmlns"); This also works, and might be simpler for some users.
nsDecl = spo.createElementAsLastChild(MbXMLNSC.NAMESPACE_DECLARATION, "xmlns", volvoNamespace);
//nsDecl.setNamespace("xmlns") Not required. The namespace of a default namespace decl must be ""
MbElement aa = spo.createElementAsLastChild(MbXMLNSC.FOLDER,"ApplicationArea",null);
aa.setNamespace(oagisNamespace);
MbElement cdt = aa.createElementAsLastChild(MbXMLNSC.FIELD, "CreationDateTime", "2008-12-31");
cdt.setNamespace(oagisNamespace);
MbElement da = spo.createElementAsLastChild(MbXMLNSC.FOLDER, "DataArea", null);
da.setNamespace(volvoNamespace);
|
I get this output ( line breaks and indentation added for clarity):
Code: |
<?xml version="1.0" encoding="utf-8"?>
<SyncPurchaseOrder xmlns:oa="http://www.openapplications.org/oagis/9" xmlns="http://www.volvo.com/3P/Purchasing/2008/10">
<oa:ApplicationArea>
<oa:CreationDateTime>2008-12-31</oa:CreationDateTime>
</oa:ApplicationArea>
<DataArea/>
</SyncPurchaseOrder> |
|
|
Back to top |
|
 |
satya2481 |
Posted: Tue Jan 06, 2009 9:05 am Post subject: |
|
|
Disciple
Joined: 26 Apr 2007 Posts: 170 Location: Bengaluru
|
Hi Kimbert,
Thank you very much for the code. The default namespace is been created now. But again some issue.
When I use XMLNSC domain and used the code below the element NAMESPACE_DECLARATION is not getting resolved in my toolkit for MbXMLNSC
Code: |
MbElement nsDecl = spo.createElementAsLastChild(MbXMLNSC.NAMESPACE_DECLARATION, "oa", oagisNamespace); |
The toolkit reports an error "MbXMLNSC.NAMESPACE_DECLARATION canot be resolved" but other fields of MbXMLNSC like FOLDER and ATTRIBUTE are coming correct.
I tried to rebuild the project, close and open the project. close and open the java file etc...
I am at toolkit
Version: 6.1.0
Build id: 6.1.0.2.ifix003-20081014_1021
I hope this issue is not related to the toolkit, Do you have any idea on this new issue?
When I received this error I tried to create the same in XMLNS domain instead of XMLNSC. I am getting an ouput somethinf like this
Code: |
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<SyncPurchaseOrder xmlns:oa="http://www.openapplications.org/oagis/9" xmlns="http://www.volvo.com/3P/Purchasing/2008/10">
<NS1:ApplicationArea xmlns:NS1="http://www.openapplications.org/oagis/9">
<NS1:CreationDateTime>2008-12-31</NS1:CreationDateTime>
</NS1:ApplicationArea>
</SyncPurchaseOrder> |
NS1 is getting created.. My code looks like this
Code: |
//Note the leading caps on the names of these attributes.
xmlDecl.createElementAsFirstChild(MbXMLNS.VERSION, "Version", "1.0");
xmlDecl.createElementAsFirstChild(MbXMLNS.ENCODING, "Encoding", "utf-8");
xmlDecl.createElementAsFirstChild(MbXMLNS.STANDALONE, "Standalone", "yes");
//Declare these because we need to use them in two places.
String oagisNamespace = "http://www.openapplications.org/oagis/9";
String volvoNamespace = "http://www.volvo.com/3P/Purchasing/2008/10";
//Declare this because we need it for the xmlns attribute.
String xmlnsNamespace = "http://www.w3.org/2000/xmlns/";
MbElement spo = outRoot.createElementAsLastChild(MbXMLNS.ELEMENT, "SyncPurchaseOrder", null);
//Next line is very important. The tag 'SyncPurchaseOrder' is in the volvo namespace, because the default namespace
//declaration applies to its parent element.
//If this line is omitted, you will get BIP5014.
spo.setNamespace(volvoNamespace);
MbElement nsDecl = spo.createElementAsLastChild(MbXMLNS.NAMESPACE_DECL, "oa", oagisNamespace);
nsDecl.setNamespace(xmlnsNamespace); //The xmlns attribute must be in the correct namespace.
//nsDecl.setNamespace("xmlns"); This also works, and might be simpler for some users.
nsDecl = spo.createElementAsLastChild(MbXMLNS.NAMESPACE_DECL, "xmlns", volvoNamespace);
//nsDecl.setNamespace("xmlns") Not required. The namespace of a default namespace decl must be ""
MbElement aa = spo.createElementAsLastChild(MbXMLNS.ELEMENT,"ApplicationArea",null);
aa.setNamespace(oagisNamespace);
MbElement cdt = aa.createElementAsLastChild(MbXMLNS.ELEMENT, "CreationDateTime", "2008-12-31");
cdt.setNamespace(oagisNamespace); |
What is the equivalent field to be accesed for the MbXMLNSC.FOLDER and FIELD values in MbXMLNS domain?
I have checked some information here in IBM site http://publib.boulder.ibm.com/infocenter/wmbhelp/v6r1m0/index.jsp?topic=/com.ibm.etools.mft.doc/ad70530_.htm
but didnt get any help...
Once againg thanks for the solution...
Satya _________________ IBM Certified Solution Developer WebSphere Message Broker V6.0
IBM Certified System Administrator WebSphere MQ V6.0 |
|
Back to top |
|
 |
mgk |
Posted: Tue Jan 06, 2009 10:09 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Hi.
I believe that MbXMLNSC.NAMESPACE_DECLARATION constant was only introduced in 6.1.0.3 (with iFix 1). You can try to use the numeric value of MbXMLNSC.NAMESPACE_DECLARATION instead on an earlier level which is 0x03000102.
So your code would be:
Code: |
MbElement nsDecl = spo.createElementAsLastChild(0x03000102, "oa", oagisNamespace); |
Regards, _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Jan 06, 2009 10:36 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
There may be a MbXMLNSC.SINGLENAMESPACEDECL constant that has the same numeric value as well. |
|
Back to top |
|
 |
kimbert |
Posted: Tue Jan 06, 2009 4:32 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Hi satya2481,
mgk's suggestion is correct. If you want to keep your code neat and tidy, you can define yourself an integer with the correct value. e.g.
Code: |
int MbXMLNSC_NAMESPACE_DECL = 0x03000102;
MbElement nsDecl = spo.createElementAsLastChild(MbXMLNSC_NAMESPACE_DECL, "oa", oagisNamespace);
|
If you do it this way, it will be very simple to update the code when you upgrade to v6.1.0.3.
Please don't go back to XMLNS - there is no good reason to do that, and it would require several changes in my Java code to make it work. |
|
Back to top |
|
 |
satya2481 |
Posted: Tue Jan 06, 2009 8:19 pm Post subject: |
|
|
Disciple
Joined: 26 Apr 2007 Posts: 170 Location: Bengaluru
|
Hi All,
Thank you very much once again.
Now I am getting the output like
Code: |
<?xml version="1.0" encoding="utf-8"?>
<SyncPurchaseOrder xmlns:oa="http://www.openapplications.org/oagis/9" xmlns="http://www.volvo.com/3P/Purchasing/2008/10">
<oa:ApplicationArea>
<oa:CreationDateTime>2008-12-31</oa:CreationDateTime>
</oa:ApplicationArea>
<DataArea/>
</SyncPurchaseOrder> |
I have used the integer value for MbXMLNC.NAMESPACE_DECLARATION as suggested by kimbert and mgk.
Code: |
int MbXMLNSC_NAMESPACE_DECL = 0x03000102;
MbElement nsDecl = spo.createElementAsLastChild(MbXMLNSC_NAMESPACE_DECL, "oa", oagisNamespace); |
I think I can work on this now to craeate my entire output message.
A small doubt how to know the integer constant values for the fields of MbXMLNSC or MbXMLNS? I mean how did you found the value of MbXMLNC.NAMESPACE_DECLARATION field?
Thank You
Satya |
|
Back to top |
|
 |
|