Solved

How to get Blank tags from XML using Oracle DOM Parser

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
firstswap challenge 20 68
Non-recursive backtracking, using a stack 1 103
replace a word with other 1 40
diffSum example 4 26
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

861 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

25 Experts available now in Live!

Get 1:1 Help Now