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 Huzefa Hakimi <ha...@yahoo.com> on 2003/12/11 19:24:49 UTC

XML Schema and Xerces 2-J

Hi folks,

I had couple of doubts regarding XML Schema Processing
processing.

1. When validation is turned on, does the
SchemaGrammer which is been loaded is the grammer
constructed from XML Schema or is it directly
constructed from XML Document without parsing XML
Schema.

2. Secondly I am assuming the SchemaGrammer is
constructed from XML Schema  defined in XML Document.
I am trying to gather information about all the
elements and attributes defined in Schema which are
also present in XML Document. Problem comes when I try
to collect information about attributes present from
XSModel instance obtained from ElementPSVI, it returns
no attribute information. Although both in Schema and
XML document the attributes are defined. below is code
snippet I am using to achieve this. Can anyone help me
out in figuring out the problem.

-----------------------------------------------------

ElementPSVI elementPSVI =
psviProvider.getElementPSVI();
XSModel xsmodel = elementPSVI.getSchemaInformation();

// This works fine for Element information

XSNamedMap xsMap =
xsmodel.getComponents(XSConstants.ELEMENT_DECLARATION);

for(int i = 0; i < xsMap.getLength(); i++){
    
    String name = xsMap.item(i).getName();
.
.
.
}

// But when try to get information about attributes 
// it does not get "any" attribute information

xsMap =
xsmodel.getComponents(XSConstants.ATTRIBUTE_DECLARATION);

for(int i = 0; i < xsMap.getLength(); i++){
            String name = xsMap.item(i).getName();
.
.
.
}
....

-----------------------------------------------------

Thanks for going through this and getting involved.

-Huzefa

__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

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


Re: XML Schema and Xerces 2-J

Posted by Maksym Kovalenko <mk...@marketswitch.com>.
To get attributes of the particular element use


       private org.apache.xerces.impl.xs.psvi.XSElementDeclaration 
elementDeclaration;

...

     public XSObjectList getAttributeUses()
    {
        XSTypeDefinition td = elementDeclaration.getTypeDefinition();
        if (td instanceof XSComplexTypeDefinition)
        {
            XSComplexTypeDefinition ctd = (XSComplexTypeDefinition) td;
            XSObjectList attrUses = ctd.getAttributeUses();
            return attrUses;
        }
        else
            return null;
    }


Code you use (xsmodel.getComponents(XSConstants.ATTRIBUTE_DECLARATION)) 
will return you top level info

Huzefa Hakimi wrote:

