Logo

Navigation
  • Home
  • Services
    • ERP Solutions
    • Implementation Solutions
    • Support and Maintenance Solutions
    • Custom Solutions
    • Upgrade Solutions
    • Training and Mentoring
    • Web Solutions
    • Production Support
    • Architecture Designing
    • Independent Validation and Testing Services
    • Infrastructure Management
  • Expertise
    • Microsoft Development Expertise
    • Mobile Development
    • SQL Server Database and BI
    • SAP BI, SAP Hana, SAP BO
    • Oracle and BI
    • Oracle RAC
  • Technical Training
    • Learn Data Management
      • Business Intelligence
      • Data Mining
      • Data Modeling
      • Data Warehousing
      • Disaster Recovery
    • Learn Concepts
      • Application Development
      • Client Server
      • Cloud Computing Tutorials
      • Cluster Computing
      • CRM Tutorial
      • EDI Tutorials
      • ERP Tutorials
      • NLP
      • OOPS
      • Concepts
      • SOA Tutorial
      • Supply Chain
      • Technology Trends
      • UML
      • Virtualization
      • Web 2.0
    • Learn Java
      • JavaScript Tutorial
      • JSP Tutorials
      • J2EE
    • Learn Microsoft
      • MSAS
      • ASP.NET
      • ASP.NET 2.0
      • C Sharp
      • MS Project Training
      • Silverlight
      • SQL Server 2005
      • VB.NET 2005
    • Learn Networking
      • Networking
      • Wireless
    • Learn Oracle
      • Oracle 10g
      • PL/SQL
      • Oracle 11g Tutorials
      • Oracle 9i
      • Oracle Apps
    • Learn Programming
      • Ajax Tutorial
      • C Language
      • C++ Tutorials
      • CSS Tutorial
      • CSS3 Tutorial
      • JavaScript Tutorial
      • jQuery Tutorial
      • MainFrame
      • PHP Tutorial
      • VBScript Tutorial
      • XML Tutorial
    • Learn Software Testing
      • Software Testing Types
      • SQA
      • Testing
  • Career Training
    • Career Improvement
      • Career Articles
      • Certification Articles
      • Conflict Management
      • Core Skills
      • Decision Making
      • Entrepreneurship
      • Goal Setting
      • Life Skills
      • Performance Development
      • Personal Excellence
      • Personality Development
      • Problem Solving
      • Relationship Management
      • Self Confidence
      • Self Supervision
      • Social Networking
      • Strategic Planning
      • Time Management
    • Education Help
      • Career Tracks
      • Essay Writing
      • Internship Tips
      • Online Education
      • Scholarships
      • Student Loans
    • Managerial Skills
      • Business Communication
      • Business Networking
      • Facilitator Skills
      • Managing Change
      • Marketing Management
      • Meeting Management
      • Process Management
      • Project Management
      • Project Management Life Cycle
      • Project Management Process
      • Project Risk Management
      • Relationship Management
      • Task Management
      • Team Building
      • Virtual Team Management
    • Essential Life Skills
      • Anger Management
      • Anxiety Management
      • Attitude Development
      • Coaching and Mentoring
      • Emotional Intelligence
      • Stress Management
      • Positive Thinking
    • Communication Skills
      • Conversation Skills
      • Cross Culture Competence
      • English Vocabulary
      • Listening Skills
      • Public Speaking Skills
      • Questioning Skills
    • Soft Skills
      • Assertive Skills
      • Influence Skills
      • Leadership Skills
      • Memory Skills
      • People Skills
      • Presentation Skills
    • Finding a Job
      • Etiquette Tips
      • Group Discussions
      • HR Interviews
      • Interview Notes
      • Job Search Tips
      • Resume Tips
      • Sample Resumes
 

XML – Elements, Attributes, Entities

By Exforsys | on May 14, 2006 |
XML Tutorial

XML – Elements, Attributes, Entities

In this tutorial you will learn about Elements, Anatomy of tags, Tag naming rules, Invalid tags, Valid tags, Root and child elements, Attributes, When Do I use Attributes? Entities, Character data sections, Comments and Processing instructions.

{mos_ri}

Elements

Elements are the basic building blocks of XML

It may contain
– Other elements
– Character data
– Character references
– Entity references
– Comments
– These are collectively known as element content

Ex: < student > Mason Hill < /student >

An Element consists of three parts
1. Opening Tag < student >
2. Description Mason Hill
3. Closing Tag < /student >

Anatomy of tags

All elements must have a beginning and ending tag. The opening tag of an element is written between (< ) less than and ( >)greater than sign example, < student >. The ending tag is written between (< ) less than followed by a (/) forward slash and the ( >)greater than sign example, < /student >.

Data between the opening and closing tags of an element are its contents.

For example,

< student >Nick Price< /student >

Here Nick Price is the content of the element. Most of the browsers ignore whitespaces between the tags

< student > Nick Price < /student >

Is same as

< student >
Nick Price
< /student >

Note: Unlike HTML single tags(like < /br > in HTML ) in XML are not possible.

Tag naming rules

  • XML Names must begin with
    – A letter,
    – underscore(_),
    – colon (:) and
    – valid name characters including the preceding plus digits, hyphens (-) or full stops .
  • The colon character should not be used, except as a namespace delimiter
  • XML naming conventions is not limited to ASCII characters and ideographic characters could be used.
  • It may not begin with the string “xml”,”XML”, or any match of these characters

Based on above rules examples of

Invalid tags

