Skip to Content
Special Edition Using XML, Second Edition
book

Special Edition Using XML, Second Edition

by - et al. David Gulbransen
July 2002
Intermediate to advanced
864 pages
22h 32m
English
Que
Content preview from Special Edition Using XML, Second Edition

When to Use Attributes

It would be possible to create an entire document using nothing but elements. After all, you can use elements to mark up any kind of data. For example, we could describe a camera using only elements:

<camera> 
 <manufacturer>Nikon</ manufacturer>
 <model>D1</model>
 <lens>28mm</lens>
 <format>35mm</format>
</camera>

There is nothing wrong with this approach. In fact, often elements are more flexible than attributes, and can be easier to alter. However, we could also structure this XML using attributes:

<camera manufacturer="Nikon" model="D1" lens="28mm" format="35mm"> 
</camera>

With an example of this level of simplicity, there isn't really a huge impact in the differences between using elements versus attributes. However, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

XML Pocket Reference, 3rd Edition

XML Pocket Reference, 3rd Edition

Simon St. Laurent, Michael Fitzgerald
Essential XML: Beyond Markup

Essential XML: Beyond Markup

Don Box, Aaron Skonnard, John Lam

Publisher Resources

ISBN: 078972748XPurchase book