Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Node Level Validation error

From: "Albert Yu" <albert.yu@----.-->
To: <xml-dev@-----.---.--->
Date: 3/2/2004 4:39:00 PM
Hi,

I am trying MSV package msv.20030225.zip to to do "Node
Level Validation"

The DOMVerifier example actually does not work on "Node
Level".
See the comments below in the code.

Does anybody have the same problem and know a solution?

public class DOMVerifier {

    public static void main(String[] args) throws Exception
{
        if (args.length < 2) {
            System.out.println("Usage: DOMVerifier <schema>
<instance> ...");
            return;
        }

        // setup JARV and compile a schema.
        VerifierFactory factory = new
com.sun.msv.verifier.jarv.TheFactoryImpl();
        Verifier verifier =
factory.compileSchema(args[0]).newVerifier();
        // instead, you can call
factory.newVerifier(args[0])
        // this will result in the same behavior.

        // setup JAXP
        DocumentBuilderFactory domf =
DocumentBuilderFactory.newInstance();
        domf.setNamespaceAware(true);
        DocumentBuilder builder = domf.newDocumentBuilder();

        for (int i = 1; i < args.length; i++) {
            // parse a document into a DOM.
            Document dom = builder.parse(new File(args[i]));

            // performs the validation on the whole tree.
            // instead, you can pass an Element to the
verify method, too.
            // e.g.,
verifier.verify(dom.getDocumentElement())
            if (verifier.verify(dom))
                System.out.println("valid  :" + args[i]);
            else
                System.out.println("invalid:" + args[i]);


            // or you can pass an Element to validate that
subtree

            //No, that does not work

            //For example, if you try the following code
            // you always get an exception saying
            //tag name xxxxx is not allowed. Possible tag
names are: ...

            if
(verifier.verify(dom.getFirstChild().getFirstChild()))
                System.out.println("valid  " );
            else
                System.out.println("invalid" );



        }
    }
}



Albert


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent