File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes newDocumentBuilder() method freezes with no error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "newDocumentBuilder() method freezes with no error" Watch "newDocumentBuilder() method freezes with no error" New topic
Author

newDocumentBuilder() method freezes with no error

A Stafford
Greenhorn

Joined: Oct 09, 2003
Posts: 4
I am trying to parse a document and my program freezes at the factory.newDocumentBuilder() method. I have the same jar files that I have in my build path. I am confused. Any guidance would be appreciated. Thank you.
try{
System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
System.setProperty("javax.xml.parsers.SAXParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl");
System.setProperty("javax.xml.transform.TransformerFactory", "org.apache.xalan.processor.TransformerFactoryImpl");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(false);
factory.setValidating(false);
////FREEZES HERE at factory.newDocumentBuilder()\\\\
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource inps = new InputSource(new StringReader(xml));
Document doc = builder.parse(inps);
}catch (SAXException e) {
System.out.println(xml + " is not well-formed.");
return null;
} catch (FactoryConfigurationError e) {
System.out.println("Could not locate a factory class");
return null;
} catch (ParserConfigurationException e) {
System.out.println("Could not locate a JAXP parser");
return null;
} catch (Exception e) {
System.out.println("Exception: " + e.getMessage());
e.printStackTrace();
return null;
}
A Stafford
Greenhorn

Joined: Oct 09, 2003
Posts: 4
Solved Problem. Switched my approach... Removed all xml jars and replaced with crimson.jar. Set a new System Property and removed the old. Everything works well now. Heres the code...

System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.crimson.jaxp.DocumentBuilderFactoryImpl");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource inps = new InputSource(new StringReader(xml));
Document doc = builder.parse(inps);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: newDocumentBuilder() method freezes with no error
 
Similar Threads
Why is this happening?
Problem with (my) XPath
Why these xpath function cannot work properly in such Document?
DTD Validation problem via Sax
DOM (xml) question