The Wayback Machine - https://web.archive.org/web/20240816044923/https://www.geeksforgeeks.org/xml-attributes/
Open In App

XML | Attributes

Last Updated : 14 Feb, 2022
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Prerequisite: XML | Basics
The XML attribute is a part of an XML element. The addition of attribute in XML element gives more precise properties of the element i.e, it enhances the properties of the XML element.
Syntax: 
 

<element_name attribute1 attribute2 ... > Contents... </element_name>

In the above syntax element_name is the name of an element which can be any name. The attribute1, attribute2, … is XML attribute having unique attribute name. Then in the content section, any message can be written and at the end, the element name is ended.
Below some examples are given which illustrate the above syntax:
Example 1: 
 

XML




<text category = "message">Hello Geeks</text>


In the above example, XML element is text, the category is the attribute name and message is the attribute value, Attribute name and its value always appear in pair. The attribute name is used without any quotation but attribute value is used in single ( ‘ ‘ ) or double quotation ( ” ” ).
Example 2: 
 

XML




<text category = "message" purpose ="Greet">Hello Geeks</text>


In the above example, two attribute is used with different name. So, in a single element multiple attribute is used having unique attribute name. 
But if we use two distinct element then we can use the attribute having the same attribute name. This can be understood with the help of below example: 
Example 3: 
 

XML




<text category = "message" >Hello Geeks.</text>
<text category = "message">How are you.</text>


Attribute Types: 
There are three types of attributes described below: 
 

  • String types Attribute: This type of attribute takes any string literal as a value.
  • Enumerated Type Attribute: This attribute is further distributed in two types- 
    • Notation Type: This attribute is used to declares that an element will be referenced to a notation which is declared somewhere else in the XML document.
    • Enumeration: This attribute is used to specify a particular list of values which match with attribute values.
  • Tokenized Type Attribute: This attribute is further distributed in many types: 
    • ID: This attribute is used to identify the element.
    • IDREF: This attribute is used to refer an ID which has already been named for another element.
    • IDREFS: This attribute is used to refer all IDs of an element.
    • ENTITY: This attribute is used to indicate the attribute which will represent an external entity used in the document.
    • ENTITIES: This attribute is used to indicate the attribute which will represent external entities used in the document.

Rules for creating an attribute: There are some rules that should be followed while creating an attribute: 
 

  • An attribute should not repeat itself in a single start or empty-element tag.
  • An attribute should be declared using the attribute-list declaration in the DTD (Document Type Definition).
  • An attribute element is used without any quotation and the attribute value is used in a single (‘ ‘) or double quotation (” “).
  • An attribute name and its value should always appear in pair.
  • An attribute value should not contain direct or indirect entity references to external entities.

 



Similar Reads

