<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1126" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV>
<DIV><FONT face=Arial size=2>Hi there:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>thanks for that very helpful information. The
only problem I'm having is the 3 parameters to XMLInputSource. What do I
use? You get yours from the DocType. I can't do that. I wrote
this:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial
size=2> String
schemaFile = "d:\\myschema.xsd";</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial
size=2>
org.apache.xerces.xni.parser.XMLInputSource in
=<BR>
new
org.apache.xerces.xni.parser.XMLInputSource(<BR>
schemaFile,<BR>
schemaFile,<BR>
schemaFile);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial
size=2>
in.setCharacterStream(new FileReader(schemaFile));</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial
size=2>
org.apache.xerces.impl.xs.XMLSchemaLoader loader
=<BR>
new org.apache.xerces.impl.xs.XMLSchemaLoader();</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial
size=2>
org.apache.xerces.xni.grammars.Grammar grammar =
loader.loadGrammar(in);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial
size=2>
org.apache.xerces.xni.grammars.XSGrammar xsgrammar
=<BR>
(org.apache.xerces.xni.grammars.XSGrammar)grammar;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial
size=2>
org.apache.xerces.impl.xs.psvi.XSModel xsmodel =
xsgrammar.toXSModel();<BR></FONT></DIV></DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=kellefsen@bergen.oilfield.slb.com
href="mailto:kellefsen@bergen.oilfield.slb.com">Kenneth Ellefsen</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=p.beauvoir@bolton.ac.uk
href="mailto:p.beauvoir@bolton.ac.uk">Phillip Beauvoir</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Cc:</B> <A title=jdom-interest@jdom.org
href="mailto:jdom-interest@jdom.org">jdom-interest@jdom.org</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Friday, November 29, 2002 12:47
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> Re: [jdom-interest] JDOM and XML
Schema</DIV>
<DIV><BR></DIV>Hi,<BR><BR>I ended up reinventing the wheel when I needed to
use my DTD file...<BR><BR>Maby the difference between DTD/schema isn't that
big...<BR><BR>Anyway, if it helps....<BR><BR><BR>I have now made the following
piece of code that solves my problem with<BR>retreving a DTD enumeration of
valid values for a given attribute.<BR><BR>Posting it here in case someone
else can have a use for it.<BR><BR><BR><BR>// e is an org.jdom.Element<BR>//
replace sertain static strings as you need<BR><BR><BR>org.jdom.DocType dt =
e.getDocument().getDocType();<BR><BR><BR>// Load and parse the DTD
file...<BR><BR>org.apache.xerces.impl.dtd.XMLDTDLoader dtdloader =<BR>new
org.apache.xerces.impl.dtd.XMLDTDLoader();<BR>
<BR>org.apache.xerces.xni.parser.XMLInputSource input =<BR>new
org.apache.xerces.xni.parser.XMLInputSource(<BR>
dt.getPublicID(),<BR>
"/full/path/to/dtdfile/"+dt.getSystemID(),<BR> //^^this is the
absolute path to the dtd file^^<BR>
dt.getSystemID());<BR> <BR>org.apache.xerces.impl.dtd.DTDGrammar
grammar = null;<BR>try{<BR> grammar
=(org.apache.xerces.impl.dtd.DTDGrammar)<BR>
dtdloader.loadGrammar(input);<BR>}<BR>catch(Exception ex){<BR>
System.out.println("Error when reading DTD:\n\n"+ex);<BR>
return;<BR>}<BR><BR><BR>// And now for the interesting part where<BR>// we
search for the element/attribute name in the
DTD<BR><BR>org.apache.xerces.impl.dtd.XMLAttributeDecl att = <BR>new
org.apache.xerces.impl.dtd.XMLAttributeDecl();<BR><BR>org.apache.xerces.impl.dtd.XMLElementDecl
elm = <BR>new
org.apache.xerces.impl.dtd.XMLElementDecl();<BR>
<BR>String[] enum = null;<BR>String elmName =
e.getName();<BR><BR> <BR>int i =
grammar.getFirstElementDeclIndex();<BR><BR>while(
grammar.getElementDecl(i,elm)
&&<BR>
!elm.name.localpart.equals(elmName) )<BR>{<BR> i =
grammar.getNextElementDeclIndex(i);<BR>}<BR><BR>
<BR>int j =
grammar.getFirstAttributeDeclIndex(i);<BR>
<BR>while( grammar.getAttributeDecl(j, att)
&&<BR>
!att.name.localpart.equals("value") )<BR>{<BR> j =
grammar.getNextAttributeDeclIndex(j);<BR>}<BR><BR>enum =
att.simpleType.enumeration;<BR><BR>// enum - contains ether null, or a
String[] representing<BR>// the (value1|value2|value3) definition of attribute
"value"<BR>// for the element in question<BR><BR><BR><BR><BR>On Fri,
2002-11-29 at 13:01, Phillip Beauvoir wrote:<BR>> Hi there!<BR>>
<BR>> Sorry if this has been asked before.<BR>> <BR>> I'm loading an
XML Schema file into a JDOM document and then trying to create a hierarchical
model with accessor methods to query various parts of the Schema to control an
XML Editor. Then I realise that surely somebody must have done this
already? Basically I want to:<BR>> <BR>> 1. Read the XML
Schema into a JDOM Document (easy, I can do this)<BR>> 2. Write an
API to access the Schema Elements, Constraints, etc.<BR>> <BR>> Anybody
know if this has been done already, saving me re-inventing the wheel?<BR>>
<BR>> Cheers!<BR>> <BR>> Phil Beauvoir<BR>-- <BR>Mvh,<BR><BR>Kenneth
Ellefsen
| Tlf: (+47) 55985829<BR>Schlumberger Information Solutions | <A
href="http://www.sis.slb.com">www.sis.slb.com</A><BR><BR><BR></BLOCKQUOTE></BODY></HTML>