XML Comments and Processing Instructions

Estimated study time: 9 minutes.

Beyond data, XML documents can carry two kinds of non-data content: comments for human readers, and processing instructions for applications that consume the file.

XML Comments

Comments let you annotate a document without affecting how it's parsed as data.

<!-- This section lists enrolled students -->
<students>
  <student>Meera Iyer</student>
</students>

Comment Rules

  • Comments cannot appear before the XML declaration.
  • Comments cannot be nested inside other comments.
  • The character sequence -- cannot appear inside a comment's text.

Processing Instructions (PIs)

A processing instruction passes application-specific information to whatever software is reading the XML — commonly used to link a stylesheet.

<?xml-stylesheet type="text/xsl" href="course-style.xsl"?>
<course>
  <title>Data Analytics</title>
</course>

PIs vs Comments

  • Comments are ignored by parsers — they're purely for humans reading the source.
  • Processing instructions are passed through to the application, which decides how to act on them.
💡 Tip: Use comments generously to document why data is structured a certain way — future readers of the file (including you) will thank you.

Ready to go beyond the basics?

Get hands-on training, live mentorship, and placement support with the Data Analytics Course at Uncodemy.

Explore XML Course →