Justin,
I think I have asked my question in a
wrong way.
My application is NOT dependent on ‘ga’
prefix. The output xml of
<readGroupRequest xmlns="http://ga.afl.com/">
<groupNumber>12345</groupNumber>
</readGroupRequest>
is namespace
qualified with a no-prefix. That is fine. My schema shows that this
namespace is qualified with the ‘ga’ prefix.
I thought that the attribute xmlns:ga="http://ga.afl.com/" in the <xs:schema> tag reflects
that. Isn’t that true?
My question is
that when I call getName().getPrefix() for this QName why is ‘ga’
not shown?
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
From: Dogan Atay
Sent: Tuesday, January 11, 2005
4:46 PM
To: user@xxxxxxxxxxxxxxxxxxx
Subject: 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/
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