RemoveChild and BlankSpace in the XML file.

A

Achille

Hi all,
I need to remove a node in my XML file.
I use the DOMParser.

If I use the removeChild, the node is removed but a white line remains
in my Dom tree and file xml.

How do I also do to remove the blanck line?

Thanks!
By
Achille
 
A

Alexey Dmitriev

Achille said:
Hi all,
I need to remove a node in my XML file.
I use the DOMParser.

If I use the removeChild, the node is removed but a white line remains
in my Dom tree and file xml.

How do I also do to remove the blanck line?

Thanks!
By
Achille
if the parser has not been set in a validating mode
(DocumentBuilderFactory.isValidating{}) It's connected by that spaces or
line carring between anyone two consecutive elements of DOM are treated
as a TextNode.
There is only one way to avoid it is it to set a validating mode and set
a ignoring whitespaces.
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
factory.setIgnoringElementContentWhitespace(true);
builder = factory.newDocumentBuilder();
....

Anyway If you know document structure You can remove nasty text nodes
itself.
 
Joined
Oct 24, 2015
Messages
2
Reaction score
0
I am getting an error after modifying the code like above n its not removing blank line

Warning: validation was turned on but an org.xml.sax.ErrorHandler was not
set, which is probably not what is desired. Parser will use a default
ErrorHandler to print the first 10 errors. Please call
the 'setErrorHandler' method to fix this..
 
Joined
Oct 24, 2015
Messages
2
Reaction score
0
I have done like below
dBuilder.setErrorHandler(null);
now I am not getting error but its not removing blank line in xml
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top