[Home] [By Thread] [By Date] [Recent Entries]


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


Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member