[jdom-interest] Namespace inheritance after cloning
Alistair Young
alistair at smo.uhi.ac.uk
Sun Nov 28 07:01:17 PST 2004
The inheritance problem I get is:
If I clone:
<?xml version="1.0" encoding="UTF-8"?>
<Assertion xmlns="urn:oasis:names:tc:SAML:1.0:assertion"
AssertionID="Assertion-id" MajorVersion="1" MinorVersion="1"
Issuer="guanxi.uhi.ac.uk" IssueInstant="2004-10-01T14:24:59Z">
<AuthenticationStatement AuthenticationInstant="2004-10-01T14:24:59Z"
AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:password">
<Subject>
<NameIdentifier Format="urn:mace:shibboleth:1.0:nameIdentifier"
NameQualifier="https://idp.example.org/shibboleth/">OFFLINE</NameIdentifier>
<SubjectConfirmation>
<ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer</ConfirmationMethod>
</SubjectConfirmation>
</Subject>
</AuthenticationStatement>
</Assertion>
and add it to:
<?xml version="1.0" encoding="UTF-8"?>
<Response xmlns="urn:oasis:names:tc:SAML:1.0:protocol"
xmlns:samlp="urn:oasis:names:tc:SAML:1.0:protocol"
IssueInstant="2004-10-01T14:24:59Z" MajorVersion="1" MinorVersion="1"
Recipient="http://localhost/Shibboleth.shire" ResponseID="Response-id">
<Assertion xmlns="urn:oasis:names:tc:SAML:1.0:assertion"
AssertionID="Assertion-id" IssueInstant="2004-10-01T14:24:59Z"
Issuer="guanxi.uhi.ac.uk" MajorVersion="1" MinorVersion="1">
I get:
<?xml version="1.0" encoding="UTF-8"?>
<Response xmlns="urn:oasis:names:tc:SAML:1.0:protocol"
xmlns:samlp="urn:oasis:names:tc:SAML:1.0:protocol"
IssueInstant="2004-10-01T14:24:59Z" MajorVersion="1" MinorVersion="1"
Recipient="http://localhost/Shibboleth.shire" ResponseID="Response-id">
<Assertion xmlns="urn:oasis:names:tc:SAML:1.0:assertion"
AssertionID="Assertion-id" IssueInstant="2004-10-01T14:24:59Z"
Issuer="guanxi.uhi.ac.uk" MajorVersion="1" MinorVersion="1">
<AuthenticationStatement xmlns=""
AuthenticationInstant="2004-10-01T14:24:59Z"
AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:password">
<Subject>
<NameIdentifier Format="urn:mace:shibboleth:1.0:nameIdentifier"
NameQualifier="https://idp.example.org/shibboleth/">OFFLINE</NameIdentifier>
<SubjectConfirmation>
<ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer</ConfirmationMethod>
</SubjectConfirmation>
</Subject>
</AuthenticationStatement>
</Assertion>
</Response>
AuthenticationStatement has suddenly grown a new xmlns="", overriding it's
default namespace. All the Assertion children have the same namespace set
when creating the elements. It seems that when I clone the Assertion and
add it to the root element, I lose the namespace on
AuthenticationStatement.
any advice appreciated.
thanks,
Alistair
--
Alistair Young
Senior Software Engineer
UHI at Sabhal Mòr Ostaig
Isle of Skye
Scotland
> Alistair Young wrote:
>
>> I have a strange problem. I've read the archives and the FAQ and
>> understand the non inheritance of prefix:local style namespaces.
>> However,
>> when I do:
>>
>> Document root =
>> <root xmlns="http://test.ns">
>> </root>
>>
>> Document next =
>> <next>some text</next>
>>
>> root.getRootElement().addContent((Content)next.getRootElement().clone());
>>
>> I get:
>> <root xmlns="http://test.ns">
>> <next xmlns="">some text</next>
>> </root>
>>
>> and it breaks the XML schema validation! <next> should obviously be in
>> the
>> test.ns namespace. JDOM seems to want to put it in an empty namespace.
>
> The <next> you created is in no namespace. When you move it to another
> document, the element doesn't change namespaces. Namespaces are an
> intrinsic part of each Element and don't depend on placement. So on
> output JDOM has to make sure that the default namespace on <root>
> doesn't mistakenly apply to <next> so it writes xmlns="" which reassigns
> the default namespace for that context to no namespace. JDOM's
> correctly serializing the XML data model as you created it.
>
>> Now, the weird thing is, if I create <next> with the same namespace as
>> <root>, JDOM still replaces it with xmlns="".
>
> That's not something JDOM would do. I suspect your code isn't actually
> doing what you describe here. :) If you can't figure it out, send in a
> simple code sample showing the issue and we'll see if it's any real bug.
>
>> If <root> doesn't have a namespace, then the xmlns="" isn't added to
>> <next>.
>> Nowhere in the code is xmlns="" generated when creating the <next>
>> Element.
>
> Right, because there's no need to redefine the default namespace when
> there's no default namespace in effect.
>
> -jh-
>
>
More information about the jdom-interest
mailing list