htmlc++pugixml

How to add attribute without a value with pugixml?


How can pugixml generate an attribute without a value?

Consider the following desired html:

<option value="book" selected>book</option>

The question is about the selected attribute, how to add this through pugixml.

Here is the code I currently use to generate that attribute:

option_node.append_attribute("selected");

This code adds an empty value to the attribute, as follows:

<option value="book" selected="">book</option>


Solution

  • This is a correct representation. The Section 13.1.2.3 of the HTML5 standard states:

    Empty attribute syntax

    Just the attribute name. The value is implicitly the empty string.
    Example: <input disabled>

    If you really want the empty syntax in the output, consider writing a PR for PugiXML.