i'm using org.apache.xerces.jaxp.DocumentBuilderImpl for loading xml documents in java. Document to load is:
<?xml version="1.0" encoding="UTF-8"?>CRLF
<doc >CRLF
<e1 />CRLF
</doc>
I load document in common way:
DocumentBuilder builderXml = null;
Document nodeXml = null;
ByteArrayInputStream inputStream = new ByteArrayInputStream(xmlByte);
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
builderXml = documentBuilderFactory.newDocumentBuilder();
nodeXml = builderXml.parse(inputStream);
Loaded document seems to be ok, but only one thing is missing. CR at the end of line was ommited.
If I call this
nodeXml.getChildNodes().item(0).getChildNodes().item(0).getNodeValue()
I get "\n " string.
In normal situation isn't this problem, but in combined with canonicalization I get different result as I expected. Can me someone help what is wrong with CR at the end line ?
Java SDK 1.7_25 x86
Thank in advance for your help
Vlado
EDIT:
In .net I can write this
var xDoc = new XmlDocument();
xDoc.PreserveWhitespace = true;
using (var fs = new FileStream("file.xml", FileMode.Open))
{
xDoc.Load(fs);
}
var transform = new XmlDsigC14NTransform(false) { Algorithm = SignedXml.XmlDsigC14NTransformUrl };
transform.LoadInput(xDoc);
var output = (MemoryStream)transform.GetOutput();
File.WriteAllBytes("C:\\file1.xml", output.ToArray());
and whitespaces are preserved. Is this possible in java ?