Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 11

XML elements and attributes

www.satyam.com

Satyam Learning World

Objectives
XML elements Attributes of an element Text Empty elements Comments in an XML document Naming conventions for elements and attributes

www.satyam.com

Satyam Learning World

XML Elements
Elements can be defined as <element></element> Example: <satyam> </satyam> An element can contain other elements, simple text or a mixture of both.

www.satyam.com

Satyam Learning World

Attributes of an element
Attributes contain values that are associated with an element. They are a part of elements opening tag. Attribute value must be defined within quotes. Attributes can be defined as <element attribute=value></element> Example: <eltp_training phase=1> </eltp_training>
www.satyam.com

Satyam Learning World

Text
It is written between the opening and closing tags of an element. Text can be defined as <element attribute=value>text</element> Example<module duration=2 days>Operating System</module>

www.satyam.com

Satyam Learning World

Empty Elements

Elements without attributes and text. Example:<computer> </computer>

www.satyam.com

Satyam Learning World

Comments in XML

<! -- I am a valid XML comment -- >

www.satyam.com

Satyam Learning World

Naming conventions
Element names can contain letters, numbers and underscores. It cannot contain spaces, hyphens, colons and dots. It cannot start with non-alphabetical characters or numbers or the letters xml.

www.satyam.com

Satyam Learning World

Advantages of attributes over content element

they can have names that indicate the role the value plays in the element. Element contents have content names, but there is no way to say what role the content plays in any particular element that contains it. attributes can have default values. attributes have (minimal) data types attributes take up less space as there is no need for an end tag
www.satyam.com

attributes are easier to access in DOM.

Satyam Learning World

Some disadvantages
attributes aren't as convenient for large values, or binary entities. values containing quotes can be a bother. attributes can't contain other elements. white space can't be ignored in an attribute.

www.satyam.com

10

Satyam Learning World

Practice Scenario

Write XML documents providing information regarding your permanent and present address using proper elements and attributes along with comments.

www.satyam.com

11

Satyam Learning World

You might also like