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 Scott Hinkelman <sr...@us.ibm.com> on 2007/03/01 21:29:23 UTC

obtaining an attribute name using the xs package


Hi,
I am learning and trying to process, or print out for my understanding, the
following simple schema contain 1 complex type with 1 attribute. My problem
is I have yet to be able to print out the name, "languageLocaleID", of the
attribute.

<?xml version="1.0" encoding="UTF-8"?>
<?xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:cct.="
urn:un:unece:uncefact:documentation:standard:CoreComponentType:2"
xmlns:ccts="
urn:un:unece:uncefact:documentation:standard:CoreComponentsTechnicalSpecification:2
" targetNamespace="
urn:un:unece:uncefact:documentation:standard:CoreComponentType:2"
elementFormDefault="qualified" attributeFormDefault:="unqualified" version
="2.0">
 <>xsd:complexType name="TextType">
  <xsd:simpleContent>
   <xsd:extension base="xsd:string">
    <xsd:attribute name="languageLocaleID" type="xsd:token" use="optional
"/>
   </xsd:extension>
  </xsd:simpleContent>
 </xsd:complexType>
</xsd:schema>

Here is the fundamental code I am using, starting with a method which takes
the complex type, Sorry for the length, but my question is where should I
call getName() to obtain " "languageLocaleID" ?
I obtain the Attr Uses from the complex type, get the Attr Decl from the
Attr Use, and then the SimpleType from the Attr Decl - but nowhere an I
getting the name. I am using xerces 2_9_0.

  private void processCTD(XSComplexTypeDefinition ctd) {
    System.out.println("\nprocessing complex type <"+ctd.getName()+">");

    //get the Attribute Uses fro the complex type
    XSObjectList xsol=ctd.getAttributeUses();
    System.out.println("Number of Attribute Uses...."+xsol.getLength());
    for(int j=0;j<xsol.getLength();j++){
      XSAttributeUse attruse = (XSAttributeUse)xsol.item(j);
      System.out.println("attr use ns:   "+attruse.getNamespace());
      System.out.println("attr use name: "+attruse.getName());
      System.out.println("attr use nsItem: "+attruse.getNamespaceItem());
      System.out.println("attr use type: "+ attruse.getType());
      System.out.println("attr use required: "+attruse.getRequired());));
      System.out.println("attr use constraint value:
"+attruse.getConstraintValue());//null?
      short consttype=attruse.getConstraintType();//Value Constraint: one
of default, fixed.
      try{
        Object actualvc=attruse.getActualVC();//Value Constraint: Binding
specific actual constraint value or null if the value is in error or there
is no value constraint.
        if(actualvc!=null){
          System.out.println("attr use actual value constrint:
"+actualvc.toString());
        }
      }catch(XSException e){
        e.printStackTrace();
      }
      try{
        short actualvalctype=attruse.getActualVCType();//The actual
constraint value built-in datatype, e.g. STRING_DT, SHORT_DT. If the type
definition of this value is a list type definition, this method returns
LIST_DT. If the type definition of this value is a list type definition
whose item type is a union type definition, this method returns
LISTOFUNION_DT. To query the actual constraint value of the list or list of
union type definitions use itemValueTypes. If the actualNormalizedValue is
null, this method returns UNAVAILABLE_DT .
      }catch(XSException e){
        e.printStackTrace();
      }
      try{
        ShortList sl=attruse.getItemValueTypes();//In the case the actual
constraint value represents a list, i.e. the actualValueType is LIST_DT,
the returned array consists of one type kind which represents the itemType.
If the actual constraint value represents a list type definition whose item
type is a union type definition, i.e. LISTOFUNION_DT, for each actual
constraint value in the list the array contains the corresponding
memberType kind. For examples, see ItemPSVI.itemValueTypes.
        if(sl!=null){
          for(j=0;j<sl.getLength();j++){
            short sh=sl.item(j);
            System.out.println("attr use short: "+sh);
          }
        }
      }catch(XSException e){
        e.printStackTrace();
      }

      //get the declaration for the attribute use
      XSAttributeDeclaration attrdecl=attruse.getAttrDeclaration
();//[attribute declaration]: provides the attribute declaration itself,
which will in turn determine the simple type definition used.
      short contype=attrdecl.getConstraintType();//Value constraint: one of
VC_NONE, VC_DEFAULT, VC_FIXED.
      String sconvalue=attrdecl.getConstraintValue();//Value constraint:
The constraint value with respect to the [type definition], otherwise null.
      System.out.println("attr decl value: "+sconvalue);//null ?
      try{
        Object obj=attrdecl.getActualVC();//Value Constraint: Binding
specific actual constraint value or null if the value is in error or there
is no value constraint.
      }catch(XSException e){
        //XSException - NOT_SUPPORTED_ERR: Raised if the implementation
does not support this method.
        e.printStackTrace();
      }
      try{
        short avalvct=attrdecl.getActualVCType();//The actual constraint
value built-in datatype, e.g. STRING_DT, SHORT_DT. If the type definition
of this value is a list type definition, this method returns LIST_DT. If
the type definition of this value is a list type definition whose item type
is a union type definition, this method returns LISTOFUNION_DT. To query
the actual constraint value of the list or list of union type definitions
use itemValueTypes. If the actualValue is null, this method returns
UNAVAILABLE_DT.
      }catch(XSException e){
        //XSException - NOT_SUPPORTED_ERR: Raised if the implementation
does not support this method..
        e.printStackTrace();
      }
      try{
        ShortList sl2=attrdecl.getItemValueTypes();//In the case the actual
constraint value represents a list, i.e. the actualValueType is LIST_DT,
the returned array consists of one type kind which represents the itemType.
If the actual constraint value represents a list type definition whose item
type is a union type definition, i.e. LISTOFUNION_DT, for each actual
constraint value in the list the array contains the corresponding
memberType kind. For examples, see ItemPSVI.itemValueTypes.
      }catch(XSException e){
        //XSException - NOT_SUPPORTED_ERR: Raised if the implementation
does not support this method.
        e.printStackTrace();
      }

      XSSimpleTypeDefinition std= attrdecl.getTypeDefinition();//[type
definition]: A simple type definition.
      System.out.println("attr decl ns:   "+std.getNamespace());
      System.out.println("attr decl name: "+std.getName());
      System.out.println("attr decl nsItem: "+std.getNamespaceItem());
      System.out.println("attr decl type: "+std.getType());

      StringList slist=std.getLexicalEnumeration();
      System.out.println("attr decl simple type lexical enum stringlist
length "+slist.getLength());
      for(int k=0;k<slist.getLength();k++){
        String str=slist.item(k);
        System.out.println("a string list item: "+str);
      }

      slist=std.getLexicalPattern();
      System.out.println("attr decl simple type lexical patterns stringlist
length "+slist.getLength());
      for(int k=0;k<slist.getLength();k++){
        String str=slist.item(k);
        System.out.println("a string list item: "+str);
      }
    }
  }


My output from this function is:

processing complex type <TextType>
Number of Attribute Uses....1
attr use ns:   null
attr use name: null
attr use nsItem: null
attr use type: 4
attr use required: false....
attr use constraint value: null
attr decl value: null
attr decl ns:   http://www.w3.org/2001/XMLSchema
attr decl name: token
attr decl nsItem: null
attr decl type: 3
attr decl simple type lexical enum stringlist length 0;
attr decl simple type lexical patterns stringlist length 0

Any help on the correct way to obtain or process the attribute is
appreciated. Thank you.

Scott R. Hinkelman

Re: obtaining an attribute name using the xs package

Posted by Scott Hinkelman <sr...@us.ibm.com>.
Thanks Michael,
Ed Wax earlier indicated also to obtain the name from the attr decl
interface -thanks again.......

Scott------------
Scott R. Hinkelman, Senior Software EngineerIBM Software Group / Emerging
TechnologiesCross-Industry SOA Foundation Standards StrategyOffice:
512.823.8097 (TL 793.8097)
Cell: 512.415.8490


                                                                           
             Michael                                                       
             Glavassevich                                                  
             <mrglavas@ca.ibm.                                          To 
             com>                      j-users@xerces.apache.org)          
                                                                        cc 
             03/01/2007 08:37                                              
             PM                                                    Subject 
                                       Re: obtaining an attribute name     
                                       using the xs package                
              Please respond                                               
             toj-users@xerces.                                             
                apache.org                                                 
                                                                           
                                                                           
                                                                           




