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 "Jesus M. Salvo Jr." <je...@migasia.com> on 2003/02/04 08:25:52 UTC

Namespace with no prefix - how?


How do you create a element with a namespace without any prefix, 
something like this (?):

<Response xmlns="http://mynamespace.org">
    <Status>100</Status>
</Response>

With the following code:

    Element responseElement = doc.createElementNS( 
"http://mynamespace.org", "Response" );

or

    Element responseElement = doc.createElementNS( 
"http://mynamespace.org", "Response" );
    responseElement.setPrefix( "" );

or

    Element responseElement = doc.createElementNS( 
"http://mynamespace.org", "Response" );
    responseElement.setPrefix( null );

the output is

<Response>
    <Status>100</Status>
</Response>
  
The only way I can write out the namespace is via:

    Element responseElement = doc.createElementNS( 
"http://mynamespace.org", "Response" );
    responseElement.setPrefix( "myprefix" );

.. which output like this:

<myprefix:Response xmlns:myprefix="http://mynamespace.org">
    <myprefix:Status>100</myprefix:Status>
</myprefix:Response>

but I would preferrably have the xmlns="" without a prefix so that the 
prefix do not have to be repeated for the child nodes.
What am I missing?




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


Re: Re: Namespace with no prefix - how?

Posted by Jeff Greif <jg...@alumni.princeton.edu>.
Yes, I guess I was unclear.  The XPath has to have prefixes.  The document
can have a default namespace, but XPaths cannot refer to it with a null
prefix.
Jeff

----- Original Message -----
From: "Jesus M. Salvo Jr." <je...@migasia.com>
To: <xe...@xml.apache.org>
Sent: Tuesday, February 04, 2003 5:47 PM
Subject: OT: Re: Namespace with no prefix - how?


>
> Having said that ... the following still works:
>
> the following xpath expression:
>
>     //mm100:MM7Version
>
> works against:
>
> <SubmitReq
>
xmlns="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-M
M7-1-2">
>     <MM7Version>5.3.0</MM7Version>
> </SubmitReq>
>
> ... using my custom PrefixResolver that you mentioned in the xalan
> mailing list.
>
>
> Jesus M. Salvo Jr. wrote:
>
> >
> > Thanks for that Jeff. Good you are on this list too ;)  You saved some
> > grief.
> > For the mean time, I will have things fully-prefixed.
> >
> > Jeff Greif wrote:
> >
> >> The XPath spec says you can't use XPath on this.  Some versions of
xalan
> >> will let you do /:Response/:Status, but the authors claim it's a bug
> >> if it
> >> works.
> >> Jeff
> >> ----- Original Message -----
> >> From: "Jesus M. Salvo Jr." <je...@migasia.com>
> >> To: "Xerces mailing list" <xe...@xml.apache.org>
> >> Sent: Monday, February 03, 2003 11:25 PM
> >> Subject: Namespace with no prefix - how?
> >>
> >>
> >>
> >>
> >>> How do you create a element with a namespace without any prefix,
> >>> something like this (?):
> >>>
> >>> <Response xmlns="http://mynamespace.org">
> >>>    <Status>100</Status>
> >>> </Response>
> >>>
> >>>
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> >> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
> >>
> >>
> >>
> >>
> >
> >
>
>
> --
> Jesus M. Salvo Jr.
> Mobile Internet Group Pty Ltd
> (formerly Softgame International Pty Ltd)
> M: +61 409 126699
> T: +61 2 94604777
> F: +61 2 94603677
>
> PGP Public key:
http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xC0BA5348
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
>


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


OT: Re: Namespace with no prefix - how?

Posted by "Jesus M. Salvo Jr." <je...@migasia.com>.
Having said that ... the following still works:

the following xpath expression:

    //mm100:MM7Version

works against:

<SubmitReq 
xmlns="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-2">
    <MM7Version>5.3.0</MM7Version>
</SubmitReq>

... using my custom PrefixResolver that you mentioned in the xalan 
mailing list.


Jesus M. Salvo Jr. wrote:

