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 Nick Betteridge <n....@syntactics.com> on 2003/07/31 20:38:29 UTC

Getting the namespace prefix

I'm having difficulty in trying to get the namespace prefix.

When I get the SchemaGrammar and recurse down through the model, when I get to the simpleTypes (eg "xs:string") I can recover both the name and the namespace of the simpleType, but I can't work out how to recover the namespace prefix.

ie
xsSimpleTypeDecl.getName()  will give me "string"
xsSimpleTypeDecl.getNamespace() will give me http://www.w3.org/2001/XMLSchema

how do I get "xs" (defined in the example below)

I would be very grateful if someone would point me in the right direction.

Many trhanks
Nick


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema 
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    >
    <xs:element name="responsemodel">
        <xs:annotation>
            <xs:documentation>filesystems response model</xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:sequence>
                <xs:element name="response" type="xs:string"/>
                <xs:element name="exceptionThrown" type="xs:boolean"/>
                <xs:element name="exceptionMessage" minOccurs="0" type="xs:string"/>
                <xs:sequence>
                    <xs:element name="children" minOccurs="0"
                        maxOccurs="unbounded" type="xs:string"/>
                </xs:sequence>
                <xs:element name="booleanResponse" minOccurs="0" type="xs:boolean"/>
                <xs:element name="byteResponse" minOccurs="0" type="xs:base64Binary"/>
                <xs:element name="calendarResponse" minOccurs="0" type="xs:date"/>
                <xs:element name="longResponse" minOccurs="0" type="xs:int"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

Re: Getting the namespace prefix

Posted by Nick Betteridge <n....@syntactics.com>.
Thanks for the quick reply.

Couldn't this be added to xerces - it must be a relatively easy thing to do. Seems a shame to have to parse the same schema twice.

I'm writing a SchemaWriter as I'm using xerces as the basis of  a schema editor. So far, so good except for the namespace prefix. XSDHandler creates the SchemaGrammar and also picks up the prefix.

Perhaps I should do a local build and make the fix?

Nick
  ----- Original Message ----- 
  From: Jeff Greif 
  To: xerces-j-user@xml.apache.org 
  Sent: Thursday, July 31, 2003 7:49 PM
  Subject: Re: Getting the namespace prefix


  The namespace prefix is not a part of the PSVI (post schema validation infoset) which is represented by the XSModel.  I think you'd probably have to do a separate parse of the schema file and rummage in the SAX events or the DOM to find the prefix.

  Jeff

  ----- Original Message ----- 
    From: Nick Betteridge 
    To: xerces-j-user@xml.apache.org 
    Sent: Thursday, July 31, 2003 11:38 AM
    Subject: Getting the namespace prefix


    I'm having difficulty in trying to get the namespace prefix.

    When I get the SchemaGrammar and recurse down through the model, when I get to the simpleTypes (eg "xs:string") I can recover both the name and the namespace of the simpleType, but I can't work out how to recover the namespace prefix.


Re: Getting the namespace prefix

Posted by Jeff Greif <jg...@alumni.princeton.edu>.
The namespace prefix is not a part of the PSVI (post schema validation infoset) which is represented by the XSModel.  I think you'd probably have to do a separate parse of the schema file and rummage in the SAX events or the DOM to find the prefix.

Jeff

----- Original Message ----- 
  From: Nick Betteridge 
  To: xerces-j-user@xml.apache.org 
  Sent: Thursday, July 31, 2003 11:38 AM
  Subject: Getting the namespace prefix


  I'm having difficulty in trying to get the namespace prefix.

  When I get the SchemaGrammar and recurse down through the model, when I get to the simpleTypes (eg "xs:string") I can recover both the name and the namespace of the simpleType, but I can't work out how to recover the namespace prefix.