> Sorry forgot to attach the xml and schema file for the same. And found 
> the answer for first one. SchemaGrammer as name indicates is 
> constructed from XML Schema.
>  
> But second one is still unclear why this strange  behavior!
>  
> Thanks
>  
> -Huzefa
> Huzefa Hakimi <ha...@yahoo.com> wrote:
>
>     Hi folks,
>
>     I had couple of doubts regarding XML Schema Processing
>     processing.
>
>     1. When validation is turned on, does the
>     SchemaGrammer which is been loaded is the grammer
>     constructed from XML Schema or is it directly
>     constructed from XML Document without parsing XML
>     Schema.
>
>     2. Secondly I am assuming the SchemaGrammer is
>     constructed from XML Schema defined in XML Document.
>     I am trying to gather information about all the
>     elements and attributes defined in Schema which are
>     also present in XML Document. Problem comes when I try
>     to collect information about attributes present from
>     XSModel instance obtained from ElementPSVI, it returns
>     no attribute information. Although both in Schema and
>     XML document the attributes are defined. below is code
>     snippet I am using to achieve this. Can anyone help me
>     out in figuring out the problem.
>
>     -----------------------------------------------------
>
>     ElementPSVI elementPSVI =
>     psviProvider.getElementPSVI();
>     XSModel xsmodel = elementPSVI.getSchemaInformation();
>
>     // This works fine for Element information
>
>     XSNamedMap xsMap =
>     xsmodel.getComponents(XSConstants.ELEMENT_DECLARATION);
>
>     for(int i = 0; i < xsMap.getLength(); i++){
>
>     String name = xsMap.item(i).getName();
>     .
>     .
>     .
>     }
>
>     // But when try to get information about attributes
>     // it does not get "any" attribute information
>
>     xsMap =
>     xsmodel.getComponents(XSConstants.ATTRIBUTE_DECLARATION);
>
>     for(int i = 0; i < xsMap.getLength(); i++){
>     String name = xsMap.item(i).getName();
>     .
>     .
>     .
>     }
>     ....
>
>     -----------------------------------------------------
>
>     Thanks for going through this and getting involved.
>
>     -Huzefa
>
>     __________________________________
>     Do you Yahoo!?
>     Free Pop-Up Blocker - Get it now
>     http://companion.yahoo.com/
>
>     ---------------------------------------------------------------------
>     To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
>     For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
> ------------------------------------------------------------------------
> Do you Yahoo!?
> Free Pop-Up Blocker - Get it now 
> <http://us.rd.yahoo.com/slv/mailtag/*http://companion.yahoo.com/>
>
>------------------------------------------------------------------------
>
><?xml version="1.0" encoding="UTF-8"?>
><xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
>
> <xs:element name="personnel">
>  <xs:complexType>
>   <xs:sequence>
>     <xs:element ref="person" minOccurs='1' maxOccurs='unbounded'/>
>   </xs:sequence>
>  </xs:complexType>
>
>  <xs:unique name="unique1">
>   <xs:selector xpath="person"/>
>   <xs:field xpath="name/given"/>
>   <xs:field xpath="name/family"/>
>  </xs:unique>
>  <xs:key name='empid'>
>   <xs:selector xpath="person"/>
>   <xs:field xpath="@id"/>
>  </xs:key>
>  <xs:keyref name="keyref1" refer='empid'>
>   <xs:selector xpath="person"/> 
>   <xs:field xpath="link/@manager"/>  
>  </xs:keyref>
>
> </xs:element>
>
> <xs:element name="person">
>  <xs:complexType>
>   <xs:sequence>
>     <xs:element ref="name"/>
>     <xs:element ref="email" minOccurs='0' maxOccurs='unbounded'/>
>     <xs:element ref="url"   minOccurs='0' maxOccurs='unbounded'/>
>     <xs:element ref="link"  minOccurs='0' maxOccurs='1'/>
>   </xs:sequence>
>   <xs:attribute name="id"  type="xs:ID" use='required'/>
>   <xs:attribute name="note" type="xs:string"/>
>   <xs:attribute name="contr" default="false">
>    <xs:simpleType>
>     <xs:restriction base = "xs:string">
>       <xs:enumeration value="true"/>
>       <xs:enumeration value="false"/>
>     </xs:restriction>
>    </xs:simpleType>
>   </xs:attribute>
>   <xs:attribute name="salary" type="xs:integer"/>
>  </xs:complexType>
> </xs:element>
>
> <xs:element name="name">
>  <xs:complexType>
>   <xs:all>
>    <xs:element ref="family"/>
>    <xs:element ref="given"/>
>   </xs:all>
>  </xs:complexType>
> </xs:element>
>
> <xs:element name="family" type='xs:string'/>
>
> <xs:element name="given" type='xs:string'/>
>
> <xs:element name="email" type='xs:string'/>
>
> <xs:element name="url">
>  <xs:complexType>
>   <xs:attribute name="href" type="xs:string" default="http://"/>
>  </xs:complexType>
> </xs:element>
>
> <xs:element name="link">
>  <xs:complexType>
>   <xs:attribute name="manager" type="xs:IDREF"/>
>   <xs:attribute name="subordinates" type="xs:IDREFS"/>
>  </xs:complexType>
> </xs:element>
>
> <xs:notation name='gif' public='-//APP/Photoshop/4.0' system='photoshop.exe'/>
>
></xs:schema>
>  
>
>------------------------------------------------------------------------
>
><?xml version="1.0" encoding="UTF-8"?>
><personnel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>	   xsi:noNamespaceSchemaLocation='personal.xsd'>
>
>  <person id="Big.Boss" >
>    <name><family>Boss</family>  </name>
>   <email>chief@foo.com</email>
>    <link subordinates="one.worker two.worker three.worker four.worker five.worker"/>
>  </person>
>
>  <person id="one.worker">
>    <name><family>Worker</family>     </name>
><email>one@foo.com</email>
>    <link manager="Big.Boss"/>
>  </person>
>
>  <person id="two.worker">
>    <name><family>Worker</family>     </name>
><email>two@foo.com</email>
>    <link manager="Big.Boss"/>
>  </person>
>
>  <person id="three.worker">
>    <name><family>Worker</family>     </name>
><email>three@foo.com</email>
>    <link manager="Big.Boss"/>
>  </person>
>
>  <person id="four.worker">
>    <name><family>Worker</family>     </name>
><email>four@foo.com</email>
>    <link manager="Big.Boss"/>
>  </person>
>
>  <person id="five.worker">
>    <name><family>Worker</family>     </name>
><email>five@foo.com</email>
>    <link manager="Big.Boss"/>
>  </person>
>
></personnel>
>
>  
>
>------------------------------------------------------------------------
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>

