Post Reply

[Q] java and xml

OP justinayres

16th March 2014, 01:03 PM   |  #1  
OP Junior Member
Thanks Meter: 0
 
1 posts
Join Date:Joined: Mar 2014
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();
}

}

}
16th March 2014, 06:31 PM   |  #2  
marwan.kallal's Avatar
Junior Member
Thanks Meter: 2
 
11 posts
Join Date:Joined: Mar 2014
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.
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in Java for Android App Development by ThreadRank