DocumentBuilderFactory.newInstance(); OR TransformerFactory.newInstance();
Usually when we create a reference to an class, we'll do:
Test tst = new Test();
But when we create a DocumentBuilderFactory or a TransformerFactory, we use:
DocumentBuilderFactory.newInstance();
or
TransformerFactory.newInstance();
Why use the newInstance() instead?
Thanks
Scott
Those are "factory" classes (as you might guess from their names). The DocumentBuilderFactory's newInstance() method returns an object that is an instance of DocumentBuilderFactory. If you read the documentation for the method, you will see the logic it goes through to decide which class it will produce an instance of.
This allows the user to configure the choice of DocumentBuilderFactory by changing the environment, rather than by having to modify source code and recompile.
Similar Messages
-
DocumentBuilderFactory.newInstance() only works after garbage collection
Hi all,
I am stucked with a strange behaviour of "DocumentBuilderFactory.newInstance()".
I use the DocumentBuilderFactory in an applet
to parse an xml-file.
My applet starts ok until the line 5 (newInstance) gets called.
At this time it seems that nothing happens anymore and that
the applet fails to continue.
But when I open up the java console and hit
g (garbage collection) the xml parsing continues immediatly
and my applet completes loading and runs ok.
1 private void genarteDomNodes() {
2 try {
3 // ---- Parse XML file ----
4 DocumentBuilderFactory factory =
5 DocumentBuilderFactory.newInstance();
6 DocumentBuilder builder =
7 factory.newDocumentBuilder();
8 Document document = builder.parse(
9 new URL(this.myModules_xml).openStream() );
10 // ---- Get list of nodes to given element tag name ----
11 NodeList ndList =
12 document.getElementsByTagName("meter-group");
13 printNodesFromList( ndList );
14 } catch( SAXParseException spe ) {
15 ...
16 } catch( SAXException sxe ) {
17 ...
18 } catch( ParserConfigurationException pce ) {
19 ...
20 } catch( IOException ioe ) {
21 ...
22 }
23 }I am still stucked with this problem. But I found out how to enable JAXP debug output for applets (setting system properties isn't allowed for applets).
This puts somemore output to the java console. It might help someone to understand my problem. I also printed some debug messages to track down my problem.
Following is the console output of my applet:
URL of XML to parse = "http://10.110.132.195/c8000-modules.xml"
entering "genarteDomNodes"
just before calling "DocumentBuilderFactory.newInstance()"
JAXP: find factoryId =javax.xml.parsers.DocumentBuilderFactory
!!! at this time the applet "hangs" and nothing happens;
until I hit the "g" button. Then applet continues immediatly and prints:
JAXP: loaded from fallback value: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
JAXP: created new instance of class com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl using ClassLoader: sun.plugin.security.PluginClassLoader@32060c
After invoking the garbage collector the applet continue to parse the xml file and runs as expected.
Can someone help me please. -
Weird DocumentBuilderFactory.newInstance() behaviour
problem summary
==============
jvm breaks when I call DocumentBuilderFactory.newInstance(). I suspect its something to do with security but no exception is caught in the try...catch block where DocumentBuilderFactory.newInstance() is called.
Other info about the problem
======================
I'm working on an application that use 'presence service' and message queue service. When I use Sun's message queue service, jvm doesn't break. But when I use a SKype client (jskype) jvm always fail even though jskype doesn't reference DocumentBuilderFactory.newInstance() at all. Anyone?That's great thinking Fred.
I've working on a much cut down and simplified version with just program changes to find out the cause of the behaviour.
I tried your note off suggestion without success, but your comment on the original multi being "blocked" led me to route the final events to a second copy of the multi instrument rather than the original, and it works - the custom bank changes are correctly output!
Maybe there's some kind of internal message validation or something, I'm not quite sure. But using a second copy of the multi instrument - though not ideal - is a perfectly acceptible workaround.
So thanks for the pointer - you really helped me out..! -
DocumentBuilderFactory.newInstance()
Hi Guys,
I am writing a utility that does access a database table and an xml file, like the following.
public void reads(){
tableMap = readTable(tableName); // here I am making a DB connection.
xmlMap = readXML(tableName); //
public Map readXML(){
docFact=DocumentBuilderFactory.newInstance();
//��creates an xml document
Here the problem is while I am using that readTable function the application exits by the line �docFact=DocumentBuilderFactory.newInstance()�. and if the readTable function is not called it works fine!.
Biju.Did you run if from GUI of from console? One of the possibilities is that your JRE is crashed (in that case it usually create a log file).
-
DocumentBuilderFactory.newInstance().newDocumentBuilder() error
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.*;
public class FrameRecorder extends Thread {
public Document dmt;
public FrameRecorder() {
DocumentBuilderFactory fctry = DocumentBuilderFactory.newInstance();
fctry.setValidating(true);
fctry.setNamespaceAware(true);
fctry.setIgnoringElementContentWhitespace(true);
//the error is on the next line.
DocumentBuilder bldr = fctry.newDocumentBuilder();
When I run it, I get an error saying:
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
Unhandled exception type ParserConfigurationException
at FrameRecorder.<init>(FrameRecorder.java:11)
at BaseFrame.<init>(BaseFrame.java:17)
at Base.createGUI(Base.java:10)
at Base$1.run(Base.java:7)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:226)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:602)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)
I don't know what to do to fix this.
I'm running 64-bit Ubuntu 10.4 so could it be a compatibility problem? The only headway I could make was that .newDocumentBuilder() throws a ParserConfigurationException (that's the error I'm getting), and the docs tell me that .newDocumentBuilder() throws this when it "DocumentBuilder cannot be created which satisfies the configuration requested".
Any help?Yes, somewhere in your code you have a compile error. I'm guessing you're using Eclipse and running your code from within it (or at least, running the Eclipse compiled classes from the command line).
You need to go and fix the compiler error. You already have all the information you need. You know where it is, you know what it is, and the documentation confirms it. -
TransformerFactory.newInstance cannot be resolved to a type"
Hi Techies,
i am writing simple application for creation of XML using java,
but while compiling i am getting the following error
"Exception in thread "main" java.lang.Error: Unresolved compilation problem:
TransformerFactory.newInstance cannot be resolved to a type"
can any one help me to solve this error..
thanks in advancehey here the code goes
package src;
import java.io.*;
import javax.xml.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.TransformerFactory;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class XMLCreator {
* @param args
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the number of elements");
String str = bf.readLine();
int no = Integer.parseInt(str);
System.out.println("Enter root: ");
String root = bf.readLine();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
Element rootElement = doc.createElement(root);
doc.appendChild(rootElement);
for(int i=1;i<=no;i++){
System.out.println("Enter the data");
String element = bf.readLine();
System.out.println("Enter data");
String data = bf.readLine();
Element em = doc.createElement(element);
em.appendChild(doc.createTextNode(data));
rootElement.appendChild(em);
TransformerFactory tf = new TransformerFactory.newInstance();
Transformer tr = tf.newTransformer();
DOMSource domsrc = new DOMSource(doc);
StreamResult res = new StreamResult(System.out);
tr.transform(domsrc, res);
}catch (Exception e) {
// TODO: handle exception
} -
When I tried this servlet example apache-tomcat-5.5.17 using java version "1.5.0_07"
javax.servlet.ServletException: Servlet execution threw an exception
root cause
javax.xml.transform.TransformerFactoryConfigurationError: Provider org.apache.xalan.processor.TransformerFactoryImpl not found
javax.xml.transform.TransformerFactory.newInstance(Unknown Source)
XML2HTMLServlet.openFile(XML2HTMLServlet.java:31)
XML2HTMLServlet.doGet(XML2HTMLServlet.java:19)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
// XML2HTMLServlet.java
//http://forum.java.sun.com/thread.jspa?forumID=34&threadID=260273
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;
public class XML2HTMLServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
try {
openFile("file:/apps/tomcat/apache-tomcat-5.5.17/webapps/xml/financials.xml", "file:/apps/tomcat/apache-tomcat-5.5.17/webapps/xml/financials.xsl", writer);
} catch (Exception e) {
e.printStackTrace(writer);
private void openFile(String xmlPath, String xslPath, PrintWriter writer)
throws IOException, ParserConfigurationException, SAXException,
TransformerConfigurationException, TransformerException {
File xmlFile = new File(xmlPath);
File xslFile = new File(xslPath);
TransformerFactory tFact = TransformerFactory.newInstance();
DocumentBuilderFactory dbFact = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dbFact.newDocumentBuilder();
Document xmlDoc = builder.parse(xmlFile);
Document xslDoc = builder.parse(xslFile);
Node xmlDocNode = (Node)xmlDoc;
Node xslDocNode = (Node)xslDoc;
DOMSource xmlSrc = new DOMSource(xmlDocNode);
DOMSource xslSrc = new DOMSource(xslDocNode);
DOMResult htmlResult = new DOMResult();
Transformer transformer = tFact.newTransformer(xslSrc); // the exception occurs here!
}Setting the proerty work now , I get no display, just a
When I tried this servlet example
apache-tomcat-5.5.17 using java version "1.5.0_07"
javax.servlet.ServletException: Servlet execution
threw an exception
root cause
javax.xml.transform.TransformerFactoryConfigurationErr
or: Provider
org.apache.xalan.processor.TransformerFactoryImpl not
found
javax.xml.transform.TransformerFactory.newInstance(Un
known Source)
XML2HTMLServlet.openFile(XML2HTMLServlet.java:31)
XML2HTMLServlet.doGet(XML2HTMLServlet.java:19)
javax.servlet.http.HttpServlet.service(HttpServlet.ja
va:689)
javax.servlet.http.HttpServlet.service(HttpServlet.ja
va:802)
// XML2HTMLServlet.java
//http://forum.java.sun.com/thread.jspa?forumID=34&thr
eadID=260273
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;
public class XML2HTMLServlet extends HttpServlet {
System.setProperty("javax.xml.transform.TransformerFactory", "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
try {
penFile("file:/apps/tomcat/apache-tomcat-5.5.17/webapp
s/xml/financials.xml",
"file:/apps/tomcat/apache-tomcat-5.5.17/webapps/xml/fi
nancials.xsl", writer);
} catch (Exception e) {
e.printStackTrace(writer);
private void openFile(String xmlPath, String
xslPath, PrintWriter writer)
throws IOException,
ParserConfigurationException, SAXException,
TransformerConfigurationException,
TransformerException {
File xmlFile = new File(xmlPath);
File xslFile = new File(xslPath);
TransformerFactory tFact =
TransformerFactory.newInstance();
DocumentBuilderFactory dbFact =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder =
dbFact.newDocumentBuilder();
Document xmlDoc =
builder.parse(xmlFile);
Document xslDoc =
builder.parse(xslFile);
Node xmlDocNode = (Node)xmlDoc;
Node xslDocNode = (Node)xslDoc;
DOMSource xmlSrc = new
DOMSource(xmlDocNode);
DOMSource xslSrc = new
DOMSource(xslDocNode);
DOMResult htmlResult = new
DOMResult();
Transformer transformer =
tFact.newTransformer(xslSrc); // the exception
occurs here! -
DocumentBuilderFactory and TransformerFactory
I saw some coding like this:*
factory = DocumentBuilderFactory.newInstance();
builder = factory.newDocumentBuilder();
Document doc = builder.newDocument();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
t.setOutputProperty("encoding","UTF-8");
t.transform(new DOMSource(doc),new StreamResult(baos)); String xmlString = new String(baos.toByteArray(), "utf8");
My questions are:*
1) Does the doc (Document)
contains the such header as:
*<?xml version="1.0" ?>*
2) Must the doc object host an XML string, or it can contain any type string(i.e., not necessarily an XML string)?
3) What is the purpose of using the transformer to transform the doc as:
t.transform(new DOMSource(*doc*),new StreamResult(*baos*));
4) Does the Transformer add the header <?xml version="1.0" ?> to the baos object?
Thanks
Scott
Edited by: scottjsn on Jan 11, 2008 3:58 PMI saw some coding like this:*
factory = DocumentBuilderFactory.newInstance();
builder = factory.newDocumentBuilder();
Document doc = builder.newDocument();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
t.setOutputProperty("encoding","UTF-8");
t.transform(new DOMSource(doc),new StreamResult(baos)); String xmlString = new String(baos.toByteArray(), "utf8");
My questions are:*
1) Does the doc (Document)
contains the such header as:
*<?xml version="1.0" ?>*
2) Must the doc object host an XML string, or it can contain any type string(i.e., not necessarily an XML string)?
3) What is the purpose of using the transformer to transform the doc as:
t.transform(new DOMSource(*doc*),new StreamResult(*baos*));
4) Does the Transformer add the header <?xml version="1.0" ?> to the baos object?
Thanks
Scott
Edited by: scottjsn on Jan 11, 2008 3:58 PM -
I am currently working on an applet that solves Sudoku puzzles, allowing you to build your own in a Constructor and then solve them in a seperate Solver. To do this, we are implementing the puzzles files as XML documents.
I have the code completely complied and on the server ( [sudoku.unl.edu|sudoku.unl.edu]) and it runs NEARLY perfectly, however when trying to access the server to save the xml code, the apache error_log presents this message: "File does not exist: classes/META-INF/services
/javax.xml.parsers.DocumentBuilderFactory"
Looking at the Java Doc here it says that the program should look for that in the jars. I am unsure of exactly how the applet is interacting with the server, but typing "java -version" yields:
java version "1.6.0_11"
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot(TM) 64-Bit Server VM (build 11.0-b16, mixed mode)Notably, the code works PERFECTLY in NetBeans, contacting the server using SCP and uploading the file and such, so the code doesn't seem to be the problem, unless I need to direct the DocumentBuilder code somehow. This is the code that I believe is causing the trouble (I have tried to include all relevant imports that are in my code):
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
DocumentBuilderFactory factoryBuilder;
DocumentBuilder builder;
Document doc;
Element docElement;
try
factoryBuilder = DocumentBuilderFactory.newInstance( );
builder = factoryBuilder.newDocumentBuilder();
doc = builder.parse( indexLocation );
docElement = doc.getDocumentElement();
NodeList children = docElement.getChildNodes();
for(int i =0; i < children.getLength(); i++)
if(children.item(i).getNodeType() == 1)
if((children.item(i).getNodeName()).equals("directory"))
if ((children.item(i).getAttributes().getNamedItem("name").getNodeValue()).equals("UsersInput")) {
Node firstChild = findNodeItem(children.item(i), "Difficulty0.." + this.upperField.getText());
Node secondChild = findNodeItem(firstChild, "Level" + this.levelField.getText());
Node thirdChild = findNodeItem(secondChild, (String)suTypeList.getSelectedItem());
Element newFile = doc.createElement("file");
newFile.setAttribute("name", fileName);
thirdChild.appendChild(newFile);
SshParameters params = new SshParameters("cse.unl.edu", "consystlab","A/tutti");
// create new Scp instance
Scp scp = new Scp(params);
// register event listener
scp.addListener(this);
// establish connection
scp.connect();
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StringWriter sw=new StringWriter();
StreamResult result = new StreamResult(sw);
transformer.transform(source, result);
String xmlString=sw.toString();
// upload file
scp.upload(xmlString.getBytes(), indexPath, "libraryIndex.xml");
// disconnect
scp.disconnect();
catch (IOException e)
System.out.println("IO ERROR7");
System.out.println(e);
catch (TransformerException tranE){
tranE.printStackTrace();
catch (ParserConfigurationException e)
System.out.println("IO ERROR8");
System.out.println(e);
catch (SAXException e)
System.out.println("IO ERROR9");
System.out.println(e);
}So my question is, what exactly are the contents of the file in the META-INF/services folder? I have manually created this file in my classes directory, where the program is searching. When I place text in it, it appends the text with .class and searches for that file, but doesn't seem to do anything with the file. I attempted directing it to the "DocumentBuilderFactory.class" file that I extracted from the classes.jar included with the JDK.
I feel like all I need is this file to contain the correct content and the code will FINALLY work, but I have not been able to find anything out there on it.
Thank for you for your help, sorry this was such a long message.
-JasonThanks!
Thanks for the fast reply. I don't know if I made my point clear.
I do not want to determine the parser by myself. I want the client system use the default parser, so I do not have the hit of downloading the fairly large parser jar.
However, I want it not to do an empty request to the server for nothing. This turn around time kills an Applet. I want a fast loading applet!
I'll go in trial and error mode, when I find the time next week.
Thanks again, I appreciate it!
K<o> -
XML/transformerfactory problem
ok here goes; ive written a method that outputs a hashmap to an xml file, this program seemed to run fine untill i updated to java 1.6 but after recompiling [without errors] each time the method is called in the program i get these errors
Exception in thread "main" java.lang.AbstractMethodError: org.apache.crimson.tree.XmlDocument.getXmlStandalone()Z
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.setDocumentInfo(DOM2TO.java:373)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:127)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:94)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:663)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:709)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:313)
at bob2.xmlinout.toxml(xmlinout.java:57)
at bob2.google.getestimate(google.java:92)
at bob2.google.doFight(google.java:44)
at bob2.mybot.onSay(mybot.java:77)
at bob2.bot.switcher(bot.java:171)
at bob2.bot.run(bot.java:152)
at bob2.bot.connect(bot.java:83)
at bob2.bob.main(bob.java:27)
Java Result: 1heres the method in question:
public void toxml(HashMap<String, Integer> map, String filename)throws Exception{
//System.out.println("map in writer= " + map);
DocumentBuilder builder = null;
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = builder.newDocument();
Element root = document.createElement("googles");
for(String key : map.keySet()){
Integer value = map.get(key);
Element newNode = document.createElement("entry");
Attr newKey = document.createAttribute("key");
Attr newValue = document.createAttribute("value");
newKey.setValue(key.toUpperCase().replace(" ", ""));
newValue.setValue(value.toString());
newNode.setAttributeNode(newKey);
newNode.setAttributeNode(newValue);
root.appendChild(newNode);
document.appendChild(root);
Transformer transformer = TransformerFactory.newInstance().newTransformer();
Source source = new DOMSource(document);
File file = new File(filename);
Result result = new StreamResult(file);
transformer.transform(source,result);
}if anyone can help id really apreciate it, i just cant figure out whats going wrong.i'd ask on the xalan mailing lists:
http://xml.apache.org/mail.html#xalan-j-users -
How to set a new DocumentBuilderFactory in my application?
Hello Suners,
I really need some help to set a new DocumentBuilderFactory in my application.
I have a new instance of DocumentBuilderFactory with my settings and i need to set it in the application so that it use it to show some special DOM elements.
DocumentBuilderFactory.newInstance("com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl", null) ;now i just need a clue how to make it recognizable to my application i mean how to make my application obtain a reference to the new DocumentBuilderFactory so it can use the factory to configure and obtain parser instances?.
Edited by: abulseed on Aug 29, 2010 6:59 AMabulseed wrote:
now i just need a clue how to make it recognizable to my application i mean how to make my application obtain a reference to the new DocumentBuilderFactory so it can use the factory to configure and obtain parser instances?.That code already produces a reference to the new DocumentBuilderFactory (assuming it's correct code). The normal thing to do with the reference would be to assign it to a variable. Then your application could use the variable, which refers to the factory, to do those things which it is supposed to do. -
Error while creating DocumentBuilderFactory object for parsing XML string
When I try to execute the following statement in an EJB class,
DocumentBuilderFactory df=DocumentBuilderFactory.newInstance();
I get the following exception:
javax.xml.parsers.FactoryConfigurationError: Provider org.apache.crimson.jaxp.DocumentBuilderFactoryImpl not found
When the same statement is executed from a standalone java class, it works fine.
The IDE used is Visual Age for Java.
The JAXP package used is JAXP 1.0.1
Can anybody please let me know how can we overcome this problem?
Thanks and Regards,
Shashi Anand B
E-Mail : [email protected]javax.xml.parsers.FactoryConfigurationError: Provider
org.apache.crimson.jaxp.DocumentBuilderFactoryImpl not
foundI suspect that this may be due to a classpath issue and/or a Java version issue. Doe your Visual Age installation use Java 1.3? Do you have Sun Java 1.4 also installed on your system? It may be that when you are executing from a standalone Java class, that you are using the Java 1.4 runtime, which include the org.apach.crimson.* classes. Earlier version of Java do not include this, although it may be in the JAXP package.
I think that your Visual Age IDE is configured such that the DocumentBuilderFactory is unable to find the appropriate implementation.
I hope this helps!
- David -
ParserConfigurationException with javax.xml.parsers.DocumentBuilderFactory
Like many people, I am trying to just read in the contents of a XML file. My code compiles in WS studio and I publish it to the server. However, I keep getting a ParserConfigurationException when I try to get a DocumentBuilder from the factory. Below is my code:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse( new File(XMLFILE) );
Any idea why?The xmlfile is valid and here is the partial stacktrace
Root Error-1: javax/xml/parsers/ParserConfigurationException
java.lang.Exception: javax/xml/parsers/ParserConfigurationException
at Search5F_Results_jsp_5._jspService(_Search_5F_Results_jsp_5.java:206)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:127)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.runtime.JspServlet$JspServletWrapper.service(JspServlet.java:390)
at org.apache.jasper.runtime.JspServlet.serviceJspFile
Do I need to set some system property? -
ClassCastException in DocumentBuilderFactory on DB-Server
Hi,
I've deployed an application, that recieves a xml-String to parse.
It's running fine in JDeveloper but when I deploy it to the Database
I recieve the ClassCastException.
I figured out that it's thrown when I do:
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Whats the problem with the DocumentBuilderFactory?
Any Suggestions?
THX
Selim KeserHave you loaded the same version of the Oracle XDK for Java into the database account where you're trying to run this?
-
[Solution] DocumentBuilderFactory, Serialization, and WL 8.1 SP 2
<pre>
Hello All!
I finally have gotten my web services to work properly. All of my serialization
woes were caused by my using the javax.xml.parsers.DocumentBuilderFactory and
NOT setting the following options:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setNamespaceAware(true);
Yup. That's it. I saw this being done in one of the tech support people's examples:
private Document getDocumentWithWL(String resourceName)
throws Exception
weblogic.apache.xerces.parsers.DOMParser parser = new weblogic.apache.xerces.parsers.DOMParser();
parser.setFeature(
"http://apache.org/xml/features/dom/defer-node-expansion",
false );
parser.setFeature( "http://xml.org/sax/features/validation",
false);
parser.setFeature( "http://xml.org/sax/features/namespaces",
true);
parser.setFeature( "http://apache.org/xml/features/validation/schema",
true);
parser.parse(new org.xml.sax.InputSource(this.getClass().getClassLoader().getResourceAsStream(resourceName)));
return(parser.getDocument());
and decided to write the analog to this using the DocumentBuilderFactory:
private Document getDocumentWithDB(String resourceName)
throws Exception
DocumentBuilder db = null;
DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
// Set params
fac.setValidating(false);
fac.setNamespaceAware(true);
db = fac.newDocumentBuilder();
Document doc = db.parse(this.getClass().getClassLoader().getResourceAsStream(resourceName));
return(doc);
Now my doc/lit web services are able to marshall data between the service and
client. I have to still use the DII dynamic proxy client method for invoking
the web service (SOAPElement!! grr).
Thanks to all who helped diagnose this problem. You know that you have this problem
when you see errors about "Local name of attribute can not be null ...." coming
out of weblogic's XML serialization code.
Hope this helps someone else out there
-- jake
</pre>Well basically that means there was a partial message that came in over a socket, and the server waited 60 seconds for the rest of the message, but it never arrived.
Was the server, or a client under heavy load? Did you notice any response time problems?
-- Rob
WLS Blog http://dev2dev.bea.com/blog/rwoollen/
Maybe you are looking for
-
Hi, In a program to update the database table I need to lock the table Is this correct to use enqueue functional module before the modify & commit statement and dequeue functional module after modify & commit statement.
-
Quark Express 6.5 won't quit on my Intel-based iMac
Hi, At work I use a 20-inch Intel Core 2 Duo iMac (with 2GB RAM installed) and run Quark Express 6.5 as a PowerPC program through Rosetta. Quark runs fairly quickly and saves OK, but it never quits properly when I shut my Mac down normally, it just h
-
Java2D get image size without read image to buffer
Hi, I need get the image size without buffering the image. Can somebody help me? THX
-
I have 2 pages in question. 1, located at www.salleboise.com/club_tournaments.cfm and the other at http://www.salleboise.com/tournament.cfm?tid=1&f=1&e=1 My question is this. Why does the text at the top of the page differ so much in positioning? I d
-
Ssharehare files between different users on the one Mac
How can I share in read/write directories (e.g. documents, pictures. I got an iMac with an SSD and a hard drive. Shared and Public are located in the SSD, which I want to avoid to use.I want shared directories on the hard drive. I also looked at a p