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 JC <ch...@hotmail.com> on 2002/06/19 22:34:59 UTC

How to identify the namespace?

Here is something that is bugging me... during the parsing of an RSS file, 
I need to be able to tell if it is a 0.9 RSS or a 1.0 RSS. Unlike RSS 0.91 
and 0.92, there is no "version" attribute. Here is what I have to work with:

<rdf:RDF xmlns="http://my.netscape.com/rdf/simple/0.9/" 
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

This is an RSS 0.9 file.

<rdf:RDF xmlns="http://purl.org/rss/1.0/" 
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

This is an RSS 1.0 file.

The only difference between the two is the xmlns value. However, I cannot 
figure out how to get ahold of it. During element parsing, I only have 
access to the xmlns:rdf value (as uri), the element name and the qname. The 
attributes length is zero.

So how can I get ahold of the xmlns value during parsing?

Thanks for any help!


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


Re: How to identify the namespace?

Posted by Jan Dvorak <ja...@mathan.cz>.
Hi Kakoli,

You need your parser configured namespace-aware.
If you obtain it via JAXP, don't forget to setNamespaceAware(true) on the 
SAXParserFactory. Otherwise you may want to set the 
http://xml.org/sax/features/namespaces feature to true.

Jan Dvorak

Kakoli wrote:
| Hi all,
|
| I am not able to get different namespaces for a parent element and a child
| element even though I have defined different namespaces for both.
|
|  My xml request looks like :
|
| <?xml version="1.0" encoding="UTF-8"?>
| <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
|         <Body>
|                 <EL1 generic="2.0" xmlns="urn:uddi-org:api_v2">
|                         <EL2 xmlns="urn:uddi-org:repl">abcd</EL2>
|                 </EL1>
|         </Body>
| </Envelope>
|
| This is parsed by SAXParser(xerces 1.4.3)
|
| In my code of startElement method  where namespace is passed as a
| parameter, for both EL1 and EL2, the namespace obtained is the same as
| EL1(i.e., the root element), even though for EL2, different namespace is
| used. How do I get the EL2 namespace?
|
| Any answers?
|  Thanks & Regards,
| Kakoli
|
|
|
|  -----Original Message-----
| From: JC [mailto:churjs@hotmail.com]
| Sent: Thursday, June 20, 2002 10:28 PM
| To: xerces-j-user@xml.apache.org
| Subject: Re: How to identify the namespace?
|
|
|   This was what I needed! (The first part, not the second.) Thank you very
| much.
|
|
|
|   At 05:54 PM 6/20/2002 +0200, you wrote:
|
|     Hi,
|
|     If you use SAX2, you'll see a startPrefixMapping( prefix, nsuri ) event
|     before the startElement() event. Anyway, the startElement() event also
| passes
|     the namespace URI to you.
|     If you use DOM, you can get the namespace URI out of every element
| node.
|
|     Jan Dvorak
|
|     > Here is something that is bugging me... during the parsing of an RSS
|
| file,
|
|     > I need to be able to tell if it is a 0.9 RSS or a 1.0 RSS. Unlike RSS
|
| 0.91
|
|     > and 0.92, there is no "version" attribute. Here is what I have to
|     > work with:
|     >
|     > <rdf:RDF xmlns="http://my.netscape.com/rdf/simple/0.9/"
|     > xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|     >
|     > This is an RSS 0.9 file.
|     >
|     > <rdf:RDF xmlns="http://purl.org/rss/1.0/"
|     > xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|     >
|     > This is an RSS 1.0 file.
|     >
|     > The only difference between the two is the xmlns value. However, I
|
| cannot
|
|     > figure out how to get ahold of it. During element parsing, I only
|     > have access to the xmlns:rdf value (as uri), the element name and the
|
| qname. The
|
|     > attributes length is zero.
|     >
|     > So how can I get ahold of the xmlns value during parsing?
|     >
|     > Thanks for any help!
|     >
|     >
|     > ---------------------------------------------------------------------
|     > 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


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


RE: How to identify the namespace?

Posted by Kakoli <ka...@india.hp.com>.
Hi all,

I am not able to get different namespaces for a parent element and a child
element even though I have defined different namespaces for both.

 My xml request looks like :

<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
        <Body>
                <EL1 generic="2.0" xmlns="urn:uddi-org:api_v2">
                        <EL2 xmlns="urn:uddi-org:repl">abcd</EL2>
                </EL1>
        </Body>
</Envelope>

This is parsed by SAXParser(xerces 1.4.3)

