Link to home
Start Free TrialLog in
Avatar of dibanu
dibanu

asked on

How to get Blank tags from XML using Oracle DOM Parser

I am using Oracle DOM Parser to parser my XML.

I need to find out which tags are BLANK in the XML and then differ the processing for such tags . CAn anybody help
Avatar of MogalManic
MogalManic
Flag of United States of America image

For nodes that are blank node.getChildNodes()==null
For nodes that only contain whitespace:

isBlank=true;
NodeList nl=node.getChildNodes();
for(int i=0;i<nl.getLength();i++) {
  Node eachItem=nl.item(i);
  if (!eachItem instanceof TextElement) {
     isBlank=false;
     break;
  } else {
     if (eachItem.getNodeValue().trim().length>0) {
       isBlank=false;
       break;
     }
  }
}
Avatar of CEHJ
Not sure if i understand that code example although i think


>>if (eachItem.getNodeValue().trim().length>0) {


should be

if (eachItem.getNodeValue().trim().length()>0) {

You may want to add the blank nodes to a List so you know which ones to avoid

ASKER CERTIFIED SOLUTION
Avatar of MogalManic
MogalManic
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial