1

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>

0

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you that helps. I'll accept your answer because 1) It implicitly answers the question with "No, PugiXML cannot do this currently", and 2) It shows that the form of selected="" is still valid in HTML5.
Pugixml cannot do it because the result is not valid XML. XML and HTML5 may look alike but they play by different rules.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.