[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",
> "
>
http://www.hirbc.com/xml/Screening/BackgroundCheck-2_0
>
http://www.hirbc.com/xml/Screening/Screenings-2_0/Schemas/BackgroundCheck-2_0.xsd
> ");
>
> root.addNamespaceDeclaration(schemaloc);
But for what it's worth, will output another namespace
declaration, like:
'xmlns:schemaLocation="http://..."'.
That is, following is exactly as expected:
> *xmlns:*schemaLocation="
>
http://www.hirbc.com/xml/Screening/BackgroundCheck-2_0
>
>
http://www.hirbc.com/xml/Screening/Screenings-2_0/Schemas/BackgroundCheck-2_0.xsd"
> 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://...",
xsi);
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
namespace.
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
scope.
Hope this helps,
-+ Tatu +-
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
More information about the jdom-interest
mailing list