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 Lingzhi Zhang <lz...@cse.ogi.edu> on 2003/07/14 23:31:40 UTC

examine XML Schema

Hi,

I am wondering the way to examine XML Schema and retrieve useful
information to build my own representations of the Schema for my
application. Specificially, I wish to extract the child(children) and
parent of types defined in the Schema. For example, if there is a schema
like

type book {title, year, authors, ISBN},

how to get the children (title, year, author, ISBN) of type book, and
how to find out that the parent of title, year, author, ISBN is book by
parsing the schema? I used the schema preparser and get an XSModel of the
schema, however, I couldn't find any method in ComplexTypeDefinition and
SimpleTypeDefinition interface which provides this functionality. Could
Xerces do this? and How to do it? Thanks.

Stephen


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


what is the validation mechanism against schema?

Posted by Lingzhi Zhang <lz...@cse.ogi.edu>.
Hi,

I am curious about the mechanism that Xerces validates an XML document 
against schema. For example, there is only tag in XML data, however, the
elemement name might be associated with a type definition in schema. How
does Xerces maps the tag name (element name) into type name and then
validate it with the type definition? Are there some convenient method
provide this functionlity in the API?

Another thing I am interested in is how Xerces determine definition of a
tag in XML document. The tag name corresponds to a element declaration
name in the schema. However, the same element declaration may appears
serveral places in the schema. So to find the declaration in schema needs
to check the context. In the worst case, the validat context may be almost
the whole document (e.g. two paths exactly the same from botton until they
reach the immediate child of root element). Is my understanding correct?

Thank.

Stephen



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


Re: examine XML Schema

Posted by Maksym Kovalenko <mk...@marketswitch.com>.
Something like this

    f1(XSElementDeclaration elementDeclaration)
    {
        XSTypeDefinition td = elementDeclaration.getTypeDefinition();
        if (td instanceof XSComplexTypeDefinition)
            traverseCTD((XSComplexTypeDefinition) td);
    }

    private void traverseCTD(XSComplexTypeDefinition ctd)
    {
        XSTerm term = ctd.getParticle().getTerm();
        if (term instanceof XSModelGroup)
        {
            XSModelGroup group = (XSModelGroup) term;
            XSObjectList particles = group.getParticles();
            for (int i = 0; i < particles.getLength(); i++)
            {
                XSParticle particle = (XSParticle) particles.item(i);
                XSTerm particleTerm = particle.getTerm();
                if (particleTerm instanceof XSElementDeclaration)
                {
                    XSElementDeclaration xsChildElementDeclaration = 
(XSElementDeclaration) particleTerm;
/*
* Here's your child. Process as you wish.
* I think some recursion is needed and example need to be changed to 
process schemas like the following, but you should get the idea
*        <xs:complexType>
*           <xs:sequence>
*                <xs:element name="a"/>
*                <xs:element name="b"/>
*                <xs:choice>
*                    <xs:element name="c"/>
*                    <xs:element name="d"/>
*                </xs:choice>
*            </xs:sequence>
*        </xs:complexType>
*/
                }
            }
        }
    }


Lingzhi Zhang wrote:

>Hi,
>
>I am wondering the way to examine XML Schema and retrieve useful
>information to build my own representations of the Schema for my
>application. Specificially, I wish to extract the child(children) and
>parent of types defined in the Schema. For example, if there is a schema
>like
>
>type book {title, year, authors, ISBN},
>
>how to get the children (title, year, author, ISBN) of type book, and
>how to find out that the parent of title, year, author, ISBN is book by
>parsing the schema? I used the schema preparser and get an XSModel of the
>schema, however, I couldn't find any method in ComplexTypeDefinition and
>SimpleTypeDefinition interface which provides this functionality. Could
>Xerces do this? and How to do it? Thanks.
>
>Stephen
>
>
>---------------------------------------------------------------------
>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