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 -->
</element>

you could write this:

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

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.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s


%d bloggers like this: