wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes replace OutputFormat.setPreserveSpace by JAXP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "replace OutputFormat.setPreserveSpace by JAXP" Watch "replace OutputFormat.setPreserveSpace by JAXP" New topic
Author

replace OutputFormat.setPreserveSpace by JAXP

Tom John
Greenhorn

Joined: Apr 15, 2002
Posts: 29
How to translate "OutputFormat.setPreserveSpace()" into JAXP?

I'm working on the code implemented by the old Xerce.jar&Xalan.jar.
Now I need to adapt these code by JAXP.

I faced these lines as below:
===============implemented by the old Xerce.jar&Xalan.jar====================
Document doc = ...;
OutputFormat format = new OutputFormat(doc);
format.format.setIndenting(true);
format.setPreserveSpace(true);
format.setLineWidth(65);


Now I can successfully translate the method "setIndenting" by the following
==============================implemented by the JAXP========================
TransformerFactory tfactory = TransformerFactory.newInstance();
Transformer serializer= tfactory.newTransformer();
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
...

Now I don't know how to translate the method of "setPreserveSpace" in JAXP?
I also don't know how to translate the method of "setLineWidth" in JAXP?

Looking forword your help!

Thanks in advance!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

What do those things do? (Yes, I suppose I could google for it, but it would be more convenient for potential answerers if they didn't have to do that.)
Tom John
Greenhorn

Joined: Apr 15, 2002
Posts: 29
Paul, can you help me?

I googled my questions already..
But I can't find out any answer...
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

I didn't mean for you to search for the answer. I meant for you to tell us what the question means. What does "setPreserveSpace" do?
Tom John
Greenhorn

Joined: Apr 15, 2002
Posts: 29
Paul, actually, I also don't know what's the setPreserveSpace.

I only know it's a old method in class org.apache.xml.serialize.OutputFormat which is from old Xerce.jar.

I guess can we translate this method by DocumentBuilderFactory.setIgnoringElementContentWhitespace(false) in JAXP???
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

Originally posted by Tom John:
Paul, actually, I also don't know what's the setPreserveSpace.

I only know it's a old method in class org.apache.xml.serialize.OutputFormat which is from old Xerce.jar.
Pity you didn't keep the documentation when you downloaded that, then. I could only find documentation for what I suppose is a newer version, and it doesn't have that method. You could try removing it from your code to see what difference that makes. Then you might be able to figure out what it does.
I guess can we translate this method by DocumentBuilderFactory.setIgnoringElementContentWhitespace(false) in JAXP???
Nope. Your original question was about serializing XML. That's taking data from some internal format and producing an XML document from it. You can't equate that to something that a parser does, namely taking an XML document and producing some internal format from it. Besides which "ignoring element-content whitespace" sounds exactly opposite to "preserve space" to me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: replace OutputFormat.setPreserveSpace by JAXP