Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to ignore whitespace in text nodes?

 
Naren Chivukula
Ranch Hand
Posts: 577
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm using JAXP with DOM Parser. When I parse the xml file and navigate through the nodes, parser is taking whitespaces as textnodes. How to ignore these whitespace text nodes? Is there any method to ignore?

Thanks in advance,
Narendranath.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use DocumentBuilderFactory#setIgnoringElementContentWhitespace(boolean) to make the DOM parser ignore ignorable whitespace, that is, whitespace that is inside element content only elements.
 
Naren Chivukula
Ranch Hand
Posts: 577
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used like that only. But I'm still getting the nodeList.getLength() of Node taking into account of empty text nodes. When I remove those empty text nodes and mentioning tags side by side (without space) then I'm getting nodeList.getLength() as a different value.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic