Validity vs. well-formedness: If an XML document does not conform to its DTD, should it be considered a “bad XML document”?
-
AIncorrect: it is not DTD-valid, but it may still be well-formed XML
-
BCorrect: any non-conformance makes XML bad
-
CCorrect only for internal DTDs
-
DCorrect only if namespaces are used
Answer
Correct Answer: Incorrect: it is not DTD-valid, but it may still be well-formed XML
Explanation
Introduction / Context:XML distinguishes between well-formedness (syntactic correctness per XML 1.0 rules) and validity (conformance to a DTD or schema). Confusing these leads to incorrect error handling and validation assumptions.
Given Data / Assumptions:
- We consider a document with a referenced DTD.
- The document may or may not conform to that DTD.
- “Bad XML” is not a formal term; the standards speak of well-formed vs. valid.
Concept / Approach:A document is well-formed if it obeys XML syntax: proper nesting, single root, quoted attributes, etc. It is valid if, in addition, it conforms to declarations in a DTD (or schema when using XSD). If a document does not conform to its DTD, it is invalid, but it can still be perfectly well-formed XML. Many XML workflows use schema validation instead of DTDs, or may not require validation at all.
Step-by-Step Solution:
Check well-formedness first (parser-level XML rules).If a DTD/schema is supplied, validate structure and datatypes.If rules do not match, label the document “invalid,” not “bad XML.”Verification / Alternative check:Most XML parsers offer a non-validating mode that still parses well-formed XML without consulting a DTD; failing validation does not make the XML unparsable.
Why Other Options Are Wrong:
- Calling the document “bad XML” conflates distinct concepts.
- Scope (internal vs external DTD) and namespaces do not change the definitions.
Common Pitfalls:Expecting validation errors to be the same as syntax errors. They are different; fix accordingly.
Final Answer:Incorrect: it is not DTD-valid, but it may still be well-formed XML