wood burning stoves 2.0
The moose likes XML and Related Technologies and the fly likes DocumentBuilderFactory parser returns doc: [#document: null] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "DocumentBuilderFactory parser returns doc: [#document: null]" Watch "DocumentBuilderFactory parser returns doc: [#document: null]" New topic

DocumentBuilderFactory parser returns doc: [#document: null]

Max Tomlinson
Ranch Hand

Joined: Jul 17, 2001
Posts: 365
Hi all-

I want to update an xml doc before I send it but can't get DocumentBuidlerFactory to work, even with a simple doc: e.g.
<?xml version="1.0" ?>

I've tried many combinations of setting various properties to DBF all to no avail.

my code:

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
String p = System.getProperty("javax.xml.parsers.DocumentBuilderFactory");
//this displays: JAXP: find factoryId =javax.xml.parsers.DocumentBuilderFactory
//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: null
DocumentBuilder db = dbf.newDocumentBuilder();
//File f = new File(fn);
Document doc = db.parse(fn);
//this returns a doc with [#document: null]
NodeList nl = doc.getElementsByTagName("Address");
Node n = nl.item(0).getFirstChild();
// text.setLength(0);
// String docStr = getStringFromDocument(doc);
// if (null==docStr) {
// status = "Error on doc transform " + status;
// log.error(status);
// return status;
// }
// log.info(docStr);
// text.append(docStr);
} catch (Exception e) {
String status = "Exception on attempting to update Subscribe request " + e.getMessage();


Max Tomlinson
Ranch Hand

Joined: Jul 17, 2001
Posts: 365
My error -
there was nor problem with document: null which was my assumption.
I was imply not using the ns prefix when I tired to get elements by tagname.

subject: DocumentBuilderFactory parser returns doc: [#document: null]
It's not a secret anymore!