learn xml in 11.5 minutes by l.c. rees
|
To learn XML, open a text editor like SimpleText or Notepad and type: <?xml version="1.0"?> <PARENT> <CHILD> This is content. </CHILD> <EMPTY/> </PARENT> Save this as wellform.xml. Let's examine the XML you just created in detail. <?xml version="1.0"?> declares your XML is version 1.0, so programs know to use it like XML 1.0. <PARENT> is markup. XML is divided into markup and content. Markup is information about content, describing it to any level of detail desired. Correct markup must follow certain rules. First, markup containing content must have opening and closing tags. <PARENT> is an opening tag. </PARENT> is a closing tag. Opening tags start with < and close with >. Closing tags start with </ and close with >. Second, markup must nest properly. Markup tags divide into parents and children. Parent markup encloses child markup. A child's opening and closing tags must be contained within its parent's opening and closing tags. You can have... ...but not...<PARENT> <CHILD> This is content. </CHILD> </PARENT> ...or...<PARENT> <CHILD> This is content. </PARENT> </CHILD> <CHILD> <PARENT> This is content. </CHILD> </PARENT> Third, if markup contains no content, it must begin with < and end with /> like <EMPTY/>.
So if you...
<?xml version="1.0"?> <!DOCTYPE PARENT [ <!ELEMENT PARENT (CHILD*)> <!ELEMENT CHILD (MARK?,NAME+)> <!ELEMENT MARK EMPTY> <!ELEMENT NAME (LASTNAME+,FIRSTNAME+)*> <!ELEMENT LASTNAME (#PCDATA)> <!ELEMENT FIRSTNAME (#PCDATA)> <!ATTLIST MARK NUMBER ID #REQUIRED LISTED CDATA #FIXED "yes" TYPE (natural|adopted) "natural"> <!ENTITY STATEMENT "This is well-formed XML"> ]> <PARENT> &STATEMENT; <CHILD> <MARK NUMBER="1" LISTED="yes" TYPE="natural"/> <NAME> <LASTNAME>child</LASTNAME> <FIRSTNAME>second</FIRSTNAME> </NAME> </CHILD> </PARENT> Save it as valid.xml. Valid XML is more complex than the well-formed XML used in simple.xml so let's examine its parts in detail. <?xml version="1.0"?>, fills the same role it did in simple.xml. The second line, <!DOCTYPE PARENT [, declares this section is a document type definition or DTD and its name(PARENT). A DTD is the primary distinction between well-formed and valid XML. Well-formed XML can give you a vague idea of an XML document's purpose but leaves room for doubt. A DTD eliminates this by providing a stringent standard to measure a document against. A DTD declares each part of an XML document and its proper form exactly. This DTD is named PARENT. DTD's are enclosed between an opening [ and a closing ]>. <!ELEMENT PARENT (CHILD)*>, shows a DTD's most basic part, the element.
An element defines markup's name and form. <!ELEMENT PARENT (CHILD*)> declares:
The next line, <!ELEMENT CHILD (MARK?,NAME+)>, lists the children of the child CHILD. It lists:
...or...<CHILD> <NAME> </NAME> </CHILD> ...but never...<CHILD> <MARK/> <NAME> </NAME> </CHILD> <CHILD> <MARK/> </CHILD> <!ELEMENT MARK EMPTY>shows the element value EMPTY. This indicates markup containing no content like... ...or...<MARK/> ...from simple.xml.<EMPTY/>
The following line, <!ELEMENT NAME (LASTNAME+,FIRSTNAME+)*>, tells us:
The next two lines contain #PCDATA. #PCDATA indicates when markup contains content. This can be anything and does not have to follow the same rules as markup. The following line contains another DTD fundamental, the attribute An attribute is a description given to an element to further define it. Attributes are declared in attribute lists. The attribute list in valid.xml... ...tells you:<!ATTLIST MARK NUMBER ID #REQUIRED LISTED CDATA #FIXED "yes" TYPE (natural|adopted) "natural">
...where, of the attributes of MARK, "1" is required and unique, "yes" is regular text and fixed, and "natural" is the chosen, default choice.<MARK NUMBER="1" LISTED="yes" TYPE="natural"/> VALID.XML next brings up a third DTD part, the entity. The entity points to a something that can be inserted at any point in the XML document. The line <!ENTITY STATEMENT "This is well-formed XML"> inserts This is well-formed XML whenever &STATEMENT; appears. The DTD then closes with ]> and the rest of the XML document follows it as outlined. You have learned XML in 11.5 minutes. |
. |
home |