So far, this book has focused on elements and attributes. This chapter discusses the other kinds of nodes, namely comments, processing instructions, documents, and text nodes. CDATA sections and XML character and entity references are also covered in this chapter.
XML comments, delimited by
-->, can be both queried and constructed in XQuery. Some implementations will discard comments when parsing input documents or loading them into a database, so you should consult the documentation for your implementation to see what is supported.
Comments may appear at the beginning or end of an input document, or within element content. Example 22-1 shows a small XML document with two comments, on the second and fifth lines.
<?xml version="1.0" encoding="UTF-8"?>
<!-- This is a business document -->
<!-- date created -->
Comment nodes do not have any children, and their parent is either a document node or an element node. In this example, the comment on the second line is a child of the document node, and the comment on the fifth line is a child of the
Comment nodes do not have names, so calling any of the name-related functions with a comment node will result in the empty sequence or a zero-length string, depending ...