This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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?
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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: replace OutputFormat.setPreserveSpace by JAXP