uses the non-validating parser by default, but it can also activate validation.
Activating validation allows the application to tell whether the XML document contains the right tags or whether those tags are in the right sequence.
There are lots of tutorials online on doing this, but I was not able to find a way that satisfies all my constraints, which are as follows: -I don't know the scheme beforehand, I have a bunch of XML and XSD files and every XML contains information about the XSD it should conform to -The validatior should alter the stream the handler gets and insert the default values for optional attributes from the XSD if necessary -The current custom handler should be used I'm fairly new to this topic, so I can't preclude that I've stumbled over the solution without beeing aware of it, but I'm currently completely confused on how to do this.
Here is a minimum SSCCE, which should show the problem and related parts: package parser Test; import
XML Schema is an XML-based representation of the structure of an XML document.
Through its support for datatypes and namespaces, XML Schema has the potential to provide the standard structure for XML elements and attributes.
In other words, it can tell you whether the document is valid.
From the standpoint of an application that is interested in processing only the XML data, that is a good thing because the application is never bothered with white space that exists purely to make the XML file readable.
Your Content Handler will be notified of default values for optional attributes. Unfortunately, I'm still having problems with my implementation, since my parser does not accept my validator as content handler.
If it uses some custom mechanism, you may have to do a "prepass" reading (some of) the source file to discover the schema, then reading it again with the Validator Handler in place.
If the parser is not able find a schema or if the XML document does not conform to the schema, an error is raised.
Next, create an XMLSchema object from the schema document with which an XML document is to be validated.
Default Handler; public class Parser Test The tricky bit is that in order to create a Validator Handler, you need to know what schema is in use. If it uses the xsi:schema Location attribute, then you can (probably) get the Validator Handler to pick it up automatically.
You get this by creating a Schema Factory, calling its new Schema() method to compile a schema, and then calling Validator Handler() to create the Validator Handler. I know that the Validator Handler I postet in the SSCCE is just a dummy, but even the way you described in your last comment I still get the error I described in my SSCCE (the part written in comments).
I'm using a SAX parser with a custom handler to parse some XML files.
This works well so far, but I want to check more than only the well-formedness of the given file and use validation via an XSD Scheme, which also contains default values for optional attributes.
The Input Source object is created with an Input Stream object created from the example XML schema document,
As discussed before, we have used an Input Source object because most SAX implementations are Input Source based.