- When you parse an XML file with a DTD, tell the parser to ignore white space
factory.setValidating(true);
factory.setIgnoringElementContentWhitespace(true);
- If the parser has access to a DTD, it can fill in defaults for attributes
- For example, suppose a DTD defines a currency attribute for a price element:
<!ATTLIST price currency CDATA "USD">
- If a document contains a price element without a currency attribute, the parser can supply the default:
String attributeValue = priceElement.getAttribute("currency");
// Gets "USD" if no currency specified