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.