-- 
------------------------------------------------------------------------

Maksym Kovalenko
Software Engineer
Marketswitch Corporation
http://www.marketswitch.com <http://www.marketswitch.com/>
108 Powers Court, Suite 225
Dulles, VA 20166
Phone: +1 (703) 444-6750 ext. 302
Fax: +1 (703) 444-6812


Re: XML Schema and Xerces 2-J

Posted by Huzefa Hakimi <ha...@yahoo.com>.
Sorry forgot to attach the xml and schema file for the same. And found the answer for first one. SchemaGrammer as name indicates is constructed from XML Schema. 
 
But second one is still unclear why this strange  behavior!
 
Thanks
 
-Huzefa
Huzefa Hakimi <ha...@yahoo.com> wrote:
Hi folks,

I had couple of doubts regarding XML Schema Processing
processing.

1. When validation is turned on, does the
SchemaGrammer which is been loaded is the grammer
constructed from XML Schema or is it directly
constructed from XML Document without parsing XML
Schema.

2. Secondly I am assuming the SchemaGrammer is
constructed from XML Schema defined in XML Document.
I am trying to gather information about all the
elements and attributes defined in Schema which are
also present in XML Document. Problem comes when I try
to collect information about attributes present from
XSModel instance obtained from ElementPSVI, it returns
no attribute information. Although both in Schema and
XML document the attributes are defined. below is code
snippet I am using to achieve this. Can anyone help me
out in figuring out the problem.

-----------------------------------------------------

ElementPSVI elementPSVI =
psviProvider.getElementPSVI();
XSModel xsmodel = elementPSVI.getSchemaInformation();

// This works fine for Element information

XSNamedMap xsMap =
xsmodel.getComponents(XSConstants.ELEMENT_DECLARATION);

for(int i = 0; i < xsMap.getLength(); i++){

String name = xsMap.item(i).getName();
.
.
.
}

// But when try to get information about attributes 
// it does not get "any" attribute information

xsMap =
xsmodel.getComponents(XSConstants.ATTRIBUTE_DECLARATION);

for(int i = 0; i < xsMap.getLength(); i++){
String name = xsMap.item(i).getName();
.
.
.
}
....

-----------------------------------------------------

Thanks for going through this and getting involved.

-Huzefa

__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

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



---------------------------------
Do you Yahoo!?
Free Pop-Up Blocker - Get it now