Solved

How to get Blank tags from XML using Oracle DOM Parser

Posted on 2004-09-13
5
254 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

776 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