If you went the Schema route, you would have to
1) Load the .xsd file into the object model.
2) poke around for all the stuff you need.
Step 1) is easy. The code you need is at the end of this email.
It came directly from SourceGenerator.
I've never messed around with step two, but here's what I'd do:
Start by invoking either Schema.getComplexTypes()
or Schema.getElementDecls(), whichever you need.
Then drill down to find what you need. I don't know much beyond that.
SchemaUnmarshaller schemaUnmarshaller = null;
try {
schemaUnmarshaller = new SchemaUnmarshaller();
} catch (XMLException e) {
e.printStackTrace();
}
Sax2ComponentReader handler = new
Sax2ComponentReader(schemaUnmarshaller);
parser.setDocumentHandler(handler);
parser.setErrorHandler(handler);
try {
parser.parse(source);
}
catch(java.io.IOException ioe) {
System.out.println("error reading XML Schema file");
return;
}
catch(org.xml.sax.SAXException sx) {
Exception except = sx.getException();
if (except == null) except = sx;
if (except instanceof SAXParseException) {
SAXParseException spe = (SAXParseException)except;
System.out.println("SAXParseException: " + spe);
System.out.print(" - occured at line ");
System.out.print(spe.getLineNumber());
System.out.print(", column ");
System.out.println(spe.getColumnNumber());
}
else except.printStackTrace();
return;
}
Schema schema = schemaUnmarshaller.getSchema();
//John, this is where you drill down to find
//the stuff you need (step 2) , above).
> -----Original Message-----
> From: John Thorhauer [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, November 21, 2002 12:43 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [castor-dev] gettng schema info from a
> TypeValidator
>
>
> On Thu, 2002-11-21 at 12:31, [EMAIL PROTECTED] wrote:
> > John,
> >
> > Have you considered querying
> org.exolab.castor.xml.schema.Schema
> > for the schema rules instead of the generated source?
>
> Well, the problems with working directly with the
> schema is that I need
> to only get a subsection of the schema and that
> subsection is much
> easier to determine based on the object model and not the schema
> itself. This is why I am looking at trying to use the
> object model
> instead.
>
> So for example I have a schema that looks something like this:
>
> <xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema"
> elementFormDefault = "qualified"
> attributeFormDefault = "unqualified">
>
> <xs:include schemaLocation = "included-schema.xsd"/>
>
> <xs:element name = "PurchaseOrder">
> <xs:complexType>
> <xs:sequence>
> <xs:element ref = "PurchaseOrderHeader"/>
> <xs:element ref = "PurchaseOrderLineItem"/>
> <xs:element ref = "PurchaseOrderSummary"/>
> </xs:sequence>
> </xs:element>
>
> </xs:schema>
>
>
> Now the above included schema called
> included-schema.xsd has a lot of
> stuff that i dont care about in terms of a
> PurchaseOrder so I figured
> that the easiest way to get the validation information
> for only the
> PurchaseOrder is to load the PurchaseOrderDescriptor
> that was generated
> and work with that as it will only contain the subset
> of descriptors
> that I need. Is there a better way to accomplish this?
>
>
> Thanks,
> John
> --
> ********************************
> ** John Thorhauer
> ** [EMAIL PROTECTED]
> ** take a look at:
> ** http://tambora.zenplex.org
> ** http://www.zenplex.org
> ** http://www.zenplex.com
> ********************************
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
>
>
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev