- To add a child element to the head section, click on the head element and choose Child Element from the Insert menu. Name the new child element title.
- To add another child element, click on title and choose Element from the Insert menu. Name this element base.
- In HTML, the base element has an attribute named target. The target attribute defines the default page to which a link will go when no link is specified in an a element. To add an attribute to this element, click on base and choose Attribute from the Insert menu. Name the attribute target.
-
The completed head element is shown in Figure 3-4.
Figure 3-4. The completed head element in XML Notepad.
- Choose Source from the View menu to display the source code, shown in Figure 3-5.
-
Figure 3-5. Source code for the completed head element.
As you can see, this source code looks a lot like HTML. This document meets the requirements for a well-formed XML document, but it can also be used as an HTML document with a little work. Three of the elements are empty elements: <title/>, <base target=""/>, and <body/>. XML uses the singleton format to denote an empty element, which is not recognized by HTML. To modify these elements so that HTML Web browsers can read them, they should be written as follows:
<title></title> <base target=""></base> <body></body>
We could leave the title and body elements as singletons since a Web browser reading this as an HTML document will simply ignore them. However, we don't want a Web browser to ignore the empty base element because it has the target attribute associated with it. The base element is supposed to be empty because it exists only as a container for its target attribute. We should change the base element to <base target=""></base>, but this cannot be done in XML Notepad. If you edit the document in a regular text editor and change this element, XML Notepad will change it back to the singleton when it reads the file.
We can prevent XML Notepad from converting the element back to a singleton by adding a comment to the element. To do so, click on base and choose Comment from the Insert menu, and then add the following comment value in the right pane of XML Notepad:
Default link for page
The source code will now look as follows:
<base target=""><!--Default link for page--></base>
This added comment solves the empty element problem without having to resort to any ugly hacks.
These problems are caused by the fact that HTML doesn't understand singletons. You will encounter these difficulties when you XMLize currently existing HTML document structures.