You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by "Ali, Haneef" <ha...@hp.com> on 2005/09/22 23:13:26 UTC

Dom serialization

Hi,

I have  couple of doubts in dom?

Consider the following code?
	a) Element env = Document.createElementNS("soapnamespace",
"soap:Envelope");	
	b) env.setAttribute("xmls:soap", 'soapnamespace");

A) Do we really needs to make the call "setAttribute(...)
B) If  we don't make that call then serialization with
org.apache.xml.serialize.XMLSerializer and JAXP Transformer doesn't add
the namespace attribute

C) If we add that setAttribute call, then  DOM3 ( DOMLSImplementaion)
DOMSerializer adds  two xmlns attributes.
	(ie) <soap:Enveope  xmlns:soap="soapEnvelope"
xmlns:soap="soapEnvelope' />

D) Assume if we go with DOM3 serialization and don't do
setAttribute(...), then how will you append a textNode which is a qName.
	(ie)   Element env = Document.createElementNS("wsrfnamepace",
"wsrf:GetResourceProperty");	
		 Qname myQName = new Qname("myNamespace", "myElement");
		 How to append the qName?

		I need the result as
			<wsrf:GetResourceProperty  
				xmlns:wsrf="wsrfnamespace",
xmlns:ns1="myNamespace">
				ns1:myElement
			</wsrf:GetResourceProperty>

	In this case, do we need to call setAttribute(..)

Regards,				  	
Haneef

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: Dom serialization

Posted by Stanimir Stamenkov <st...@myrealbox.com>.
/Ali, Haneef/:

> Consider the following code?
> 	a) Element env = Document.createElementNS("soapnamespace", 
> "soap:Envelope");
> 	b) env.setAttribute("xmls:soap", 'soapnamespace");
> 
> A) Do we really needs to make the call "setAttribute(...)
> B) If  we don't make that call then serialization with 
> org.apache.xml.serialize.XMLSerializer and JAXP Transformer doesn't add 
> the namespace attribute

DOM 2 has different namespace considerations [1] than DOM 3 and 
leave the maintenance of the namespace declaration attributes to the 
user application. DOM 3 LS however specifies 
<http://www.w3.org/TR/DOM-Level-3-LS/load-save.html#LS-LSSerializer>:

> Namespaces are fixed up during serialization, the serialization 
> process will verify that namespace declarations, namespace prefixes 
> and the namespace URI associated with elements and attributes are 
> consistent. If inconsistencies are found, the serialized form of the 
> document will be altered to remove them. The method used for doing 
> the namespace fixup while serializing a document is the algorithm 
> defined in Appendix B.1, "Namespace normalization" [2], of [DOM 
> Level 3 Core].

/Ali, Haneef/:

> C) If we add that setAttribute call, then  DOM3 ( DOMLSImplementaion) 
> DOMSerializer adds  two xmlns attributes.
> 	(ie) <soap:Enveope  xmlns:soap="soapEnvelope" 
> xmlns:soap="soapEnvelope' />

So, given the above it could be an error on the serializer part but 
I'm not really sure if the correct behavior is guaranteed only when 
serializing DOM 3 created nodes.

> D) Assume if we go with DOM3 serialization and don't do
> setAttribute(...), then how will you append a textNode which is a qName.
> 	(ie)   Element env = Document.createElementNS("wsrfnamepace",
> "wsrf:GetResourceProperty");	
> 		 Qname myQName = new Qname("myNamespace", "myElement");
> 		 How to append the qName?

Whatever serialization you go with text nodes are just character 
data. You add the text you wish in the normal way:

Document doc;
...
env.appendNode(doc
     .createTextNode("myNamespace" + ":" + "myElement");

or using the DOM 3 interfaces:

env.setTextContent("myNamespace" + ":" + "myElement");


[1] 
http://www.w3.org/TR/DOM-Level-2-Core/core.html#Namespaces-Considerations

[2] 
http://www.w3.org/TR/DOM-Level-3-Core/namespaces-algorithms.html#normalizeDocumentAlgo

-- 
Stanimir

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: Dom serialization

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
"Ali, Haneef" <ha...@hp.com> wrote on 09/22/2005 05:13:26 PM:

> Hi,
> 
> I have  couple of doubts in dom?
> 
> Consider the following code?
>    a) Element env = Document.createElementNS("soapnamespace",
> "soap:Envelope"); 
>    b) env.setAttribute("xmls:soap", 'soapnamespace");
        ^^^^^^^^^^^^^^^^
        This might be your problem.

Element.setAttribute() creates a non-namespace-aware node. You should 
never use the DOM Level 1 methods with a DOM containing namespace-aware 
nodes. Note that setAttribute() is not equivalent to calling 
setAttributeNS() with a null namespace URI and that you must specify 
"http://www.w3.org/2000/xmlns/" as the namespace when creating xmlns 
attributes using setAttributeNS().

<snip/>

> 
> Regards, 
> Haneef
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
> 

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org