XML Well-Formed |
|
Well-Formedness |
Tag Creation |
Earlier, we mentioned that XML works through markups. A simple markup is made of a tag created between the left angle bracket "<" and the right angle bracket ">". Just creating a markup is not particularly significant. You must give it meaning. To do this, you can type a number, a date, or a string on the right side of the > symbol. The text on the right of the right angle bracket ">" is referred to as the item's text. In the .NET Framework, it is called a value. After specifying the value of the markup, you must close it: this is a rule not enforced in HTML but must be respected in XML to make it "well-formed". To close a tag, use the same formula of creating a tag with the left angle bracket "<", the tag, and the right angle bracket ">" except that, between the < symbol and the tag, you must type a forward slash. The formula to use is: <tag>some value</tag> The item on the left side of the "some value" string, in this case <tag>, is called the opening or start-tag. The item on the right side of the "some value" string, in this case </tag>, is called the closing or end-tag. Like<tag> is a markup, </tag> also is called a markup. As mentioned previously, with XML, you create your own tags with custom names. This means that a typical XML file is made of various items. Here is an example: |
<title>The Distinguished Gentleman</title><director>Jonathan Lynn</director><length>112 Minutes</length>
<title>The Distinguished Gentleman</title> <director>Jonathan Lynn</director> <length>112 Minutes</length>
Yet a better solution consists of typing each element on its own line. This would make the document easier to read. Here is an example: <title>The Distinguished Gentleman</title> <director>Jonathan Lynn</director> <length>112 Minutes</length> All these are possible and acceptable because the XML parser doesn't consider the empty spaces or end of line. Therefore, to make your code easier to read, you can use empty spaces, carriage-return-line-feed combinations, or tabs inserted in various sections. All these are referred to as white spaces.
Most XML files contain more than one tag. We saw that a tag most have a starting point and a tag must be closed as seen in the above example. One tag can be be included in another tag: this is referred to as nesting. A tag that is created inside of another tag is said to be nested. A tag that contains another tag is said to be nesting. Consider the following example: <Smile>Please smile to the camera</Smile> <English>Welcome to our XML Class</English> <French>Bienvenue à notre Classe XML</French> In this example, you may want the English tag to be nested in the Smile tag. To nest one tag inside of another, you must type the nested tag before the end-tag of the nesting tag. For example, if you want to nest the English tag in the Smile tag, you must type the whole English tag before the </Smile> end tag. Here is an example: <Smile>Please smile to the camera<English>Welcome to our XML Class</English></Smile> To make this code easier to read, you can use white spaces as follows: <smile>Please smile to the camera <English>Welcome to our XML Class</English> </smile> When a tag is nested, it must also be closed before its nesting tag is closed. Based on this rule, the following code is ill-formed: <Smile>Please smile to the camera <English>Welcome to our XML Class </Smile> </English> The rule broken here is that the English tag that is nested in the the Smile tag is not closed inside the Smile tag but outside.
|
|
||
Previous | Copyright © 2004-2010 FunctionX, Inc. | Next |
|