[From nobody Fri Aug 6 17:08:12 2004 Date: Mon, 02 Dec 2002 10:16:20 +0100 From: Kenneth Ellefsen <kellefsen@bergen.oilfield.slb.com> Subject: Re: [jdom-interest] JDOM and XML Schema In-reply-to: <016701c297c7$ce9a4ce0$cdca8f93@BijouLaptop> To: Phillip Beauvoir <p.beauvoir@bolton.ac.uk> Message-id: <1038820580.4723.24.camel@kenneth> MIME-version: 1.0 X-Mailer: Ximian Evolution 1.0.8 Content-type: text/plain Content-transfer-encoding: 7BIT References: <001601c2979f$0aca9cc0$cdca8f93@BijouLaptop> <1038574079.32287.65.camel@kenneth> <016701c297c7$ce9a4ce0$cdca8f93@BijouLaptop> Hi. this is just of the top of my head, but isn't int a URI? In which case you'll have to use "file:path", someone correct me if I'm wrong... Regards, Kenneth On Fri, 2002-11-29 at 17:53, Phillip Beauvoir wrote: > Hi there: > > 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: > > > String schemaFile = "d:\\myschema.xsd"; > > org.apache.xerces.xni.parser.XMLInputSource in = > new org.apache.xerces.xni.parser.XMLInputSource( > schemaFile, > schemaFile, > schemaFile); > > in.setCharacterStream(new FileReader(schemaFile)); > > org.apache.xerces.impl.xs.XMLSchemaLoader loader = > new org.apache.xerces.impl.xs.XMLSchemaLoader(); > > org.apache.xerces.xni.grammars.Grammar grammar = loader.loadGrammar(in); > > org.apache.xerces.xni.grammars.XSGrammar xsgrammar = > (org.apache.xerces.xni.grammars.XSGrammar)grammar; > > org.apache.xerces.impl.xs.psvi.XSModel xsmodel = xsgrammar.toXSModel(); > > ----- Original Message ----- > From: Kenneth Ellefsen > To: Phillip Beauvoir > Cc: jdom-interest@jdom.org > Sent: Friday, November 29, 2002 12:47 PM > Subject: Re: [jdom-interest] JDOM and XML Schema > > > Hi, > > I ended up reinventing the wheel when I needed to use my DTD file... > > Maby the difference between DTD/schema isn't that big... > > Anyway, if it helps.... > > > I have now made the following piece of code that solves my problem with > retreving a DTD enumeration of valid values for a given attribute. > > Posting it here in case someone else can have a use for it. > > > > // e is an org.jdom.Element > // replace sertain static strings as you need > > > org.jdom.DocType dt = e.getDocument().getDocType(); > > > // Load and parse the DTD file... > > org.apache.xerces.impl.dtd.XMLDTDLoader dtdloader = > new org.apache.xerces.impl.dtd.XMLDTDLoader(); > > org.apache.xerces.xni.parser.XMLInputSource input = > new org.apache.xerces.xni.parser.XMLInputSource( > dt.getPublicID(), > "/full/path/to/dtdfile/"+dt.getSystemID(), > //^^this is the absolute path to the dtd file^^ > dt.getSystemID()); > > org.apache.xerces.impl.dtd.DTDGrammar grammar = null; > try{ > grammar =(org.apache.xerces.impl.dtd.DTDGrammar) > dtdloader.loadGrammar(input); > } > catch(Exception ex){ > System.out.println("Error when reading DTD:\n\n"+ex); > return; > } > > > // And now for the interesting part where > // we search for the element/attribute name in the DTD > > org.apache.xerces.impl.dtd.XMLAttributeDecl att = > new org.apache.xerces.impl.dtd.XMLAttributeDecl(); > > org.apache.xerces.impl.dtd.XMLElementDecl elm = > new org.apache.xerces.impl.dtd.XMLElementDecl(); > > String[] enum = null; > String elmName = e.getName(); > > > int i = grammar.getFirstElementDeclIndex(); > > while( grammar.getElementDecl(i,elm) && > !elm.name.localpart.equals(elmName) ) > { > i = grammar.getNextElementDeclIndex(i); > } > > > int j = grammar.getFirstAttributeDeclIndex(i); > > while( grammar.getAttributeDecl(j, att) && > !att.name.localpart.equals("value") ) > { > j = grammar.getNextAttributeDeclIndex(j); > } > > enum = att.simpleType.enumeration; > > // enum - contains ether null, or a String[] representing > // the (value1|value2|value3) definition of attribute "value" > // for the element in question > > > > > On Fri, 2002-11-29 at 13:01, Phillip Beauvoir wrote: > > Hi there! > > > > Sorry if this has been asked before. > > > > 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: > > > > 1. Read the XML Schema into a JDOM Document (easy, I can do this) > > 2. Write an API to access the Schema Elements, Constraints, etc. > > > > Anybody know if this has been done already, saving me re-inventing the wheel? > > > > Cheers! > > > > Phil Beauvoir > -- > Mvh, > > Kenneth Ellefsen | Tlf: (+47) 55985829 > Schlumberger Information Solutions | www.sis.slb.com > > -- Mvh, Kenneth Ellefsen | Tlf: (+47) 55985829 Schlumberger Information Solutions | www.sis.slb.com ]