Chris Simmons <[EMAIL PROTECTED]> wrote on 02/28/2007 06:36:49 AM: > Hi all, > > I'd like to be able to have attributes defaulted according to a schema > grammar when I create a new element or at least when I add it to the > DOM. The only way I can see of doing this at the minute is to call > Document.normalizeDocument() having configured it it to perform schema > validation. This seems like overkill when you consider that our > documents contain literally thousands of nodes. > > You can't do this manually through the DOM interfaces as there's no > public setter corresponding with Attr.getSpecified() plus you'd have to > do something very similar to the schema validator. > > Is there a better way of doing this?
You can probably get away with validating a subtree. You can do that with the JAXP 1.3 validation API [1]. Something like: Element elem = ...; SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); ... Schema schema = factory.newSchema(...); Validator validator = schema.newValidator(); validator.validate(new DOMSource(elem), new DOMResult(elem)); This will augment the given element node and its descendants with default attributes, type info, etc... > Regards, > > Chris Simmons. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] [1] http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/validation/package-summary.html Michael Glavassevich XML Parser Development IBM Toronto Lab E-mail: [EMAIL PROTECTED] E-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]