Professional Documents
Culture Documents
XML Elements and Attributes: Satyam Learning World
XML Elements and Attributes: Satyam Learning World
www.satyam.com
Objectives
XML elements Attributes of an element Text Empty elements Comments in an XML document Naming conventions for elements and attributes
www.satyam.com
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
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
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
Empty Elements
www.satyam.com
Comments in XML
www.satyam.com
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
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
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
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