XML
Introduction
XML attributes
XML attributes
- You can include one or more attributes in the start tag for an element.
- An attribute typically consists of an attribute name, an equal sign, and a string value in quotes.
- If an element has more than one attribute, the order in which the attributes appear doesn't matter, but the attributes must be separated by one or more spaces.
When to use attributes instead of child elements
- The choice of whether to implement a data item as an attribute or as a separate child element is often a matter of preference.
- Two advantages of attributes are:
- they can appear in any order
- they are more concise because they do not require end tags
- Two advantages of child elements are:
- they're easier for people to read
- they're more convenient for long string values
How to specify a DTD file in an XML document
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE Products SYSTEM "products.dtd"> <Products> <Product Code="java"> <Description>Murach's Beginning Java</Description> <Price>49.5</Price> </Product> <Product Code="jsps"> <Description>Murach's Java Servlets and JSP</Description> <Price>49.5</Price> </Product> </Products>