dakkar 0 Newbie Poster

I've a problem with some code, this is the "core" of the code:

File xmldocFile = new File(xmlFile);
              File schemaFile = new File(xsdFile);

              try
              {
                 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                 dbf.setValidating(true);
                 SchemaFactory sf = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
                 Schema mySchema = sf.newSchema(schemaFile);
                 dbf.setSchema(mySchema);

                 DocumentBuilder db = dbf.newDocumentBuilder();
                 ErrorChecker errors = new ErrorChecker();
                 db.setErrorHandler(errors);

                 db.parse(xmldocFile);
              }
              catch (Exception e)
              {
                    System.out.print("[Parsing]=================================================================");
                    System.out.println("Error: " + e);
                    System.out.print("==========================================================================");
              }

and this is the output error when I run it on a couple of example files:


H:\_java_prove_>java SchemaTest xeno08x.xml xeno08x.xsd
XML File:xeno08x.xml
XSD File:xeno08x.xsd
=> Line [2] -----------------------------------
Document root element "record", must match DOCTYPE root "null".
-----------------------------------------------------------------------
=> Line [2] -----------------------------------
Document is invalid: no grammar found.
-----------------------------------------------------------------------
=> Line [2] -----------------------------------
http://www.w3.org/TR/xml-schema-1#cvc-complex-type.3.2.2?record&xsi:noNamespaceS
chemaLocation
-----------------------------------------------------------------------
=> Line [2] -----------------------------------
http://www.w3.org/TR/xml-schema-1#cvc-complex-type.3.2.2?record&xsi:noNamespaceS
chemaLocation
-----------------------------------------------------------------------


I've tried various changes, but I don't find the error :_(

Can anyone help me?

TYIA

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.