Custom Comments in XML

Imagine you’re using an XML parser to read in files, editing them, and then using an XML formatter to write the files, and that the XML style <!– comments –> are not preserved. If the editing process preserves all elements and attributes, however, even those that are not expected, then that might be exploited to provide custom comments.

Thus, rather than writing this:

<element field="value">
  <!-- comment text -->

you could write this:

<element field="value">
  <comment>comment text</comment>

or this:

<element comment="comment text" field="value"/>

Furthermore, note that if the order of sibling elements is not preserved (perhaps the elements are being deliberately sorted), then the comment will have to be a child (not a sibling) of the associated element.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: