java - Call to get XML element returns null -
i have series of xml files looking through , grabbing specific element from.
<key>a</key>
i'm using snippet of code grab xml element, returns null instead of element looking for. not able change xml files.
file key = new file(filepath); printwriter keywriter = new printwriter(key); file xmlfile = new file(configpath); documentbuilderfactory documentbuilderfactory = documentbuilderfactory.newinstance(); documentbuilder documentbuilder = documentbuilderfactory.newdocumentbuilder(); document document = documentbuilder.parse(xmlfile); nodelist nodes = document.getelementsbytagname("key"); element keyvalue = (element) nodes.item(0); keywriter.println(keyvalue); keywriter.close(); }
i've tried using document method apache xmlconfiguration , getelementbyid have returned null far.
i noticed in code passing element object writer's println
function in:
keywriter.println(keyvalue);
this print null value in file. try replacing with:
keywriter.println(keyvalue.gettextcontent());
Comments
Post a Comment