[Q] java and xml

Search This thread

justinayres

New member
Mar 16, 2014
1
0
something is wrong with my setup...

Eclipse Keplar
Windows 7 32bit
java 7u51

db = dbf.newDocumentBuilder(); throws ParserConfigurationError..
please help me. this file is as simple as i could make it.


import java.io.File;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;


public class XMLHELP {

public static void main(String[] args) {

File file = new File("foo.xml");
DocumentBuilderFactory dbf;
DocumentBuilder db = null;

dbf = DocumentBuilderFactory.newInstance();
try {
db = dbf.newDocumentBuilder();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

try {
Document doc = db.parse(file);
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}
 

marwan.kallal

Member
Mar 15, 2014
11
2
ParserConfigurationError means that you misconfigured your factory.

Look here at the newInstance() method in the DocumentBuilderFactory API.
That tells you where it looks for configurations if you don't supply any. One of those files may be messed up or out of place, so give it your own configuration. I just ran the exact same code with a dummy XML file and it worked perfectly with no exceptions or errors. Look up how to configure it yourself or what the default should be, and that could fix your problem.