[jdom-interest] create namespace

Tatu Saloranta cowtowncoder at yahoo.com
Sat Nov 12 10:04:19 PST 2005

--- Ashar Siddiqui <siddiqui.ashar at gmail.com> wrote:

> Here is my code.
> xsi= Namespace.getNamespace("xsi", "
> http://www.w3.org/2001/XMLSchema-instance" );
> root.addNamespaceDeclaration(xsi);

This would cause 'xmlns:xsi="http:/...."' to be added
to the element.

But this one does not make sense:

> schemaloc = Namespace.getNamespace("schemaLocation",
> "
> ");
> root.addNamespaceDeclaration(schemaloc);

But for what it's worth, will output another namespace
declaration, like:


That is, following is exactly as expected:

> *xmlns:*schemaLocation="
> userId="900JHY"password="WF040503" account="900JHY">
> <BackgroundSearchPackage *xmlns="*">\u2026
> how to fix it special I want xsi:schemaLocation not
> xmlns:schemaLocation,

Then just use the first namespace that you declared to
add the attribute to
define schema location to use:

root.setAttribute("schemaLocation", "http://...",

As to having "xmlns=''" in second element, since you
did not show how the element is created, I can not say
for sure, but I would guess that you are creating it
in the default (empty) namespace; in which case it has
redefine the current default namespace to be empty
If this is not what you want, you have to pass in
namespace definition in element constructor: it should
still use parent's declaration if and when it's in
Hope this helps,

-+ Tatu +-

Yahoo! Mail - PC Magazine Editors' Choice 2005 

More information about the jdom-interest mailing list