You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Dogan Atay <DA...@aflac.com> on 2005/01/11 22:45:41 UTC

Prefix question

I have a schema like the following

 

<xs:schema 

targetNamespace="http://ga.afl.com/" 

xmlns:xs="http://www.w3.org/2001/XMLSchema" 

elementFormDefault="qualified" 

attributeFormDefault="unqualified" 

xmlns:ga="http://ga.afl.com/" 

xmlns:png="http://ga.afl.com/png/" 

xmlns:pnr="http://ga.afl.com/pnr/" 

xmlns:ct="http://es.afl.com/ct/">

 

      <xs:import namespace=http://es.aflc.com/ct/ <http://es.aflc.com/ct/>
schemaLocation="ct.xsd"/>

      <xs:import namespace="http://ga.afl.com/png/"
schemaLocation="Png.xsd"/>

      <xs:import namespace="http://ga.afl.com/pnr/"
schemaLocation="Pnr.xsd"/>

 

      

      <xs:element name="readGroupRequest" type="ga:GroupIdentifierType"/>

 

      <xs:complexType name="GroupIdentifierType">

            <xs:choice>

                  <xs:element name="pngId" type="xs:integer"/>

                  <xs:element name="batchId" type="png:BatchIDType"/>

                  <xs:element name="groupNumber" type="ct:GroupNumberType"/>

            </xs:choice>

      </xs:complexType>

</xs:schema>

 

After the schema is compiled I do the following

 

SchemaType type = ReadGroupRequestDocument.type;

SchemaProperty[] schemaProperties = type.getElementProperties();

for(int i=0; i < schemaProperties.length; i++)

{

      SchemaProperty schemaProperty = schemaProperties[i];

      QName qName = schemaProperty.getName();

                        

      System.out.println("NamespaceURI: " + qName.getNamespaceURI());

      System.out.println("LocalPart: " + qName.getLocalPart());

      System.out.println("Prefix: " + qName.getPrefix());

}

 

The output of that code is

NamespaceURI: http://ga.afl.com/

LocalPart: readGroupRequest

Prefix:

 

 

What I do not understand is why the prefix is not "ga".  The schema has this
information.

 

I need to get this information out of the schema because the xml I generate
must have this prefix.  I will use XMLOptions setSaveSuggestedPrefixes()
method but I do not want to hardcode a prefix in my source code.  How else
can I get the prefix from the schema?

 

Thanks,

 

Dogan Atay

 


Re: Prefix question

Posted by Justin Makeig <ju...@thatone.com>.
Parsers are free to choose their own prefixes (or none at all). Why is 
your application dependent on the prefix "ga"? The URI to which this 
prefix points is what's important, not the prefix itself.

- Justin

Dogan Atay wrote:
> I have a schema like the following
> 
>  
> 
> <xs:schema
> 
> targetNamespace="http://ga.afl.com/"
> 
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> 
> elementFormDefault="qualified"
> 
> attributeFormDefault="unqualified"
> 
> xmlns:ga="http://ga.afl.com/"
> 
> xmlns:png="http://ga.afl.com/png/"
> 
> xmlns:pnr="http://ga.afl.com/pnr/"
> 
> xmlns:ct="http://es.afl.com/ct/">
> 
>  
> 
>       <xs:import namespace=http://es.aflc.com/ct/ schemaLocation="ct.xsd"/>
> 
>       <xs:import namespace="http://ga.afl.com/png/" 
> schemaLocation="Png.xsd"/>
> 
>       <xs:import namespace="http://ga.afl.com/pnr/" 
> schemaLocation="Pnr.xsd"/>
> 
>  
> 
>      
> 
>       <xs:element name="readGroupRequest" type="ga:GroupIdentifierType"/>
> 
>  
> 
>       <xs:complexType name="GroupIdentifierType">
> 
>             <xs:choice>
> 
>                   <xs:element name="pngId" type="xs:integer"/>
> 
>                   <xs:element name="batchId" type="png:BatchIDType"/>
> 
>                   <xs:element name="groupNumber" type="ct:GroupNumberType"/>
> 
>             </xs:choice>
> 
>       </xs:complexType>
> 
> </xs:schema>
> 
>  
> 
> After the schema is compiled I do the following
> 
>  
> 
> SchemaType type = ReadGroupRequestDocument.type;
> 
> SchemaProperty[] schemaProperties = type.getElementProperties();
> 
> for(int i=0; i < schemaProperties.length; i++)
> 
> {
> 
>       SchemaProperty schemaProperty = schemaProperties[i];
> 
>       QName qName = schemaProperty.getName();
> 
>                        
> 
>       System.out.println("NamespaceURI: " + qName.getNamespaceURI());
> 
>       System.out.println("LocalPart: " + qName.getLocalPart());
> 
>       System.out.println("Prefix: " + qName.getPrefix());
> 
> }
> 
>  
> 
> The output of that code is
> 
> NamespaceURI: http://ga.afl.com/
> 
> LocalPart: readGroupRequest
> 
> Prefix:
> 
>  
> 
>  
> 
> What I do not understand is why the prefix is not “ga”.  The schema has 
> this information.
> 
>  
> 
> I need to get this information out of the schema because the xml I 
> generate must have this prefix.  I will use XMLOptions 
> setSaveSuggestedPrefixes() method but I do not want to hardcode a prefix 
> in my source code.  How else can I get the prefix from the schema?
> 
>  
> 
> Thanks,
> 
>  
> 
> Dogan Atay
> 
>  
> 

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