A problem occurs when the program has to process documents from multiple sources, which may apply different meaning to elements with the same name: an element from one vendor will be very different from the like-named element from another.
Even within an organization, XML data formats can undergo revision, and you may need to handle “version 1” data differently than “version 2.” attributes and does the right thing.
The XML specification requires that an XML document either have a prologue that specifies its encoding, or be encoded in UTF-8 or UTF-16.
But in this example I used a Java String, which is UTF-16 encoded, without a prologue. The answer is that the parser did not read the string directly.
Parser will use a default Error Handler to print the first 10 errors.
Please call the 'set Error Handler' method to fix this.
Document Builder Factory dbf = Document Builder Instance(); Namespace Aware(true); Validating(true); Document Builder db = Document Builder(); Error Handler(new Error Handler() ); Document dom = db.parse(new Input Source(xml)); is called “to report conditions that are not errors or fatal errors as defined by the XML recommendation.” I'm not entirely certain what those conditions might be, and have never seen this method invoked.