Detailed explanation of how to write code comments in XML

黄舟
Release: 2017-03-10 19:48:03
Original
2414 people have browsed it

This article mainly introduces the detailed method of writing code comments in XML. The article summarizes some points to pay attention to when using comments, such as XML does not support nested comments, etc. Friends who need it can refer to it

XML comments are similar to HTML comments. Comments are used to add explanation or understand a line of XML code.

Comments can be used to include relevant links, information and terms. They are only visible in the source code, not the XML code. Comments can appear anywhere in the XML code.

Grammar
Explanation starts with , for example .
Comments can appear in the preamble of a document, including a document type definition (DTD); after the document; or in the text content. Comments cannot appear in attribute values. Cannot appear in markup.
The parser considers the comment to have ended when it encounters >; then continues processing the document as normal XML. Therefore, the string > cannot appear in comments. Apart from this restriction, any legal XML character can appear in a comment, much like a CDATA section. This allows the XML comments to be removed from the output stream seen by the parser without deleting the content of the document.
The following comments can be used to temporarily remove markers.

Example
The following is a demonstration example of using comments in an XML document:

<?xml version="1.0" encoding="UTF-8" ?>
<!---Students grades are uploaded by months---->
<class_list>
    <student>
        <name>Tanmay</name>
        <grade>A</grade>
    </student>
</class_list>
Copy after login

Note# Text between

## characters is considered a comment. ## XML comment rules The following are the rules that XML comments need to follow:

- Comments cannot appear before an XML declaration.
- Comments can appear anywhere in the document.
- Comments cannot appear in attribute values.
- Comments cannot be nested within other comments.

In HTML, you can use comments to hide scripts and stylesheets. To use this method with XML, you might have to retrieve the comment, extract its contents, check for markup characters, and then reparse. In this case, the CDATA section is a better choice.

The above is the detailed content of Detailed explanation of how to write code comments in XML. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!