• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DocumentBuilderFactory parser returns doc: [#document: null]

 
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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" ?>
<earth>
<country>us</country>
</earth>

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");
log(p);
//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();
n.setNodeValue("myAddress");
// 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) {
e.printStackTrace();
String status = "Exception on attempting to update Subscribe request " + e.getMessage();
log(status);
}

}

 
Max Tomlinson
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

thanks
Max
 
Today's lesson is that you can't wear a jetpack AND a cape. I should have read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic