In order to avoid the difficulties inherent in parsing raw XML input, almost all programs that need to process XML documents rely on an XML parser to actually read the document.
The parser is a software library (in Java it’s a class) that reads the XML document and checks it for well-formedness.
Valid XML is XML that succeeds validation against a DTD.
Well formed XML is XML that has all tags closed in the proper order and, if it has a declaration, it has it first thing in the file with the proper attributes. Neither term says anything about semantics (the meaning of something).
@Quentin: that's an important point, and one that recognized XML experts agree on (lists.w3.org/Archives/Public/www-xml-linking-comments/… @Lego Stormtroopr: I agree with you, but my question was, where does the spec say so? w3.org/TR/REC-xml/#dt-valid tells what is sufficient - but not what is required - for a document to be "valid". an XML document checked against an XML Schema can be valid without having a DTD.
"The spec explicitly says ..."); but it's not entirely obvious from the XML spec. As such, this definition doesn't exclude the possibility of other ways for a document to be valid.
A program that makes a rudimentary check on the source of a document developed using the extensible markup language.
It does not consult the document type definition which describes the source, but carries out simple checks, such as ensuring that each tag is associated with its end tag.
Rather, well-formedness refers to a low level of syntax (maybe better referred to as lexical correctness), while validity refers to a higher level of syntax (call it "structural" if you like).
Note: The Namespaces in XML Recommendation [XML Names] assigns a meaning to names containing colon characters.
For validation to be possible, the XML document needs to be associated to a DTD or an XML schema. Up until this point, this lesson has concentrated on the non-validating parser.
This section examines the validating parser to find out what happens when you use it to parse the sample program.
The following sections describe how to use the Java programming language and Web Logic Server to develop XML applications.