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 Thomas Cox <Th...@sas.com> on 2003/06/18 22:31:26 UTC

RE: Sample code to "introspect" schemas?

Karl,

Have you gotten any answers on this? 

I have the same problem - my requirements are to be able to introspect (love that word choice, BTW) a collection of 30+ nested schemata and display them in a single tree, with a separate pane displaying the properties of the selected entity. 

BTW, can anyone point me to the documentation for the features and properties supported by XMLGrammarPreparser? Hoping there will be something there to help me out...

Right now we're stuck at 2.2.1, and I can't see any nested items. The good news is that I can move up to the latest available that will ship by 4Q 2003 for this feature.

Thanks,
Thomas Cox

> -----Original Message-----
> From: Karl Mueller [mailto:karl@quotetech.com] 
> Sent: Wednesday, June 04, 2003 1:32 PM
> To: xerces-j-user@xml.apache.org
> Subject: Sample code to "introspect" schemas?
> 
> 
> Hi,
> 
> This has already been proffered but I just checked the 
> archives and they are not available.
> 
> Does anyone know where I can get some code sample to 
> "introspect" schemas? I need to introspect a schema in order 
> for me to  generate a correct XML document from it.
> 
> Briefly, I'm trying to introspect a schema (which is really 
> composed of a number of files (i.e., via includes)) and I'm 
> able to get the global elements, attributes etc. but I'm 
> unsure how go from there? That is how do I build the contents 
> of a complex type or element which itself might be composed 
> of child complex types etc? For example, I tried getting the 
> complex type content (i.e., method getEnclosingCTDefinition 
> ()) for the following element and it came back unexpectedly 
> (for me) as null:
> 
> <element name = "Customer">
> 	<complexType>
> 		<sequence>
> 			<element name = "FirstName" type = "string" />
> 			<element name = "MiddleInitial" type = 
> "string" />
> 			<element name = "LastName" type = "string" />
> 		</sequence>
> 	</complexType>
> </element>
> 
> 
> Here is a code snippet that gathers the schema grammar for me:
> 
> 	XMLSchemaLoader xmlSchemaLoader = new XMLSchemaLoader();
> 	xmlSchemaLoader.setErrorHandler (this);
> 
> 	XMLInputSource xmlInputSource = new XMLInputSource 
> (null, schemaFile.
> 	  getName (), schemaFile.toURI ().getPath ());
> 
> 	FileInputStream inputStream = null;
> 	try
> 	{
> 		inputStream = new FileInputStream (schemaFile);
> 	}
> 	catch (Exception pException) { pException.printStackTrace (); }
> 
> 	xmlInputSource.setByteStream (inputStream);
> 
> 	XSGrammar schemaGrammar = null;
> 	try
> 	{
> 		schemaGrammar = (XSGrammar) 
> xmlSchemaLoader.loadGrammar (
> 		  xmlInputSource);
> 		XSModel schemaModel = schemaGrammar.toXSModel();
> 
> 		XSNamedMap elementComponents = 
> pSchemaModel.getComponents (
> 		  XSConstants.ELEMENT_DECLARATION);
> 		System.out.println ("Element components begin 
> (" + elementComponents.
> 		  getLength () + ")");
> 
> 		for (int i = 0; i < elementComponents.getLength (); i++)
> 		{
> 			XSElementDeclaration elementDeclaration 
> = (XSElementDeclaration)
> 		  	  elementComponents.item (i);
> 			System.out.println ("\tNamespace:Name: 
> " + elementDeclaration.
> 		  	  getNamespace () + ":" + 
> elementDeclaration.getName ());
> 			System.out.println ("\tConstraint 
> value: \"" + elementDeclaration.
> 		  	  getConstraintValue() + "\"");
> 
> 			System.out.println ("\tType def name: 
> \"" + elementDeclaration.
> 		  	  getTypeDefinition().getName () + "\"");
> 
> 			if 
> (elementDeclaration.getEnclosingCTDefinition() != null)
> 			{
> 				System.out.println 
> ("\tEnclosing ct type def name: \"" +
> 				  
elementDeclaration.getEnclosingCTDefinition> ().getParticle ().
> 				  getName () + "\"");
> 			}
> 			else
> 			{
> 				System.out.println ("\tNo 
> complex type definition...");
> 			}
> 
> 			System.out.println ();
> 		}
> 		System.out.println ("Element components end...\n");
> 	}
> 	catch (Exception pException)
> 	{
> 		pException.printStackTrace ();
> 	}
> 
> One final note: as I mentioned above my schema is really 
> composed of a number of files which are brought together by 
> "include" statements and I'm hoping that all I need to do is 
> point Xerces to my "lead" .xsd file and that all the included 
> files will automatically be brought in.
> 
> Thanks.
> 
> _____________________________________________
> Karl R. Mueller
> Karl@quotetech.com _____________________________________________
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
> 
> 

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


Re: Sample code to "introspect" schemas?

Posted by Bob Schloss <rs...@us.ibm.com>.



http://www.eclipse.org/XSD is an open-source Java library which allows your
program to read, create, or alter W3C XML Schemas, and attempts to model
accurately every concept found in the W3C XML Schema language.  It is
usable by tools that do not run in the Eclipse IDE, although it pre-reqs
about 3 other JAR files which provide underlying support (e.g. EMF
runtime).

Bob




                                                                                                                                 
                      "Jeff Greif"                                                                                               
                      <jgreif@alumni.pri        To:       <xe...@xml.apache.org>                                         
                      nceton.edu>               cc:                                                                              
                                                Subject:  Re: Sample code to "introspect" schemas?                               
                      06/18/2003 04:42                                                                                           
                      PM                                                                                                         
                      Please respond to                                                                                          
                      xerces-j-user                                                                                              
                                                                                                                                 




See http://xml.apache.org/xerces2-j/faq-grammars.html#faq-5 for traversing
XML Schema grammars, and the docs for the XSModel and related classes.
Remember to set the parser configuration to use PSVI DOM implementation.

This stuff should do the right thing for schemas that <include> others.

There is another tool associated with the Eclipse development environment
project, but I don't have a reference.

Jeff


----- Original Message -----
From: "Thomas Cox" <Th...@sas.com>
To: <xe...@xml.apache.org>; <ka...@quotetech.com>
Sent: Wednesday, June 18, 2003 1:31 PM
Subject: RE: Sample code to "introspect" schemas?


Karl,

Have you gotten any answers on this?

I have the same problem - my requirements are to be able to introspect
(love
that word choice, BTW) a collection of 30+ nested schemata and display them
in a single tree, with a separate pane displaying the properties of the
selected entity.

BTW, can anyone point me to the documentation for the features and
properties supported by XMLGrammarPreparser? Hoping there will be something
there to help me out...

Right now we're stuck at 2.2.1, and I can't see any nested items. The good
news is that I can move up to the latest available that will ship by 4Q
2003
for this feature.

Thanks,
Thomas Cox

> -----Original Message-----
> From: Karl Mueller [mailto:karl@quotetech.com]
> Sent: Wednesday, June 04, 2003 1:32 PM
> To: xerces-j-user@xml.apache.org
> Subject: Sample code to "introspect" schemas?
>
>
> Hi,
>
> This has already been proffered but I just checked the
> archives and they are not available.
>
> Does anyone know where I can get some code sample to
> "introspect" schemas? I need to introspect a schema in order
> for me to  generate a correct XML document from it.
>
> Briefly, I'm trying to introspect a schema (which is really
> composed of a number of files (i.e., via includes)) and I'm
> able to get the global elements, attributes etc. but I'm
> unsure how go from there? That is how do I build the contents
> of a complex type or element which itself might be composed
> of child complex types etc?


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




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


Re: Sample code to "introspect" schemas?

Posted by Jeff Greif <jg...@alumni.princeton.edu>.
See http://xml.apache.org/xerces2-j/faq-grammars.html#faq-5 for traversing
XML Schema grammars, and the docs for the XSModel and related classes.
Remember to set the parser configuration to use PSVI DOM implementation.

This stuff should do the right thing for schemas that <include> others.

There is another tool associated with the Eclipse development environment
project, but I don't have a reference.

Jeff


----- Original Message ----- 
From: "Thomas Cox" <Th...@sas.com>
To: <xe...@xml.apache.org>; <ka...@quotetech.com>
Sent: Wednesday, June 18, 2003 1:31 PM
Subject: RE: Sample code to "introspect" schemas?


Karl,

Have you gotten any answers on this?

I have the same problem - my requirements are to be able to introspect (love
that word choice, BTW) a collection of 30+ nested schemata and display them
in a single tree, with a separate pane displaying the properties of the
selected entity.

BTW, can anyone point me to the documentation for the features and
properties supported by XMLGrammarPreparser? Hoping there will be something
there to help me out...

Right now we're stuck at 2.2.1, and I can't see any nested items. The good
news is that I can move up to the latest available that will ship by 4Q 2003
for this feature.

Thanks,
Thomas Cox

> -----Original Message-----
> From: Karl Mueller [mailto:karl@quotetech.com]
> Sent: Wednesday, June 04, 2003 1:32 PM
> To: xerces-j-user@xml.apache.org
> Subject: Sample code to "introspect" schemas?
>
>
> Hi,
>
> This has already been proffered but I just checked the
> archives and they are not available.
>
> Does anyone know where I can get some code sample to
> "introspect" schemas? I need to introspect a schema in order
> for me to  generate a correct XML document from it.
>
> Briefly, I'm trying to introspect a schema (which is really
> composed of a number of files (i.e., via includes)) and I'm
> able to get the global elements, attributes etc. but I'm
> unsure how go from there? That is how do I build the contents
> of a complex type or element which itself might be composed
> of child complex types etc?


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