Hi Scott,You want to call getName() on the XSAttributeDeclaration. You're
currently
printing out the name (i.e. xs:token) of its [type
definition].Thanks.Michael GlavassevichXML Parser DevelopmentIBM Toronto
LabE-mail: mrglavas@ca.ibm.comE-mail: mrglavas@apache.orgScott Hinkelman
<sr...@us.ibm.com> wrote on 03/01/2007 03:29:23 PM:> Hi,> I am learning and
trying to process, or print out for my
> understanding, the following simple schema contain 1 complex type
> with 1 attribute. My problem is I have yet to be able to print out
> the name, "languageLocaleID", of the attribute.>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:cct=">
urn:un:unece:uncefact:documentation:standard:CoreComponentType:2"
xmlns:ccts="> urn:un:unece:uncefact:documentation:standard:>
CoreComponentsTechnicalSpecification:2" targetNamespace="urn:un:>
unece:uncefact:documentation:standard:CoreComponentType:2"
elementFormDefault> ="qualified" attributeFormDefault="unqualified"
version="2.0">> <xsd:complexType name="TextType">> <xsd:simpleContent>>
<xsd:extension base="xsd:string">> <xsd:attribute name="languageLocaleID"
type="xsd:token" use="optional"/>
> </xsd:extension>> </xsd:simpleContent>> </xsd:complexType>>
</xsd:schema>>
> Here is the fundamental code I am using, starting with a method
> which takes the complex type, Sorry for the length, but my question
> is where should I call getName() to obtain " "languageLocaleID" ?
> I obtain the Attr Uses from the complex type, get the Attr Decl from> the
Attr Use, and then the SimpleType from the Attr Decl - but
> nowhere an I getting the name. I am using xerces 2_9_0.>
> private void processCTD(XSComplexTypeDefinition ctd) {>
System.out.println("\nprocessing complex type <"+ctd.getName()+">");>
> //get the Attribute Uses fro the complex type> XSObjectList
xsol=ctd.getAttributeUses();> System.out.println("Number of Attribute
Uses...."+xsol.getLength());> for(int j=0;j<xsol.getLength();j++){>
XSAttributeUse attruse = (XSAttributeUse)xsol.item(j);> System.out.println
("attr use ns: "+attruse.getNamespace());> System.out.println("attr use
name: "+attruse.getName());> System.out.println("attr use nsItem:
"+attruse.getNamespaceItem());> System.out.println("attr use type: "+
attruse.getType());> System.out.println("attr use required:
"+attruse.getRequired());> System.out.println("attr use constraint value:
"+attruse.> getConstraintValue());//null?
> short consttype=attruse.getConstraintType();//Value Constraint: one
> of default, fixed.> try{> Object actualvc=attruse.getActualVC();//Value
Constraint: Binding
> specific actual constraint value or null if the value is in error or>
there is no value constraint.> if(actualvc!=null){> System.out.println
("attr use actual value constrint:
"+actualvc.toString());> }
> }catch(XSException e){ > e.printStackTrace();> }
> try{> short actualvalctype=attruse.getActualVCType();//The actual
> constraint value built-in datatype, e.g. STRING_DT, SHORT_DT. If the>
type definition of this value is a list type definition, this method>
returns LIST_DT. If the type definition of this value is a list type>
definition whose item type is a union type definition, this method
> returns LISTOFUNION_DT. To query the actual constraint value of the
> list or list of union type definitions use itemValueTypes. If the
> actualNormalizedValue is null, this method returns
UNAVAILABLE_DT .> }catch(XSException e){> e.printStackTrace();> }
> try{> ShortList sl=attruse.getItemValueTypes();//In the case the actual
> constraint value represents a list, i.e. the actualValueType is
> LIST_DT, the returned array consists of one type kind which
> represents the itemType. If the actual constraint value represents a>
list type definition whose item type is a union type definition, i.> e.
LISTOFUNION_DT, for each actual constraint value in the list the
> array contains the corresponding memberType kind. For examples, see
> ItemPSVI.itemValueTypes.> if(sl!=null){> for(j=0;j<sl.getLength();j++){>
short sh=sl.item(j);> System.out.println("attr use short: "+sh);> }
> }
> }catch(XSException e){> e.printStackTrace();> }
>
> //get the declaration for the attribute use> XSAttributeDeclaration
attrdecl=attruse.getAttrDeclaration();> //[attribute declaration]: provides
the attribute declaration
> itself, which will in turn determine the simple type definition used.>
short contype=attrdecl.getConstraintType();//Value constraint: one
> of VC_NONE, VC_DEFAULT, VC_FIXED.> String
sconvalue=attrdecl.getConstraintValue();//Value constraint:
> The constraint value with respect to the [type definition], otherwise
null.> System.out.println("attr decl value: "+sconvalue);//null ?
> try{> Object obj=attrdecl.getActualVC();//Value Constraint: Binding
> specific actual constraint value or null if the value is in error or>
there is no value constraint.> }catch(XSException e){> //XSException -
NOT_SUPPORTED_ERR: Raised if the implementation does> not support this
method.> e.printStackTrace();> }
> try{> short avalvct=attrdecl.getActualVCType();//The actual constraint
> value built-in datatype, e.g. STRING_DT, SHORT_DT. If the type
> definition of this value is a list type definition, this method
> returns LIST_DT. If the type definition of this value is a list type>
definition whose item type is a union type definition, this method
> returns LISTOFUNION_DT. To query the actual constraint value of the
> list or list of union type definitions use itemValueTypes. If the
> actualValue is null, this method returns UNAVAILABLE_DT.> }catch
(XSException e){> //XSException - NOT_SUPPORTED_ERR: Raised if the
implementation does> not support this method.> e.printStackTrace();> }
> try{> ShortList sl2=attrdecl.getItemValueTypes();//In the case the actual

> constraint value represents a list, i.e. the actualValueType is
> LIST_DT, the returned array consists of one type kind which
> represents the itemType. If the actual constraint value represents a>
list type definition whose item type is a union type definition, i.> e.
LISTOFUNION_DT, for each actual constraint value in the list the
> array contains the corresponding memberType kind. For examples, see
> ItemPSVI.itemValueTypes.> }catch(XSException e){> //XSException -
NOT_SUPPORTED_ERR: Raised if the implementation does> not support this
method.> e.printStackTrace();> }
>
> XSSimpleTypeDefinition std= attrdecl.getTypeDefinition();//[type
> definition]: A simple type definition.> System.out.println("attr decl ns:
"+std.getNamespace());> System.out.println("attr decl name: "+std.getName
());> System.out.println("attr decl nsItem: "+std.getNamespaceItem());>
System.out.println("attr decl type: "+std.getType());>
> StringList slist=std.getLexicalEnumeration();> System.out.println("attr
decl simple type lexical enum stringlist
> length "+slist.getLength());> for(int k=0;k<slist.getLength();k++){>
String str=slist.item(k);> System.out.println("a string list item:
"+str);> }
>
> slist=std.getLexicalPattern();> System.out.println("attr decl simple type
lexical patterns
> stringlist length "+slist.getLength());> for(int k=0;k<slist.getLength
();k++){> String str=slist.item(k);> System.out.println("a string list
item: "+str);> }
> }
> }
>
>
> My output from this function is:>
> processing complex type <TextType>> Number of Attribute Uses....1> attr
use ns: null> attr use name: null> attr use nsItem: null> attr use type: 4>
attr use required: false> attr use constraint value: null> attr decl value:
null> attr decl ns: http://www.w3.org/2001/XMLSchema
> attr decl name: token> attr decl nsItem: null> attr decl type: 3> attr
decl simple type lexical enum stringlist length 0> attr decl simple type
lexical patterns stringlist length 0>
> Any help on the correct way to obtain or process the attribute is
> appreciated. Thank you.>
> Scott R.
Hinkelman---------------------------------------------------------------------

To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.orgFor additional
commands, e-mail: j-users-help@xerces.apache.org


Re: obtaining an attribute name using the xs package

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Scott,

You want to call getName() on the XSAttributeDeclaration. You're currently 
printing out the name (i.e. xs:token) of its [type definition].

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Scott Hinkelman <sr...@us.ibm.com> wrote on 03/01/2007 03:29:23 PM:

> Hi,
> I am learning and trying to process, or print out for my 
> understanding, the following simple schema contain 1 complex type 
> with 1 attribute. My problem is I have yet to be able to print out 
> the name, "languageLocaleID", of the attribute.
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:cct="
> urn:un:unece:uncefact:documentation:standard:CoreComponentType:2" 
xmlns:ccts="
> urn:un:unece:uncefact:documentation:standard:
> CoreComponentsTechnicalSpecification:2" targetNamespace="urn:un:
> unece:uncefact:documentation:standard:CoreComponentType:2" 
elementFormDefault
> ="qualified" attributeFormDefault="unqualified" version="2.0">
> <xsd:complexType name="TextType">
> <xsd:simpleContent>
> <xsd:extension base="xsd:string">
> <xsd:attribute name="languageLocaleID" type="xsd:token" use="optional"/>
> </xsd:extension>
> </xsd:simpleContent>
> </xsd:complexType>
> </xsd:schema>
> 
> Here is the fundamental code I am using, starting with a method 
> which takes the complex type, Sorry for the length, but my question 
> is where should I call getName() to obtain " "languageLocaleID" ?
> I obtain the Attr Uses from the complex type, get the Attr Decl from
> the Attr Use, and then the SimpleType from the Attr Decl - but 
> nowhere an I getting the name. I am using xerces 2_9_0.
> 
> private void processCTD(XSComplexTypeDefinition ctd) {
> System.out.println("\nprocessing complex type <"+ctd.getName()+">");
> 
> //get the Attribute Uses fro the complex type
> XSObjectList xsol=ctd.getAttributeUses();
> System.out.println("Number of Attribute Uses...."+xsol.getLength());
> for(int j=0;j<xsol.getLength();j++){
> XSAttributeUse attruse = (XSAttributeUse)xsol.item(j);
> System.out.println("attr use ns: "+attruse.getNamespace());
> System.out.println("attr use name: "+attruse.getName());
> System.out.println("attr use nsItem: "+attruse.getNamespaceItem());
> System.out.println("attr use type: "+ attruse.getType());
> System.out.println("attr use required: "+attruse.getRequired());
> System.out.println("attr use constraint value: "+attruse.
> getConstraintValue());//null?
> short consttype=attruse.getConstraintType();//Value Constraint: one 
> of default, fixed.
> try{
> Object actualvc=attruse.getActualVC();//Value Constraint: Binding 
> specific actual constraint value or null if the value is in error or
> there is no value constraint.
> if(actualvc!=null){
> System.out.println("attr use actual value constrint: 
"+actualvc.toString());
> }
> }catch(XSException e){ 
> e.printStackTrace();
> }
> try{
> short actualvalctype=attruse.getActualVCType();//The actual 
> constraint value built-in datatype, e.g. STRING_DT, SHORT_DT. If the
> type definition of this value is a list type definition, this method
> returns LIST_DT. If the type definition of this value is a list type
> definition whose item type is a union type definition, this method 
> returns LISTOFUNION_DT. To query the actual constraint value of the 
> list or list of union type definitions use itemValueTypes. If the 
> actualNormalizedValue is null, this method returns UNAVAILABLE_DT .
> }catch(XSException e){
> e.printStackTrace();
> }
> try{
> ShortList sl=attruse.getItemValueTypes();//In the case the actual 
> constraint value represents a list, i.e. the actualValueType is 
> LIST_DT, the returned array consists of one type kind which 
> represents the itemType. If the actual constraint value represents a
> list type definition whose item type is a union type definition, i.
> e. LISTOFUNION_DT, for each actual constraint value in the list the 
> array contains the corresponding memberType kind. For examples, see 
> ItemPSVI.itemValueTypes.
> if(sl!=null){
> for(j=0;j<sl.getLength();j++){
> short sh=sl.item(j);
> System.out.println("attr use short: "+sh);
> }
> }
> }catch(XSException e){
> e.printStackTrace();
> }
> 
> //get the declaration for the attribute use
> XSAttributeDeclaration attrdecl=attruse.getAttrDeclaration();
> //[attribute declaration]: provides the attribute declaration 
> itself, which will in turn determine the simple type definition used.
> short contype=attrdecl.getConstraintType();//Value constraint: one 
> of VC_NONE, VC_DEFAULT, VC_FIXED.
> String sconvalue=attrdecl.getConstraintValue();//Value constraint: 
> The constraint value with respect to the [type definition], otherwise 
null.
> System.out.println("attr decl value: "+sconvalue);//null ?
> try{
> Object obj=attrdecl.getActualVC();//Value Constraint: Binding 
> specific actual constraint value or null if the value is in error or
> there is no value constraint.
> }catch(XSException e){
> //XSException - NOT_SUPPORTED_ERR: Raised if the implementation does
> not support this method.
> e.printStackTrace();
> }
> try{
> short avalvct=attrdecl.getActualVCType();//The actual constraint 
> value built-in datatype, e.g. STRING_DT, SHORT_DT. If the type 
> definition of this value is a list type definition, this method 
> returns LIST_DT. If the type definition of this value is a list type
> definition whose item type is a union type definition, this method 
> returns LISTOFUNION_DT. To query the actual constraint value of the 
> list or list of union type definitions use itemValueTypes. If the 
> actualValue is null, this method returns UNAVAILABLE_DT.
> }catch(XSException e){
> //XSException - NOT_SUPPORTED_ERR: Raised if the implementation does
> not support this method.
> e.printStackTrace();
> }
> try{
> ShortList sl2=attrdecl.getItemValueTypes();//In the case the actual 
> constraint value represents a list, i.e. the actualValueType is 
> LIST_DT, the returned array consists of one type kind which 
> represents the itemType. If the actual constraint value represents a
> list type definition whose item type is a union type definition, i.
> e. LISTOFUNION_DT, for each actual constraint value in the list the 
> array contains the corresponding memberType kind. For examples, see 
> ItemPSVI.itemValueTypes.
> }catch(XSException e){
> //XSException - NOT_SUPPORTED_ERR: Raised if the implementation does
> not support this method.
> e.printStackTrace();
> }
> 
> XSSimpleTypeDefinition std= attrdecl.getTypeDefinition();//[type 
> definition]: A simple type definition.
> System.out.println("attr decl ns: "+std.getNamespace());
> System.out.println("attr decl name: "+std.getName());
> System.out.println("attr decl nsItem: "+std.getNamespaceItem());
> System.out.println("attr decl type: "+std.getType());
> 
> StringList slist=std.getLexicalEnumeration();
> System.out.println("attr decl simple type lexical enum stringlist 
> length "+slist.getLength());
> for(int k=0;k<slist.getLength();k++){
> String str=slist.item(k);
> System.out.println("a string list item: "+str);
> }
> 
> slist=std.getLexicalPattern();
> System.out.println("attr decl simple type lexical patterns 
> stringlist length "+slist.getLength());
> for(int k=0;k<slist.getLength();k++){
> String str=slist.item(k);
> System.out.println("a string list item: "+str);
> }
> }
> }
> 
> 
> My output from this function is:
> 
> processing complex type <TextType>
> Number of Attribute Uses....1
> attr use ns: null
> attr use name: null
> attr use nsItem: null
> attr use type: 4
> attr use required: false
> attr use constraint value: null
> attr decl value: null
> attr decl ns: http://www.w3.org/2001/XMLSchema
> attr decl name: token
> attr decl nsItem: null
> attr decl type: 3
> attr decl simple type lexical enum stringlist length 0
> attr decl simple type lexical patterns stringlist length 0
> 
> Any help on the correct way to obtain or process the attribute is 
> appreciated. Thank you.
> 
> Scott R. Hinkelman

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