You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Matthew Oatham <ma...@hotmail.com> on 2003/04/14 16:54:53 UTC

DocumentBuilder.parse(File file)

Hi,

I am loading an XML file in to DOM using DocumentBuilder.parse(File file).

I have written an XML writer which takes a DOM and writes it to file I have tested this and know it works as expected when creating a new DOM in memory. 

However when I create a DOM from an existing xml file then write it to disk using my xml writer there are blank line or carriage returns in the new file which didn't exist in the original. I suspect these are being inserted when the DOM is created from an existing file but can't prevent or solve it. Does anyone have an explanation or ideas to prevent or solve.

Regards.

Matt

RE: DocumentBuilder.parse(File file)

Posted by Rahul Srivastava <rs...@firstam.com>.
Hi Matt,

When you load a XML from a file as a DOM, the whitespaces become a part of
the DOM as nodes. I suspect, you are using a 'println' in some places, to
write out the nodes to the stream, and hence, when printing such a
whitespace node using println, you get, extra blank lines, or CRs.

You can avoid the creation of these whitespace nodes by using
setIgnoringElementContentWhitespace() on DBF, but, note that, this works,
when you have an associated grammar, and that grammar MUST be a DTD,
otherwise, this feature won't work. In that case, you have to modify your
program.

Anyways, you can post your code, if still, this does not fix your problem.
BTW, You might be interested in having a look at the XMLSerializer of
Xerces2-J.

Cheers,
Rahul.


-----Original Message-----
From: Matthew Oatham [mailto:matthewoatham@hotmail.com]
Sent: Monday, April 14, 2003 8:25 PM
To: general@xml.apache.org
Subject: DocumentBuilder.parse(File file)


Hi,

I am loading an XML file in to DOM using DocumentBuilder.parse(File file).

I have written an XML writer which takes a DOM and writes it to file I have
tested this and know it works as expected when creating a new DOM in memory.

However when I create a DOM from an existing xml file then write it to disk
using my xml writer there are blank line or carriage returns in the new file
which didn't exist in the original. I suspect these are being inserted when
the DOM is created from an existing file but can't prevent or solve it. Does
anyone have an explanation or ideas to prevent or solve.

Regards.

Matt



---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org