File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes How to ignore whitespace in text nodes? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Reply Bookmark "How to ignore whitespace in text nodes?" Watch "How to ignore whitespace in text nodes?" New topic
Author

How to ignore whitespace in text nodes?

Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 542

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.


Cheers,
Naren (SCJP, SCDJWS and SCWCD)
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
You can use DocumentBuilderFactory#setIgnoringElementContentWhitespace(boolean) to make the DOM parser ignore ignorable whitespace, that is, whitespace that is inside element content only elements.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 542

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to ignore whitespace in text nodes?
 
Similar Threads
how to remove indentation in a xml using java api
simple JAXPquestion
About parsing with DOM ...
Getting the text out of a HTML?
SAX parser's characters[] method and "\n" problem