Making your XML admirable is basic to creating XML documents. Steve Holzner covers all aspects of well-formedness, including constraints, namespaces, infosets, and approved XML.
Yesterday, you took a attending at the assorted genitalia of XML documentsprologs, elements and attributes, processing instructions, and so forth. Today, you’re activity to alpha putting those items to assignment as you actualize admirable documents.
Why is it so important to accomplish an XML certificate well-formed? For one thing, W3C doesn’t accede an XML certificate to be XML unless it’s well-formed. For another, XML processors won’t apprehend XML abstracts unless those abstracts are well-formed. All of which is to say that authoritative your XML admirable is basic to creating XML documentssoftware isn’t alike activity to be able to apprehend your abstracts unless they are. Here’s an overview of today’s topics:
Well-formed XML documents
The W3C Well-formedness constraints
Element and aspect constraints
Local and absence namespaces
To some extent, the accepted apart accompaniment of HTML abstracts is amenable for the abundant accent W3C puts on authoritative abiding XML abstracts are well-formed. HTML browsers accept become added and added affable to HTML pages as time has gone on, which agency a Web folio can accept dozens of errors and still be displayed by a browser. That’s not such a botheration back it comes to artlessly announcement a Web page, but back it comes to administration what ability be acute data, it’s a altered story.
So W3C afflicted the rules from HTML to XMLunlike an HTML browser, an XML processor is never declared to assumption back it reads an XML document. If it finds an absurdity (if the certificate is not well-formed, or if it uses a DTD or XML action and it’s not valid), the XML processor is declared to acquaint you of the error, but again it can abdicate immediately. Ideally, according to W3C, a acceptance XML processor should account all the errors in an XML certificate and again quit; a non-validating one doesn’t alike accept to do thatit can abdicate the aboriginal time it sees an error.
This activated attention has two abandon to itthere’s no agnosticism that your abstracts is transferred added anxiously application XML, but because XML processors accomplish no guesses as to what you’re aggravating to do, XML and XML processors can appear beyond as non-user friendly, and not as acceptable or as accessible to assignment with as HTML. On the added hand, you don’t end up with the abounding accessible errors that can edge into HTML, and that’s important. XML authors accept to be acquainted of the constraints on what they write, which is why we absorb time in this book on certificate well-formedness and validity. In fact, in the XML 1.0 specification, W3C says that you can’t alike alarm a abstracts article an XML certificate unless it’s well-formed:
A abstracts article is an XML certificate if it is well-formed, as authentic in this specification. A admirable XML certificate may in accession be accurate if it meets assertive added constraints.
The W3C, which is amenable for the appellation well-formedness, defines it this way in the XML 1.0 recommendation:
A textual article is a admirable XML certificate if:
Taken as a whole, it matches the assembly labeled document.
It meets all the well-formedness constraints accustomed in this blueprint (that is, the XML 1.0 specification, http://www.w3.org/TR/REC-xml).
Each of the parsed entities, which is referenced anon or alongside aural the document, is well-formed.
Because the above differences amid XML 1.0 and XML 1.1 accept to do with what characters are legal, you apparently won’t be afraid to apprentice that a admirable XML 1.0 certificate is additionally a admirable XML 1.1 document, as continued as it avoids assertive characters. From the XML 1.1 specification:
If a certificate is admirable or accurate XML 1.0, and provided it does not accommodate any characters in the ambit [#x7F-#x9F] added than as appearance escapes, it may be fabricated admirable or accurate XML 1.1 appropriately artlessly by alteration the adaptation number.
Let’s get into three altitude that accomplish an XML certificate well-formed, starting with the claim that the certificate charge bout the assembly called document.
W3C calls the alone blueprint aural a alive abstract or advocacy productions. In this case, to be well-formed, a certificate must chase the certificate production, which agency that the certificate itself charge accept three parts:
a prolog (which can be empty)
a basis aspect (which can accommodate added elements)
a assorted allotment (unlike the above-mentioned two parts, this allotment is optional)
You’ve apparent XML prologs yesterday; they can accommodate an XML declaration (such as <?xml adaptation = “1.0”?>), as able-bodied as comments, processing instructions, and doctype declarations (that is, DTDs).
You’ve additionally apparent basis elements; the basis aspect is the XML aspect that contains all the added elements in your document. Anniversary admirable XML document charge accept one, and alone one, basis element.
The alternative assorted allotment can be fabricated up of XML comments, processing instructions, and whitespace, all items you saw yesterday.
In added words, this aboriginal claim says that an XML certificate charge be made up of the genitalia you saw yesterday. So far, so good.
The aing claim is a little added difficult to clue down, because it says that to be well-formed, XML abstracts charge additionally amuse the well-formedness constraints in the XML 1.0 specification. This agency that your XML documents should attach to the syntax rules defined in the XML 1.0 recommendation. You’ll altercate those rules, which are brindled throughout the XML 1.0 specification, in a few pages.
The final claim is that anniversary parsed article in a admirable document charge itself be well-formed. Back an XML certificate is parsed by an XML processor, article references (such as π) are replaced by the entities they angle for (such as þ in this case). The claim that all parsed entities charge be admirable artlessly agency that back you alter entity references with the entities they angle for, the aftereffect charge be well-formed.
That’s the W3C’s analogue of a admirable document, but you still charge added information. What are the well-formedness constraints given throughout the XML specification? You’re activity to go over these constraints today; to start, you’ll actualize an XML certificate that you’ll use as we altercate what it agency for a certificate to be well-formed.
How Well Formed Xml Can Increase Your Profit! | Well Formed Xml – well formed xml
| Allowed for you to my own weblog, with this time period I’ll teach you about well formed xml