Difference Between text/xml and application/xml for Webservice Response
application/xmlThis is the recommended media type for XML data according to the IETF specifications [RFC 7303]. It signifies that the XML content might not be human-readable and could potentially contain processing instructions or other non-human-consumable elements. Syntax:Content-Type: application/xmlThis example demonstrates a web service respon
2 min read
How to remove all attributes of an HTML element using jQuery ?
In this article, we will see how to remove all attributes of an HTML element using jQuery. To remove all attributes of elements, we use the removeAttributeNode() method and .removeAllAttributes(). Syntax: $.fn.removeAllAttributes = function() { return this.each(function() { $.each(this.attributes, function() { this.ownerElement.removeAttributeNode(
1 min read
HTML DOM attributes Property
The attributes property in HTML DOM returns the group of node attributes specified by NamedNodeMap objects. The NamedNodeMap object represents the collection of attribute objects and can be accessed by index number. The index number starts at 0. Syntax: node.attributes Return Value: It returns the NamedNodeMap object which is the collection of node
2 min read
jQuery | Set Content and Attributes
Set Content: It is used to set the content using jQuery. The following methods are used to set the content which are listed below: text(): It is used to set or return the text content of selected elements. html(): It is used to set or return the innerHTML content of the selected element. val(): This parameter is used to set or return the value of a
2 min read
jQuery | Get Content and Attributes
Get Content: In order to get the content of DOM object, there are three simple methods.jQuery methods for DOM manipulation which are listed below: text(): It is used to set or return the text content of selected elements. html(): It is used to set or return the content of selected elements including HTML markup. val(): It is used to set or return t
2 min read
How to conditionally add attributes to React components?
We can conditionally add attributes to React components with the following approaches: Approach 1: Evidently, with some attributes, React is smart enough to omit the attribute if the value you pass to it is not truthy. For example: state= { disabled: false, required: true } return ( &lt;input type="text" disabled={disabled} required={required} /
2 min read
Blaze UI Divider Attributes
Blaze UI is a user interface toolkit that provides a strong foundation and many components to building maintainable and scalable websites efficiently. All the features of Blaze UI rely on native browser features so it does not require an additional framework or library to work. In this article, we will be seeing Blaze UI Divider Attributes. The Div
3 min read
PHP | SimpleXMLElement attributes() Function
Pre-requisite: Read XML BasicsThe SimpleXMLElement::attributes() function is an inbuilt function in PHP which is used to retrieve the attributes and its value from an XML tag in a SimpleXML object. Syntax: SimpleXMLElement SimpleXMLElement::attributes( $namespace, $is_prefix ) Parameter: This function accepts two parameters as mentioned above and d
2 min read
Difference between 'hidden' and 'aria-hidden' attributes in HTML
The HyperText Markup Language (HTML) is a powerful web development tool combined with CSS and JavaScript. Apart from these, HTML also uses Accessible Rich Internet Application (ARIA) to make web content affable for a person with disabilities. Although ARIA is beneficial, there are keywords common to both HTML and ARIA, creating perplexity among ama
2 min read
Copy all the attributes of one element and apply them to another with JavaScript
The task is to copy all attributes of one element and apply them to another with the help of JavaScript. Here 2 approaches are discussed. Approach 1: Select both elements(target and source element).Get the properties of source element by using el.prop('attributes') method.Use .each() method on each object property and set that property to the targe
2 min read
Why are dashes preferred for CSS selectors / HTML attributes ?
CSS is a hyphen-delimited syntax language which means while writing HTML attributes we can use hyphen(-). Example: font-size, line-height, background-color, etc... There are various reasons to preferring hyphen(-): In CSS, one can use underscore(_) instead of hyphen(-) for CSS selectors(class, id, span, ...), but preference is given based on its ea
2 min read
What is the difference between properties and attributes in HTML?
HTML is the standard language for creating documents that are intended to be displayed on web browsers. It is very usual to get confused with attributes and properties while performing DOM object manipulation in JavaScript. Before learning about the differences, let us first define the Document Object Model. DOM: It is the acronym for the Document
4 min read
What are these attributes `aria-labelledby` and `aria-hidden` ?
The term, ARIA with attributes such as aria-labelledby and aria-hidden stands for Accessible Rich Internet Applications. These are the set of standards and guidelines that makes web applications more accessible to people with disabilities. This is used in the interactive content in an HTML document such as error messages, progress bars, progressive
3 min read
SVG Element.attributes Property
The SVG Element.attributes property returns an object that contains all the attributes of the given element. Syntax: var attr = element.attributes Return value: This property returns an object that contains all the attributes of the element. Example 1: C/C++ Code &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;body&gt; &lt;svg width=&quot;350&quot; height=
1 min read
Design a table using table tag and its attributes
In this article, we will create a table using HTML. To create this table, we must know the tags required to create the table. At first, we will create the structure of the table and we will use attributes to design the table. Approach: To create the table we have to use the &lt;table&gt; tag and we will use attributes of the &lt;table&gt; tag to de
1 min read
How to add attributes to an HTML element in jQuery?
Given an HTML document containing some elements and the task is to add the attributes to the HTML elements. Approach: Given an HTML document containing &lt;label&gt;, &lt;input&gt; and &lt;button&gt; elements. The &lt;input&gt; element contains the type and id attribute. When user click on the button, the jQuery function is called. We use $(selecto
1 min read
ASP Attributes Property
The ASP Attributes Property is used for returning or setting the attributes of the specified file or folder. The attributes are defined with the following numerical values: 0: Normal file1: Read-only file2: Hidden file4: System file6: Folder or directory32: The file has changed since the last backup1024: Link or shortcut2048: Compressed file Syntax
2 min read
Blaze UI Autocomplete Attributes
Blaze UI is a free open-source UI toolkit that provides a strong and maintainable foundation to develop scalable web solutions. All the components of Blaze UI are developed mobile-first and rely on native browser features, not on any additional library or framework. In this article, we will be seeing Blaze UI Autocomplete Attributes. The Autocomple
2 min read
Backbone.js attributes View
Backbone.js attributes view are nothing but a hash of attributes which are set as HTML DOM element attributes on the view's el. For example, (id, class, data-properties, etc.), or in other cases, a function that returns a hash. Syntax: view.attributes Parameters: View: It is a class under Backbone which is implemented as Backbone.View.extend( { } )
2 min read
Placeholder vs Value Attributes in HTML
Placeholder Attribute:The placeholder attribute specifies a short hint that describes the expected value of an input field/textarea. The short hint is revealed in the field before the user enters a value. It is just a temporary hint and has nothing to do with logical executions in the backend. Syntax: &lt;input placeholder = "text"&gt; &lt;textarea
3 min read
How to Define Multiple CSS Attributes in jQuery ?
In jQuery, you can define multiple CSS attributes for an element using the css() method. This method allows you to set one or more CSS properties for an element. In this article, we will see the different ways to define multiple CSS attributes in jQuery. Syntax: The syntax for defining multiple CSS attributes using the jQuery css() method. $(select
2 min read
What are HTML tags & Attributes mandatory for a good Web page in SEO ?
Search engine optimization (SEO) is the process that involves enhancing the visibility of a website on search engines. This is achieved by increasing the website's ranking on search engine results pages, such as Google. The higher the website appears on these pages, the more likely it is to receive a larger volume of traffic. SEO involves understan
5 min read
Blaze UI Badges Attributes
Blaze UI is a framework-free open source UI toolkit that uses JavaScript components to build great user interfaces. It is the same as a bootstrap for use and has great different elements to use to make your website look more amazing. This framework allows us to use various of its styles and properties to make a website more user-friendly. Blaze UI
3 min read
Blaze UI Timelines Attributes
Blaze UI is a CSS open-source lightweight UI toolkit that provides great tools for building customized and scalable applications. It can work with any framework that exists. It can adapt to any ecosystem. All designs or CSS are mobile-first and hence responsive. Blaze UI Timelines are used to illustrate the events that occurred according to their t
3 min read
Blaze UI Counter Attributes
Blaze UI is an open-source user interface library that comes with a lot of components that help in reducing the development time of the website. All the components of Blaze UI are mobile-first and work well on devices of all screen sizes. All the features of Blaze UI rely on native browser features rather than a library or a framework which makes i
3 min read
Blaze UI File Upload Attributes
Blaze UI is a framework-free open source UI toolkit that uses JavaScript components to build great user interfaces. It is the same as a bootstrap for use and has great different elements to use to make your website look more amazing. This framework allows us to use various of its styles and properties to make a website more user-friendly. Blaze UI
2 min read
Blaze UI Image Attributes
Blaze UI is a CSS open-source framework. It is a lightweight UI toolkit and provides great tools for building customized and scalable applications. It can work with any framework that exists. It can adapt to any ecosystem. All designs or CSS are mobile-first and hence responsive. Its project is available open-source so a large community maintains i
2 min read
Blaze UI Drawers Attributes
Blaze UI is a CSS open-source framework. It is a lightweight UI toolkit that provides great tools for building customized and scalable applications. It can work with any framework that exists. It can adapt to any ecosystem. All designs or CSS are mobile-first and hence responsive. Its project is available open-source so a large community maintains
3 min read
Blaze UI Alerts Attributes
Blaze UI is a framework-free open source UI toolkit that uses JavaScript components to build great user interfaces. It is the same as a bootstrap for use and has great different elements to use to make your website look more amazing. This framework allows us to use various of its styles and properties to make a website more user-friendly. Blaze UI
2 min read
Blaze UI Avatars Attributes
Blaze UI is a framework-free open source UI toolkit that uses JavaScript components to build great user interfaces. It is the same as a bootstrap for use and has great different elements to use to make your website look more amazing. This framework allows us to use various of its styles and properties to make a website more user-friendly. We can us
3 min read
three90RightbarBannerImg