Index Changes
This is version 3. It is not the current version, and thus it cannot be edited.
[Back to current version]   [Restore this version]

Document.createElement() or Document.createElementNS()

The discussion is about the use of Document.createElement() or Document.createElementNS().

Some components use DOMSource as the "content" of a MessageExchange that they send to other components. The DOMSource may be created using the org.w3c.dom classes, for example using the Document class. My understanding is that the Document created should be namespace aware. So you would set the DocumentBuilderFactory that is used to create the document as namespace aware.

Now the question is whether to use createElement or createElementNS. Please see the attached test program (TestElementCreation.java and product.xsd). It uses both Document.createElement() and Document.createElementNS() to create the Document and validate it. The one created using Document.createElement() is invalid.

The example uses a Schema with elementFormDefault as "unqualified". That is why the child elements are created by passing in null as the namespaceURI value. If the value is "qualified", you would use createElementNS with the proper namespaceURI and/or qualified name.

Implemeting this correctly is important for the components to be able to work with one another.

JSPWiki v2.4.100
[RSS]
« Home Index Changes Prefs
This particular version was published on 18-Apr-07 18:17 PM, -0700 by Prashant Bhagat