Hi Alex, Alex Talis <[EMAIL PROTECTED]> wrote on 10/28/2008 12:58:21 PM:
> I noticed that too. A few things seem to work better when the > document is processed by the SAX parser. Line and column numbers is > one example. The DOM API provides no methods for getting line/column numbers so they're not available to the validator when DOM is the input. Even if they were such information would gradually become misleading/meaningless if you start mutating the DOM after its loaded. > PSVI augmentation and access to PSVI is another > example. If I call setSchema method on DocumentBuilderFactory > before parsing my XML file, every node in the DOM will have PSVI > information (see code below if my description isn't clear enough). > However, if I do not validate during load, but use a Validator > afterwards, PSVI is not augmented. It is if you provide a DOMResult to the Validator. I'm guessing you're not doing that. If the node objects specified in the DOMSource and DOMResult are the same the Validator will augment the input. If you don't want the input DOM to be mutated you could specify a fresh Document (needs to be the PSVI implementation, i.e. "org.apache.xerces.dom.PSVIDocumentImpl") as the DOMResult. This result will also contain the PSVI. > Also, even though the Validator > implements PSVIProvider, all calls on this provider return null. I > see it checking internally if it's using a SAX Validator, and if it > isn't, it returns null. PSVIProvider can only be used with streaming APIs such as SAX. When the input to the Validator is DOM your application never gets control at the points where it is valid to query it. > // Load schema doc. > SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants. > W3C_XML_SCHEMA_NS_URI); > schemaFactory.setFeature("http://apache. > org/xml/features/validation/schema/augment-psvi", true); > Schema schema = schemaFactory.newSchema(new StreamSource(new File( > "C:/work/XML/AgentConfiguration.xsd"))); > > // Load XML doc. > DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); > factory.setAttribute("http://apache.org/xml/properties/dom/document-class-name > ", "org.apache.xerces.dom.PSVIDocumentImpl"); > factory.setNamespaceAware(true); > factory.setValidating(true); > factory.setSchema(schema); > DocumentBuilder parser = factory.newDocumentBuilder(); > Document document = parser.parse("C:/work/XML/AgentConfigurationTemplate.xml" > ); Thanks. Michael Glavassevich XML Parser Development IBM Toronto Lab E-mail: [EMAIL PROTECTED] E-mail: [EMAIL PROTECTED]