In my code of startElement method  where namespace is passed as a parameter,
for both EL1 and EL2, the namespace obtained is the same as EL1(i.e., the
root element), even though for EL2, different namespace is used. How do I
get the EL2 namespace?

Any answers?
 Thanks & Regards,
Kakoli



 -----Original Message-----
From: JC [mailto:churjs@hotmail.com]
Sent: Thursday, June 20, 2002 10:28 PM
To: xerces-j-user@xml.apache.org
Subject: Re: How to identify the namespace?


  This was what I needed! (The first part, not the second.) Thank you very
much.



  At 05:54 PM 6/20/2002 +0200, you wrote:

    Hi,

    If you use SAX2, you'll see a startPrefixMapping( prefix, nsuri ) event
    before the startElement() event. Anyway, the startElement() event also
passes
    the namespace URI to you.
    If you use DOM, you can get the namespace URI out of every element node.

    Jan Dvorak


    > Here is something that is bugging me... during the parsing of an RSS
file,
    > I need to be able to tell if it is a 0.9 RSS or a 1.0 RSS. Unlike RSS
0.91
    > and 0.92, there is no "version" attribute. Here is what I have to work
    > with:
    >
    > <rdf:RDF xmlns="http://my.netscape.com/rdf/simple/0.9/"
    > xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
    >
    > This is an RSS 0.9 file.
    >
    > <rdf:RDF xmlns="http://purl.org/rss/1.0/"
    > xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
    >
    > This is an RSS 1.0 file.
    >
    > The only difference between the two is the xmlns value. However, I
cannot
    > figure out how to get ahold of it. During element parsing, I only have
    > access to the xmlns:rdf value (as uri), the element name and the
qname. The
    > attributes length is zero.
    >
    > So how can I get ahold of the xmlns value during parsing?
    >
    > Thanks for any help!
    >
    >
    > ---------------------------------------------------------------------
    > 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

Re: How to identify the namespace?

Posted by JC <ch...@hotmail.com>.
This was what I needed! (The first part, not the second.) Thank you very much.



At 05:54 PM 6/20/2002 +0200, you wrote:
>Hi,
>
>If you use SAX2, you'll see a startPrefixMapping( prefix, nsuri ) event
>before the startElement() event. Anyway, the startElement() event also passes
>the namespace URI to you.
>If you use DOM, you can get the namespace URI out of every element node.
>
>Jan Dvorak
>
>
> > Here is something that is bugging me... during the parsing of an RSS file,
> > I need to be able to tell if it is a 0.9 RSS or a 1.0 RSS. Unlike RSS 0.91
> > and 0.92, there is no "version" attribute. Here is what I have to work
> > with:
> >
> > <rdf:RDF xmlns="http://my.netscape.com/rdf/simple/0.9/"
> > xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
> >
> > This is an RSS 0.9 file.
> >
> > <rdf:RDF xmlns="http://purl.org/rss/1.0/"
> > xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
> >
> > This is an RSS 1.0 file.
> >
> > The only difference between the two is the xmlns value. However, I cannot
> > figure out how to get ahold of it. During element parsing, I only have
> > access to the xmlns:rdf value (as uri), the element name and the qname. The
> > attributes length is zero.
> >
> > So how can I get ahold of the xmlns value during parsing?
> >
> > Thanks for any help!
> >
> >
> > ---------------------------------------------------------------------
> > 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

Re: How to identify the namespace?

Posted by Jan Dvorak <ja...@mathan.cz>.
Hi,

If you use SAX2, you'll see a startPrefixMapping( prefix, nsuri ) event 
before the startElement() event. Anyway, the startElement() event also passes 
the namespace URI to you.
If you use DOM, you can get the namespace URI out of every element node.

Jan Dvorak


> Here is something that is bugging me... during the parsing of an RSS file,
> I need to be able to tell if it is a 0.9 RSS or a 1.0 RSS. Unlike RSS 0.91
> and 0.92, there is no "version" attribute. Here is what I have to work
> with:
>
> <rdf:RDF xmlns="http://my.netscape.com/rdf/simple/0.9/"
> xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
>
> This is an RSS 0.9 file.
>
> <rdf:RDF xmlns="http://purl.org/rss/1.0/"
> xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
>
> This is an RSS 1.0 file.
>
> The only difference between the two is the xmlns value. However, I cannot
> figure out how to get ahold of it. During element parsing, I only have
> access to the xmlns:rdf value (as uri), the element name and the qname. The
> attributes length is zero.
>
> So how can I get ahold of the xmlns value during parsing?
>
> Thanks for any help!
>
>
> ---------------------------------------------------------------------
> 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