ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing

ExpertRating Home
ExpertRating Benefits
Recommend ExpertRating
Suggest More Tests
Privacy Policy
FAQ
Login
 
XML Tutorial - Index
XML Tutorial - Introduction to XML
XML Tutorial - How XML interact with data?
XML Tutorial - How to write first XML document
XML Tutorial - What are XML Elements and Attributes?
XML Tutorial - What is XML Schema and DTD?
XML Tutorial - Which Browser support XML?
XML Tutorial - XML and Styles
XML Tutorial - Embedding XML in HTML
XML Tutorial - Working with XML Parser
XML Tutorial - Working with CDATA
     

 
Online Personal Trainer Certification
Personal Trainer Certification (Spanish)
Six Sigma Certification
Find a Personal Trainer
Project Management Certification
Six Sigma Certification
Six Sigma Black Belt Certification
Master Black Belt Certification
Six Sigma Green Belt Certification
Life Coach Certification
Lean Management Certification
Lean Six Sigma Certification
First Aid Certification
CPR Certification
Yoga Certification
Aerobics Certification
Pilates Certification
Business Analyst Certification
SEO Certification
Online Business Writing Course & Certification
Makeup Artist Certification
Baby Sitting Course & Certification
Time Management Certification
Health Club Management Certification
Medical Coding Certification
Medical Billing Certification
Business Analysis Course
Master Trainer Certification
Total Quality Management Certification
Kaizen Certification
Creative Writing Certification
Event Management Certification
Test Search by Job Title
Administrative Assistant Certification
Virtual Assistant Certification
  All Online Courses
   

   
   
   
   
   
   

   
  Home > Courses, Tutorials & eBooks > XML Tutorial > What are XML Elements and Attributes?
 

XML Tutorial - What are XML Elements and Attributes?

 
Page 2 of 2
 

Naming rules for Element Tags and Attribute Names

  • Element tag names  and Attribute names can begin with a letter, a colon, or an underscore, but NOT  with numbers.

  • Subsequent characters may include alphanumeric, underscores, hyphens, and colons.

  • Names cannot contain certain XML-specific symbols like the ampersand (&), the "at" symbol (@), or the "less-than" symbol (<).

  • Element tag names and Attribute names cannot contain white space.

  • Names cannot contain parenthetic statements ( words enclosed in parentheses or brackets ).

Which has a better usage, element or attribute ?

The classic XML design question, asked by adopters is when to use elements and attributes in XML design. Elements are used to encapsulate pieces of data, and attributes are generally used to provide accompanying information about an element. So, given below are the benefits and disadvantages of both elements and attributes and these can be used as a guiding principle for using elements and attributes :

Benefits of Using Elements

  • They are more extensible because attributes can later be added to them without affecting a processing application.

  • They can contain other elements.

  • They can be repeated.

  • You have more control over the rules of their appearance. For example, you can say that a product can either have a number or a product code child. This is not possible for attributes.

  • Their order is significant if specified as part of a sequence, while the order of attributes is not. Obviously, this is only an advantage if you care about the order.

  • When the values are lengthy, elements tend to be more readable than attributes.

Disadvantages of Using Elements

Elements require start and end tags, so are therefore more verbose.

  • Note
       Not all elements require a start and end tag - elements can be declared in a single line.

Benefits of Using Attributes

They are less verbose.

Attributes can be added to the instance by specifying default values.

Attributes are atomic and cannot be extended and its existence should serve to remove any and all possible ambiguity of the element it describes.

Disadvantages of Using Attributes

Attributes may not be extended by adding children, whereas a complex element may be extended by adding additional child elements.

If attributes are to be used in addition to elements for conveying business data, rules are required for specifying when a specific data item shall be an element or an attribute.

 
Summary
 

In this chapter you have learnt:

  • About the importance of XML elements and attributes.
  • What are various rules to be followed while naming attributes and elements?
  • What is better to use, amongst element and attribute?
  • Various benefits and drawbacks of using elements.
  • Benefits and drawbacks of using attributes.

 

 
Review Questions
 

Fill in the Blanks

  1. The opening tag for an element is also called as ------- tag.
  2. <SmithBaker> will end with the -------- tag.
  3. </Tim> is an ---------- element.-------
  4. provide additional information for an element.
  5. Element tag names can begin with a ---------, a colon or an ---------.

Solutions

  1. start
  2. </SmithBaker>
  3. empty
  4. Attributes
  5. letter, underscore

Which of the following are valid declarations?

  1. <Liza> She is a banker </liza>
  2. <switch><bulb>Second switch from the right, on the switch board, is for bulb.</switch></bulb>
  3. </Switch>
  4. <Student class = "fifth'> Rosa </Student>
  5. <Bird type= 'non-flying'> Penguin </Bird>

Solutions

  1. Invalid. The start tag does not match with the end tag. XML is case-sensitive.
  2. Invalid. The overlapping of tags is not allowed in XML.
  3. Valid. This is an empty tag.
  4. Invalid. The quotes, in which the value of the attribute is given, does not match with each other.
  5. Valid.

 

 
What's Next

The next chapter will acquaint you with the basic concepts of XML schema and a DTD. The chapter will further elucidate the types of DTD's and how a document is validated.

                 Hop over to the next chapter to get an XML schema and DTD close-up.
 
   
 
 
     
Home  |  About Us  |  Privacy Policy  |  Site Map  |  FAQs  |  Contact Us
 
© ExpertRating 2015. All Rights Reserved.