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 Brent Halsey <br...@gmail.com> on 2007/11/20 23:48:48 UTC

Help navigating schema

My ultimate goal is to take a schema and generate a blank XML
template.  From there I'd like to create a web based form that
validates data based on the rules outlined in the schema.

My schema looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.someplace.com/SOMEPLACE"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.someplace.com/SOMEPLACE"
elementFormDefault="qualified" attributeFormDefault="unqualified">
       <xs:include schemaLocation="./Some_Aggregates.xsd"/>
       <xs:include schemaLocation="./Some_Types.xsd"/>
       <xs:element name="SomeRq">
               <xs:complexType>
                       <xs:sequence>
                               <xs:element ref="SomeID"/>
                               <xs:element ref="SomeIdInfo" minOccurs="0"/>
                               <xs:element ref="SomeInfo"/>
                       </xs:sequence>
               </xs:complexType>
       </xs:element>
       <xs:element name="SomeRs">
               <xs:complexType>
                       <xs:sequence>
                               <xs:element ref="SomeStatus"/>
                               <xs:element ref="SomeID"/>
                               <xs:element ref="SomeIdRec" minOccurs="0"/>
                       </xs:sequence>
               </xs:complexType>
       </xs:element>
</xs:schema>

>From this schema, I should be able to create XML for SomeRq and/or SomeRs.

I've got the following java code:

XSModel model = schemaLoader.loadURI(argv[0]);
if (model != null) {
XSNamedMap ccomponents = model.getComponents(XSTypeDefinition.COMPLEX_TYPE);
int complexcount = ccomponents.getLength();
XSComplexTypeDefinition complexType = null;
XSParticle particle = null;
for (int i = 0; i < complexcount; i++)
{
        complexType = (XSComplexTypeDefinition)ccomponents.item(i);
        System.out.println("name: " + complexType.getName() +
complexType.getParticle());
}



This code prints out information on the complex types included in
<xs:include schemaLocation="./Some_Types.xsd"/>, but not in SomeRq or
SomeRs...

I am having a difficult time understanding the API for Xerces-J for
schemas and haven't found many examples outside of the QueryXS that
comes with the most recent version of Xerces.

Any help you can provide me with would be great!

Thanks,

Brent

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


Re: Help navigating schema

Posted by Jeff Greif <je...@gmail.com>.
The components that are accessible from model.getComponents() are those 
at top-level in the schema, the global elements and named type 
definitions (children of the xs:schema element).  You asked only for the 
complex type definitions (the named ones), not also for the global 
elements.  If you ask for the global elements also, you can each one's 
type by a method on ElementDecl or something similar.

Jeff

Brent Halsey wrote:
> My ultimate goal is to take a schema and generate a blank XML
> template.  From there I'd like to create a web based form that
> validates data based on the rules outlined in the schema.
>
> My schema looks like this:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema targetNamespace="http://www.someplace.com/SOMEPLACE"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns="http://www.someplace.com/SOMEPLACE"
> elementFormDefault="qualified" attributeFormDefault="unqualified">
>        <xs:include schemaLocation="./Some_Aggregates.xsd"/>
>        <xs:include schemaLocation="./Some_Types.xsd"/>
>        <xs:element name="SomeRq">
>                <xs:complexType>
>                        <xs:sequence>
>                                <xs:element ref="SomeID"/>
>                                <xs:element ref="SomeIdInfo" minOccurs="0"/>
>                                <xs:element ref="SomeInfo"/>
>                        </xs:sequence>
>                </xs:complexType>
>        </xs:element>
>        <xs:element name="SomeRs">
>                <xs:complexType>
>                        <xs:sequence>
>                                <xs:element ref="SomeStatus"/>
>                                <xs:element ref="SomeID"/>
>                                <xs:element ref="SomeIdRec" minOccurs="0"/>
>                        </xs:sequence>
>                </xs:complexType>
>        </xs:element>
> </xs:schema>
>
> >From this schema, I should be able to create XML for SomeRq and/or SomeRs.
>
> I've got the following java code:
>
> XSModel model = schemaLoader.loadURI(argv[0]);
> if (model != null) {
> XSNamedMap ccomponents = model.getComponents(XSTypeDefinition.COMPLEX_TYPE);
> int complexcount = ccomponents.getLength();
> XSComplexTypeDefinition complexType = null;
> XSParticle particle = null;
> for (int i = 0; i < complexcount; i++)
> {
>         complexType = (XSComplexTypeDefinition)ccomponents.item(i);
>         System.out.println("name: " + complexType.getName() +
> complexType.getParticle());
> }
>
>
>
> This code prints out information on the complex types included in
> <xs:include schemaLocation="./Some_Types.xsd"/>, but not in SomeRq or
> SomeRs...
>
> I am having a difficult time understanding the API for Xerces-J for
> schemas and haven't found many examples outside of the QueryXS that
> comes with the most recent version of Xerces.
>
> Any help you can provide me with would be great!
>
> Thanks,
>
> Brent
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
>
>
>
>   


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