Java XML problems

Hello,
I am writing an app that loads an XML document as its config file. I keep gettin the following error when I run the program, and test the loading of XML. org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'root'.
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:236)
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:172)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:382)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:316)
        at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1944)
        at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:705)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:330)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(XMLNSDocumentScannerImpl.java:779)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1794)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
        at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:250)
        at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:292)
        at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:172)
        at config.loadXMLConfig(config.java:83)
        at config.<init>(config.java:41)
        at SMTP.main(SMTP.java:10)
I am new to XML in general, and have never attempted to code java xml before. I wrote most of this code based on the XML tutorials on sun's site. The correct fix is worth 500 points.

The XML Document:

<?xml version="1.0"?>
<root>
<!-- start of MailPro-LM Configuration -->
      <!-- basic system configuration options -->
      <basic>
            <system_mode>distributor</system_mode>
            <max_smtp_out>25</max_smtp_out>
            <max_retries>3</max_retries>
            <retry_after>10</retry_after>
            <log_path>/root/log.txt</log_path>
            <accounting_type>database</accounting_type>
            <accounting_path>/root/acct.txt</accounting_path>
            <spool_path>/root/spool/</spool_path>
            <mailer_id>1</mailer_id>
            <dns_max_retries>3</dns_max_retries>
            <mta_ip>192.168.1.115</mta_ip>                                                                                                      
      </basic>
</root>


My Code so far:

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;  
import javax.xml.parsers.FactoryConfigurationError;  
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;  
import org.xml.sax.SAXParseException;
import java.io.File;
import java.io.IOException;
import org.w3c.dom.Document;
import org.w3c.dom.DOMException;

public class config{
         private static final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
       private static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
       private static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
      
      //XML Data Container
      static Document cfg;
      
        public config()
        {
               loadXMLConfig();
        }

  public boolean loadXMLConfig()
      {
          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          factory.setValidating(true);
        factory.setNamespaceAware(true);
        factory.setNamespaceAware(true);
        factory.setValidating(true);

        factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);

            try
            {
                  DocumentBuilder builder = factory.newDocumentBuilder();
                  builder.setErrorHandler(
                                new org.xml.sax.ErrorHandler() {
                                    // ignore fatal errors (an exception is guaranteed)
                                    public void fatalError(SAXParseException exception)
                                    throws SAXException {
                                    }

                                    // treat validation errors as fatal
                                    public void error(SAXParseException e)
                                    throws SAXParseException
                                    {
                                      throw e;
                                    }

                                    // dump warnings too
                                    public void warning(SAXParseException err)
                                    throws SAXParseException
                                    {
                                      System.out.println("** Warning"
                                         + ", line " + err.getLineNumber()
                                         + ", uri " + err.getSystemId());
                                      System.out.println("   " + err.getMessage());
                                    }
                                }
                              );
                  cfg = builder.parse(new File("config.xml"));
                  
          }
            catch (SAXException sxe)
            {
            // Error generated during parsing
            Exception  x = sxe;
            if (sxe.getException() != null)
                x = sxe.getException();
            x.printStackTrace();
            } catch (ParserConfigurationException pce) {
             // Parser with specified options can't be built
             pce.printStackTrace();
          } catch (IOException ioe) {
             // I/O error
             ioe.printStackTrace();
          }
          
          return true;
      }
}

richardsimnettAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
http://www.java2s.com/Code/Java/XML/SAX.htm

i am not sure weather we can directly help you in correcting the program so only i am providing you the link which will help you to solve it.

Thank You.
0
CEHJCommented:
Get rid of

>>
         factory.setValidating(true);
        factory.setNamespaceAware(true);
        factory.setNamespaceAware(true);
        factory.setValidating(true);

        factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
>>

as there's nothing to validate (you have no schema or DTD)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
:-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.