What is XML Whitespace?
XML considers four characters to be whitespace: the carriage return (\r or ch(13)), the linefeed (\n or ch(10)), the tab(\t), and the spacebar (' '). In XML documents, there are two types of whitespace:
- Significant whitespace is part of the document content and should be preserved.
- Insignificant whitespace is used when editing XML documents for readability. These whitespaces are typically not intended for inclusion in the delivery of the document.
Usually without DTD or XML schema definition, all whitespaces are significant whitespaces and should be preserved. However, with DTD or XML schema definitions, only the whitespaces in the content are significant as follows:
------------------
John Smith
Product Manager
Example.com
--------------------
What is XML Whitespace?
XML considers four characters to be whitespace: the carriage return (\r or ch(13)), the linefeed (\n or ch(10)), the tab(\t), and the spacebar (' '). In XML documents, there are two types of whitespace:
- Significant whitespace is part of the document content and should be preserved.
- Insignificant whitespace is used when editing XML documents for readability. These whitespaces are typically not intended for inclusion in the delivery of the document.
Usually without DTD or XML schema definition, all whitespaces are significant whitespaces and should be preserved. However, with DTD or XML schema definitions, only the whitespaces in the content are significant as follows:
------------------
John Smith
Product Manager
Example.com
--------------------
Problem : java.net.MalformedURLException: no protocol: error
DocumentBuilder documentBuilder
DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document expectedDoc = documentBuilder.parse(new InputSource(actualResult)));
where actualResult is an string containing the xml
Solution :
Here a String is passed to the parse method, but it expects a URI (as
the documentation says, "Parse the content of the given URI as an XML
document").
Do this instead:
Document doc =
documentBuilder
.parse(new InputSource(new StringReader(getValidXML())));