< .stock >< /.stock >
< product1 >< / product1 >
< product^stock >< /product^stock >

Valid tags

< _stock >< /_stock >
< product1 >< /product1 >
< product-stock >< /product-stock >

Root and child elements

The root Element is the first element in a document and it contains all other elements. In the following example student is the root element and all other elements are contained within it (name, roll-number) are child elements.

< student >
< name >
Bill Gates
< /name >
< roll-number >
55
< /roll-number >
< /student >


In XML one cannot overlap tags. The opening and ending tags of child elements must be inside the parent element. Overlap of tags with siblings is not allowed as shown in the following example.

< student >
< name >
< roll-number >
Jason
< /name >
< /roll-number >
< /student >

The proper format is as follows

< student >
< name >
Jason
< /name >
< roll-number >
< /roll-number >
< /student >

The root element is also called the Document element. There is only one root element . All other elements lie within the root.

NOTE: A Tag could be empty i.e. contain no data like the roll-number tag in above example. Such tags are called EMPTY ELEMENTS.

Attributes

Attributes give the information about the elements. They can be specified only in the element start tag and their values are enclosed strictly in double quotation-mark. This is unlike HTML where attributes could be in single, double or without quotations.

Syntax: < tag attribute = “value” >description < /tag >

Example:

< problem size=“huge” cause=“unknown” solution=“run away” >

If elements are the “nouns” of XML, then attributes are its “adjectives”.An Element can have zero, one or more attributes. Also an attribute name can only appear once within an element

Bad: < Test name=“John” name=“Doe” / >
Good: < Test first=“John” last=“Doe” / >

The million dollar question

When Do I use Attributes?

Unfortunately there is no definite answer to this question. There are many contrarian views on the use of attributes. It is widely accepted belief that attributes are metadata i.e. data about data . In such scenarios use of attributes is recommended. For example , the lang attribute describing the language of the content of the element.

Entities

Entity references are placeholders for other values that are otherwise reserved in the language or that maybe misinterpreted. For example the less than (< ) and the greater than ( > ) symbols are reserved for demarking the tags. If the entity description itself contains one of these symbols the data would be misinterpreted. To avoid such a scenario Entities are used. The ampersand (&) symbol is reserved to indicate start of an entity.

The various predefined entities are as follows

<

LESS THAN

>

GREATER THAN

&

AMPERSAND

"

QUOTATIONS

&apos

APOSTROPHEE

 

 

 

.

Character data sections

Character data sections contain raw data that are not parsed by XML parsers.

Syntax : < ![CDATA[ raw data ]] >

Example:

< book ISIN = “INB101235647” >
< author >
Kacey Price
< ![CDATA[ kacey has also authored “Complete Reference ” series]] >
< /author >
< /book >

Comments

Comments are enclosed in < !—Comments — >

Example :

< !—This is start of second child element — >

Processing instructions

Processing instructions are used to pass information to applications which use this information to execute special task.

Syntax : < ? ? >

Example

< ?xml version=”1.0” encoding= “ISO-8859-1”? >

NOTE: Here the version attribute specifies the version of XML being used while encoding gives the encoding format for parsers.

A xml document displayed in IE 5.0 or above.

« « XML Introduction
PHP Tutorial – Installation » »

Author Description

Avatar

Editorial Team at Exforsys is a team of IT Consulting and Training team led by Chandra Vennapoosa.

Free Training

RSSSubscribe 394 Followers
  • Popular
  • Recent
  • XML Processing

    July 16, 2007 - 0 Comment
  • XML – Document Type Definitions (DTD)

    June 14, 2006 - 0 Comment
  • XML Remote Calling Procedure

    July 19, 2007 - 0 Comment
  • XML – Elements in Document Type Definitions (DTD)

    June 14, 2006 - 0 Comment
  • XML Security

    July 21, 2007 - 0 Comment
  • Working with XML in Flash

    August 30, 2007 - 0 Comment
  • XML SQL Server

    July 23, 2007 - 0 Comment
  • Working with XML in Python

    September 2, 2007 - 0 Comment
  • XML and Service Oriented Architecture

    July 25, 2007 - 0 Comment
  • Working with XML in Perl

    September 6, 2007 - 0 Comment
  • Working with XML in C

    September 7, 2007 - 0 Comment
  • Working with XML in Perl

    September 6, 2007 - 0 Comment
  • Working with XML in Python

    September 2, 2007 - 0 Comment
  • Working with XML in Flash

    August 30, 2007 - 0 Comment
  • Working with XML in Oracle

    August 30, 2007 - 0 Comment
  • Working with XML in Visual Basic

    August 28, 2007 - 0 Comment
  • Using XML with Microsoft Excel

    August 24, 2007 - 0 Comment
  • XML Spy

    August 24, 2007 - 0 Comment
  • XML and Service Oriented Architecture

    July 25, 2007 - 0 Comment
  • XML SQL Server

    July 23, 2007 - 0 Comment

Exforsys e-Newsletter

ebook
 

Related Articles

  • Working with XML in C
  • Working with XML in Perl
  • Working with XML in Python
  • Working with XML in Flash
  • Working with XML in Oracle

Latest Articles

  • Project Management Techniques
  • Product Development Best Practices
  • Importance of Quality Data Management
  • How to Maximize Quality Assurance
  • Utilizing Effective Quality Assurance Strategies
  • Sitemap
  • Privacy Policy
  • DMCA
  • Trademark Information
  • Contact Us
© 2023. All Rights Reserved.IT Training and Consulting
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject Read More
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT