Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

XML Documents : Page 6

XML documents are similar to HTML documents. They contain information and markup tags that define the information, and are saved as ASCII text.


advertisement
Elements
Elements are the basic building blocks of XML (and HTML, for that matter). Each element is a piece of data, identified by a tag. The tag contains the name of the element and any of its attributes, like this:

<AUTHOR dob="1864">Thadius J. Frog</AUTHOR>

Thadius J. Frog is now identified as an author element. This particular author element as a date of birth (dob) attribute value of 1864.

Chose Your Own
XML is an extensible markup language. This means you create a set of elements that work for your content—and that you'll be able to use consistently within the document.



Whether you use a DTD or not, you'll still want to sit down and write a list of the element names that you will be using in your document. XML is case-sensitive, so as you're thinking about the element names, be sure the think about how you capitalize them also.

Select names that are both easy to rememberer and easy to type. Ideally, your tags should have some inherent meaning too. This makes them easier to use. For example, if you want to identify "last name" as an element, consider naming the element something like "last-name" or "surname."

Be consistent in your use of names. It is easier to apply one set of general rules to 20 different tags than it is to remember eight discrete tags that follow no particular pattern. For example, if your document is a listing of classes, you could use these elements:

<list-of-classes>
<name-class>
<instructor-name>
<Sec>
<TIME>
<descprt>

But you're just asking for confusion!

There's a mix of capitalization. There's a mix of abbreviation and full words. In one case the phrase "name" is the first part of tag; in the other it is the second part of the tag. It isn't logical to remember this set of names.

Wouldn't names like this be easier to use?

<classlist>
<class>
<section>
<time>
<instructor>
<description>

Theses names are all lowercase, full words, no plurals—and easy set of criteria to remember.

Focus on Structure, Not Format
One of the goals of using XML is to separate structure ("this is an author") from format ("display this in 10 point Helvetica"). Elements remain identified as elements, no matter what platform you move the data to. An XML document is completely interpretable.

When you think about elements, think about the role they play and the data they contain. Don't think about how the elements will look on the page. Appearance is handled separately.

You are using elements to identify data within your document as playing a certain role or belonging to a certain category of data.

Displaying Elements
You can use any tag name you want, as long as you follow proper XML syntax. Of course, those tags alone won't do anything. They will just sit there quietly, marking up your data.

After you data is marked up, you'll use style sheets or other processing tools to display the XML document. You can control the display based on information contained in the elements.

Using Elements
In a well-formed XML document, you can insert any element tag you want, as long as you follow proper syntax.

In a valid XML document, only the elements which are specified in the DTD will pass muster. If you randomly add other elements, their use will be flagged as an error.

When you use elements in an XML document, you must follow standard XML syntax:

  • The element name surrounds the data which it defines. For example: <chapter-head>Tying Knots</chapter-head>.
  • All elements, including empty elements, must end. This means having an open and close tag for regular elements and a tag that closes with a slash for empty elements.
  • The element name is case sensitive: <AUTHOR>,is not the same as <author>.
DTDs and Elements

One of the ways to define and codify all your elements is to create a DTD. A DTD defines the allowable elements, their attributes (if any) are, and their relationship is to other elements.

By validating your XML document against a DTD, you can test to be sure that elements in the documents are being used correctly.





Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date