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 Martin Lambert <Ma...@denovopharma.com> on 2003/07/24 17:45:04 UTC

examining XML schema attributes

Hi,

I am trying to examine schema attribute definintions using Xerces.  I am able to retrieve information about attributes that includes an attribute name, its type name and whether it is required.
However I want to retrieve more detailed information about the attribute's type. For example, given the type definition below I would like to retrieve the values that make up the enumeration i.e.
1,2,3,4,5. I can't seem to work out the correct approach to retrieving this information. I would also like to know how this would work for a type with restrictions like 'negative integer'. 

I have also included my code to highlight how I have been trying to approach this problem.

<simpleType name="testType">
         <restriction base="integer">
            <enumeration value="1"/>
            <enumeration value="2"/>
            <enumeration value="3"/>
            <enumeration value="4"/>
            <enumeration value="5"/>
         </restriction>
 </simpleType>  

<complexType name="classType">
	  <sequence>
	  	<element name="template" type="templateType" maxOccurs="unbounded"/>
	  </sequence>
	  <attribute name="matches" type="testType" use="required"/>
</complexType>

Where element is an instance of 'XSElementDeclaration':

XSTypeDefinition elementTypeDef = element.getTypeDefinition();
XSObjectList attributeUses  = ((XSComplexTypeDefinition)elementTypeDef).getAttributeUses();
        
for(int attrUseIdx=0; attrUseIdx < attributeUses.getLength(); attrUseIdx++)
{
            XSAttributeUse attributeUse = (XSAttributeUse)attributeUses.item(attrUseIdx);
            XSAttributeDeclaration attribute = attributeUse.getAttrDeclaration();
            XSSimpleTypeDefinition attributeType = attribute.getTypeDefinition();
            
            System.out.println(attribute.getName() + ", required? " + attributeUse.getRequired() +
            ", bounded? " + attributeType.getBounded() + ", finite? " + attributeType.getFinite() +
            ", numeric? " + attributeType.getNumeric() + ", type: " + attributeType.getName() +
            ", constraint value: " + attribute.getConstraintValue() + ", enumeration" attributeType);            
}

Hope there is a straightforward answer to this.

Cheers,

Martin.


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


Re: examining XML schema attributes

Posted by Mark Brucks <br...@j3s.us>.
Martin:

Given that I am in the middle of doing this as well, I believe I have 
the answer.  Once you get the type declaration from the attribute, cast 
it to XSSimpleTypeDecl and then use the getLexicalEnumeration method. 
 This returns a StringList containing the enumerated values for the type 
(this is how you get both enumerations for attributes as well as 
enumerations for content for simple types that are restrictions on the 
primitive string type).  Restrictions like 'negative integer' don't 
generate enumerations, so you have to use the getBaseType method to 
determine what the primitive type is (and I believe that negativeInteger 
is a primitive type).

Mark Brucks

Martin Lambert wrote:

>Hi,
>
>I am trying to examine schema attribute definintions using Xerces.  I am able to retrieve information about attributes that includes an attribute name, its type name and whether it is required.
>However I want to retrieve more detailed information about the attribute's type. For example, given the type definition below I would like to retrieve the values that make up the enumeration i.e.
>1,2,3,4,5. I can't seem to work out the correct approach to retrieving this information. I would also like to know how this would work for a type with restrictions like 'negative integer'. 
>
>I have also included my code to highlight how I have been trying to approach this problem.
>
><simpleType name="testType">
>         <restriction base="integer">
>            <enumeration value="1"/>
>            <enumeration value="2"/>
>            <enumeration value="3"/>
>            <enumeration value="4"/>
>            <enumeration value="5"/>
>         </restriction>
> </simpleType>  
>
><complexType name="classType">
>	  <sequence>
>	  	<element name="template" type="templateType" maxOccurs="unbounded"/>
>	  </sequence>
>	  <attribute name="matches" type="testType" use="required"/>
></complexType>
>
>Where element is an instance of 'XSElementDeclaration':
>
>XSTypeDefinition elementTypeDef = element.getTypeDefinition();
>XSObjectList attributeUses  = ((XSComplexTypeDefinition)elementTypeDef).getAttributeUses();
>        
>for(int attrUseIdx=0; attrUseIdx < attributeUses.getLength(); attrUseIdx++)
>{
>            XSAttributeUse attributeUse = (XSAttributeUse)attributeUses.item(attrUseIdx);
>            XSAttributeDeclaration attribute = attributeUse.getAttrDeclaration();
>            XSSimpleTypeDefinition attributeType = attribute.getTypeDefinition();
>            
>            System.out.println(attribute.getName() + ", required? " + attributeUse.getRequired() +
>            ", bounded? " + attributeType.getBounded() + ", finite? " + attributeType.getFinite() +
>            ", numeric? " + attributeType.getNumeric() + ", type: " + attributeType.getName() +
>            ", constraint value: " + attribute.getConstraintValue() + ", enumeration" attributeType);            
>}
>
>Hope there is a straightforward answer to this.
>
>Cheers,
>
>Martin.
>
>
>---------------------------------------------------------------------
>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