>
> Thanks for that Jeff. Good you are on this list too ;)  You saved some 
> grief.
> For the mean time, I will have things fully-prefixed.
>
> Jeff Greif wrote:
>
>> The XPath spec says you can't use XPath on this.  Some versions of xalan
>> will let you do /:Response/:Status, but the authors claim it's a bug 
>> if it
>> works.
>> Jeff
>> ----- Original Message -----
>> From: "Jesus M. Salvo Jr." <je...@migasia.com>
>> To: "Xerces mailing list" <xe...@xml.apache.org>
>> Sent: Monday, February 03, 2003 11:25 PM
>> Subject: Namespace with no prefix - how?
>>
>>
>>  
>>
>>> How do you create a element with a namespace without any prefix,
>>> something like this (?):
>>>
>>> <Response xmlns="http://mynamespace.org">
>>>    <Status>100</Status>
>>> </Response>
>>>
>>>   
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
>> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>>
>>
>>  
>>
>
>


-- 
Jesus M. Salvo Jr.
Mobile Internet Group Pty Ltd
(formerly Softgame International Pty Ltd)
M: +61 409 126699
T: +61 2 94604777
F: +61 2 94603677

PGP Public key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xC0BA5348



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


Re: Namespace with no prefix - how?

Posted by "Jesus M. Salvo Jr." <je...@migasia.com>.
Thanks for that Jeff. Good you are on this list too ;)  You saved some 
grief.
For the mean time, I will have things fully-prefixed.

Jeff Greif wrote:

>The XPath spec says you can't use XPath on this.  Some versions of xalan
>will let you do /:Response/:Status, but the authors claim it's a bug if it
>works.
>Jeff
>----- Original Message -----
>From: "Jesus M. Salvo Jr." <je...@migasia.com>
>To: "Xerces mailing list" <xe...@xml.apache.org>
>Sent: Monday, February 03, 2003 11:25 PM
>Subject: Namespace with no prefix - how?
>
>
>  
>
>>How do you create a element with a namespace without any prefix,
>>something like this (?):
>>
>><Response xmlns="http://mynamespace.org">
>>    <Status>100</Status>
>></Response>
>>
>>    
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
>
>  
>


-- 
Jesus M. Salvo Jr.
Mobile Internet Group Pty Ltd
(formerly Softgame International Pty Ltd)
M: +61 409 126699
T: +61 2 94604777
F: +61 2 94603677

PGP Public key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xC0BA5348



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


Re: Namespace with no prefix - how?

Posted by Jeff Greif <jg...@alumni.princeton.edu>.
The XPath spec says you can't use XPath on this.  Some versions of xalan
will let you do /:Response/:Status, but the authors claim it's a bug if it
works.
Jeff
----- Original Message -----
From: "Jesus M. Salvo Jr." <je...@migasia.com>
To: "Xerces mailing list" <xe...@xml.apache.org>
Sent: Monday, February 03, 2003 11:25 PM
Subject: Namespace with no prefix - how?


>
>
> How do you create a element with a namespace without any prefix,
> something like this (?):
>
> <Response xmlns="http://mynamespace.org">
>     <Status>100</Status>
> </Response>
>


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


Re: Namespace with no prefix - how?

Posted by Joseph Kesselman <ke...@us.ibm.com>.
>How do you create a element with a namespace without any prefix, 
>something like this (?):

> <Response xmlns="http://mynamespace.org"/>

You're on the right track.

    Element responseElement = doc.createElementNS( 
        "http://mynamespace.org", "Response" );

The question is what to do about the default namespace declaration. 
THEORETICALLY, it shouldn't be needed by most DOM processing, only when 
you write the document out to a file or SAX stream or whatever, and a good 
XML serializer should realize that it has to automatically create the 
default namespace declaration at that time. 

If you have a DOM that prototypes DOM Level 3, you can run namespace 
normalization and it will create the default namespace declaration (and 
reconcile any other declarations, as necessary).

Or you can explicitly create it:

        String namespaceForNamespaces="http://www.w3.org/2000/xmlns/";
        responseElement.setAttributeNS(namespaceForNamespaces,"xmlns","
http://mynamespace.org");


See also the current DOM Level 3 Working Draft, section 1.1.10 
(namespaces),  Document.normalizeDocument(), and appendix B.1 ("Namespace 
Normalization" pseudocode).
______________________________________
Joe Kesselman  / IBM Research


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