| Author | Message | 
		
		  | mangoMan | 
			  
				|  Posted: Wed Apr 04, 2007 1:07 pm    Post subject: Adding XML Declaration and Namespaces |   |  | 
		
		  | Acolyte
 
 
 Joined: 16 Oct 2003Posts: 69
 
 
 | 
			  
				| The XML message I create in the JCN does not have a declaration nor any namespaces.  How can I add them so it looks like this: 
 
 
   
	| Quote: |  
	| <?xml version="1.0" encoding="UTF-8"?> <Request xmlns="urn:AFS:PCS:xml:specification:schema:2.0.0_Phase_8.0" xmlns:ac="urn:AFS:PCS:xml:specification:schema:2.0.0_Phase_8.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:AFS:PCS:xml:specification:schema:2.0.0_Phase_8.0
 C:\Projects\AFS\AFS.xsd">Req</Request>
 |  
 currently it looks like this:
 
 
 
   
	| Quote: |  
	| <Request>Req</Request> |  
 
 Here is where I create the root element:
 
 
 
 
 
   
	| Code: |  
	| outMessage.getRootElement().createElementAsLastChild(MbXMLNSC.PARSER_NAME); MbElement outRoot = outMessage.getRootElement();
 MbElement outBody = outRoot.getLastChild();
 |  |  | 
		
		  | Back to top |  | 
		
		  |  | 
		
		  | jefflowrey | 
			  
				|  Posted: Wed Apr 04, 2007 1:15 pm    Post subject: |   |  | 
		
		  | Grand Poobah
 
 
 Joined: 16 Oct 2002Posts: 19981
 
 
 |  | 
		
		  | Back to top |  | 
		
		  |  | 
		
		  | mangoMan | 
			  
				|  Posted: Wed Apr 04, 2007 1:36 pm    Post subject: |   |  | 
		
		  | Acolyte
 
 
 Joined: 16 Oct 2003Posts: 69
 
 
 | 
			  
				| Thanks Jeff. 
 I have been able to add the XML_DECLARATION as follows:
 
 
 
   
	| Code: |  
	| //
 // Add XML_DECLARATION
 //
 MbElement xmlDecl = outBody.createElementAsFirstChild(MbXMLNSC.XML_DECLARATION);
 xmlDecl.setName("XmlDeclaration");
 MbElement version = xmlDecl.createElementAsFirstChild(MbXMLNSC.ATTRIBUTE, "Version", "1.0");
 MbElement encoding = xmlDecl.createElementAsFirstChild(MbXMLNSC.ATTRIBUTE, "Encoding", "utf-8");
 |  
 BUT HOW DO I CREATE THE xmlns, xmlns:xsi, xmlns:ac and the xsi:schemaLocation attributes?  The is nothing in there that can help me unless the frustration from the lack of time to solve this puzzle is blinding my acute intellect.
 |  | 
		
		  | Back to top |  | 
		
		  |  | 
		
		  | jefflowrey | 
			  
				|  Posted: Wed Apr 04, 2007 1:47 pm    Post subject: |   |  | 
		
		  | Grand Poobah
 
 
 Joined: 16 Oct 2002Posts: 19981
 
 
 | 
			  
				| You can add the default  xmlns with setNamespace. 
 The rest you might need to use Broker XPath.
 
 Or you might just be able to treat them as attributes.
 _________________
 I am *not* the model of the modern major general.
 |  | 
		
		  | Back to top |  | 
		
		  |  | 
		
		  | mangoMan | 
			  
				|  Posted: Wed Apr 04, 2007 3:31 pm    Post subject: |   |  | 
		
		  | Acolyte
 
 
 Joined: 16 Oct 2003Posts: 69
 
 
 | 
			  
				| Thank you. 
 May you live long and prosper.
 |  | 
		
		  | Back to top |  | 
		
		  |  | 
		
		  | mangoMan | 
			  
				|  Posted: Thu Apr 05, 2007 1:56 pm    Post subject: |   |  | 
		
		  | Acolyte
 
 
 Joined: 16 Oct 2003Posts: 69
 
 
 | 
			  
				| Oh, just one thing... 
 when I use the setNamespace() method, it creates a NS1: qualifier for the root tag and the namespace is in the root tag is defined as xmlns:NS1="default.namespace" I just want this xmlns="default.namespace"
 
 I don't need no stinkin NS1 qualifier attached to my XML.  Can I prevent that from happening?
 |  | 
		
		  | Back to top |  | 
		
		  |  | 
		
		  | fjb_saper | 
			  
				|  Posted: Thu Apr 05, 2007 2:04 pm    Post subject: |   |  | 
		
		  |  Grand High Poobah
 
 
 Joined: 18 Nov 2003Posts: 20767
 Location: LI,NY
 
 | 
			  
				| 
   
	| mangoMan wrote: |  
	| Oh, just one thing... 
 when I use the setNamespace() method, it creates a NS1: qualifier for the root tag and the namespace is in the root tag is defined as xmlns:NS1="default.namespace" I just want this xmlns="default.namespace"
 
 I don't need no stinkin NS1 qualifier attached to my XML.  Can I prevent that from happening?
 |  Sure, but why would you want to? Other parser recognize this correctly, so where is the problem??
 _________________
 MQ & Broker admin
 |  | 
		
		  | Back to top |  | 
		
		  |  | 
		
		  | mangoMan | 
			  
				|  Posted: Thu Apr 05, 2007 2:49 pm    Post subject: |   |  | 
		
		  | Acolyte
 
 
 Joined: 16 Oct 2003Posts: 69
 
 
 | 
			  
				| I know what you mean but they want what they want.....what can I do.  There must be a way to accomplish what I want. |  | 
		
		  | Back to top |  | 
		
		  |  | 
		
		  | fjb_saper | 
			  
				|  Posted: Thu Apr 05, 2007 5:15 pm    Post subject: |   |  | 
		
		  |  Grand High Poobah
 
 
 Joined: 18 Nov 2003Posts: 20767
 Location: LI,NY
 
 | 
			  
				| 
   
	| mangoMan wrote: |  
	| I know what you mean but they want what they want.....what can I do.  There must be a way to accomplish what I want. |  
 They won't care as long as you can demonstrate that it works reliably...
 Remember the best expert is the one that gets the job done.
 
 My advice: learn what parser they use and if it is capable of handling the prefix, don't bother... just run a field demo... If it works nobody will care how as long as it works reliably... and you can truthfully say ... well we used standard xml...
 _________________
 MQ & Broker admin
 |  | 
		
		  | Back to top |  | 
		
		  |  | 
		
		  | jefflowrey | 
			  
				|  Posted: Thu Apr 05, 2007 5:56 pm    Post subject: |   |  | 
		
		  | Grand Poobah
 
 
 Joined: 16 Oct 2002Posts: 19981
 
 
 | 
			  
				| Plus, remember, XML is only supposed to be machine readable.  It's nice if it's also human readable, but in most cases not worth a lot of trouble. _________________
 I am *not* the model of the modern major general.
 |  | 
		
		  | Back to top |  | 
		
		  |  | 
		
		  | kimbert | 
			  
				|  Posted: Fri Apr 06, 2007 12:38 pm    Post subject: |   |  | 
		
		  |  Jedi Council
 
 
 Joined: 29 Jul 2003Posts: 5543
 Location: Southampton
 
 | 
			  
				| 
  There is. Just create an XML declaration in the message tree at the appropriate place. There are examples of how to do this using ESQL, you just need to find out how to do it using Java. 
	| Quote: |  
	| There must be a way to accomplish what I want. |  |  | 
		
		  | Back to top |  | 
		
		  |  | 
		
		  | hs | 
			  
				|  Posted: Thu May 31, 2007 5:49 am    Post subject: |   |  | 
		
		  |  Novice
 
 
 Joined: 03 Jun 2005Posts: 17
 
 
 | 
			  
				| How can you achieve this if you are not using the jcn ? 
 I have the following xml:
 
 
 
   
	| Code: |  
	| <a>
 <b>1234567890</b>
 </a>
 
 |  
 I would like to do the following:
 
 
 
   
	| Code: |  
	| <ce:a xmlns:ce="http://www.origostandards.com/schema/ce/v2">
 <ce:b>1234567890</ce:b>
 <ce:a>
 
 |  
 Any suggestions ?
 _________________
 IBM Certified System Administrator - WebSphere MQ V5.3
 |  | 
		
		  | Back to top |  | 
		
		  |  | 
		
		  | kimbert | 
			  
				|  Posted: Thu May 31, 2007 5:56 am    Post subject: |   |  | 
		
		  |  Jedi Council
 
 
 Joined: 29 Jul 2003Posts: 5543
 Location: Southampton
 
 | 
			  
				| - Decide which domain your message tree will use ( either XMLNS or XMLNSC ). - Search the docs for examples of how to put an XML Declaration into the message tree. I assure you that such examples do exist.
 |  | 
		
		  | Back to top |  | 
		
		  |  | 
		
		  | jefflowrey | 
			  
				|  Posted: Thu May 31, 2007 6:03 am    Post subject: |   |  | 
		
		  | Grand Poobah
 
 
 Joined: 16 Oct 2002Posts: 19981
 
 
 | 
			  
				| That's really just setting the namespace of a particular element. 
 You need to a) use an XML domain that supports a namespace, b) configure that element in that domain to have the given namespace.
 
 In the case of the MRM-XML domain, this is done in the model.
 
 In the case of XMLNS and XMLNSC, this is done in code.
 _________________
 I am *not* the model of the modern major general.
 |  | 
		
		  | Back to top |  | 
		
		  |  | 
		
		  |  |