1. The syntax rules were:
- XML documents must have a root element
- XML elements must have a closing tag
- XML tags are case sensitive
- XML elements must be properly nested
- XML attribute values must be quoted. Metadata (data about data) should be stored as attributes, and the data itself should be stored as elements.
XML Attributes for Metadata
Sometimes ID references are assigned to elements. These IDs can be used to identify XML elements in much the same way as the id attribute in HTML. This example demonstrates this:
| <messages> <note id="501"> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> <note id="502"> <to>Jani</to> <from>Tove</from> <heading>Re: Reminder</heading> <body>I will not</body> </note> < /messages> |
The id attributes above are for identifying the different notes. It is not a part of the note itself.
Note: metadata (data about data) should be stored as attributes, and the data itself should be stored as elements.
2. XML Parser
An XML parser converts an XML document into an XML DOM object - which can then be manipulated with a JavaScript.
3. XML DOM
A DOM (Document Object Model) defines a standard way for accessing and manipulating documents.
The XML DOM
The XML DOM defines a standard way for accessing and manipulating XML documents.
The XML DOM views an XML document as a tree-structure.
All elements can be accessed through the DOM tree. Their content (text and attributes) can be modified or deleted, and new elements can be created. The elements, their text, and their attributes are all known as nodes.
4. XML Encoding
XML documents can contain non ASCII characters, like Norwegian æ ø å , or French ê è é. To avoid errors, specify the XML encoding, or save XML files as Unicode.
- Always use the encoding attribute
- Use an editor that supports encoding
- Make sure you know what encoding the editor uses
- Use the same encoding in your encoding attribute
No comments:
Post a Comment