../courses.php
XML
XML103
3
Use Attributes Safely
Attributes add small extra details inside an opening XML tag.
What is an XML attribute?
An XML attribute is extra information placed inside an opening tag as a name and quoted value.
XML elements can hold text between opening and closing tags.
Sometimes an element also needs a small extra detail.
That extra detail can be written as an attribute.
Attributes belong inside the opening tag.
Attribute values should be quoted.
A person element with an id attribute
<person id="7">
<name>Maya</name>
<city>Calgary</city>
</person>
person is the element name.
id is the attribute name.
"7" is the quoted attribute value.
The attribute is written inside the opening tag.
The child elements still hold the main information.
IDs
Attributes are often used for identifiers.
Metadata
They can add small details about an element.
Compact
They keep small values close to the tag.
Rules
They must be written carefully to keep XML well formed.
Unquoted attribute value
<person id=7>Maya</person>
Quoted attribute value
<person id="7">Maya</person>
Ask ChatGPT: "Are my XML attributes inside the opening tag and are all attribute values quoted?"
Create an XML element with an id attribute.
Create an XML element with a language attribute.
Identify the attribute name.
Identify the attribute value.
Explain why the value needs quotes.
Forgetting quotes around attribute values.
Putting attributes in the closing tag.
Using attributes for large text content.
Using unclear attribute names.
Forgetting that attributes are part of the opening tag.
Use XML attributes for small extra details such as IDs and metadata.
Login - Jit4All
Login
Welcome back to Jit4All