Solved

How to get Blank tags from XML using Oracle DOM Parser

Posted on 2004-09-13
5
251 Views
Last Modified: 2013-11-23
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
0
Comment
Question by:dibanu
  • 2
5 Comments
 
LVL 21

Expert Comment

by:MogalManic
ID: 12042589
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;
     }
  }
}
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12045954
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

0
 
LVL 21

Accepted Solution

by:
MogalManic earned 125 total points
ID: 12046331
Sorry, didn't compile code.  Here is correct version:

        boolean isBlank=true;
        NodeList nl=node.getChildNodes();
        for(int i=0;i<nl.getLength();i++) {
            Node eachItem=nl.item(i);
            if (!(eachItem instanceof Text)) {
                isBlank=false;  //This node in the tree is NOT a leaf (i.e. it has children that are Element Nodes)
                break;
            } else {
                if (eachItem.getNodeValue().trim().length()>0) {
                    isBlank=false;  //This node has non-whitespace data as children
                    break;
                }
            }
           
        }
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now