After thirty years of developing binary file formats I'm (finally) writing out an XML document file format.
I've arrived at a part of my document header where I need to write around fifty separate boolean data members, and I was wondering: should I write these as 1/0 or true/false?
I understand the XML spec may go either way. On one hand, 1/0 SEEMS to be less work when reading the file format back in. But since since the file format is small, and cycles are cheap, is it considered proper XML to make the file format as symbolic as possible? If so, is it proper XML to do the same with ALL enum variables (output their symbolic names vs their values -- which could potentially change?)
And on a side note -- I'm generating XML in this form:
<FieldName>true</FieldName>
NOT this form:
<FieldName value="true"/>
After reading DOZENS of conflicting papers and postings (some on Stack Overflow), it SEEMS that the attribute style (example #2) has been mostly frowned upon.
Syntax of XML boolean xml version="1.0" encoding="utf-8"?> Following is a boolean declaration in schemas. The value of a boolean is an Integer value whose values are '0' and '1', representing logical yes or no. Capital Letters are avoided.
An element with no content is said to be empty. The two forms produce identical results in XML software (Readers, Parsers, Browsers). Empty elements can have attributes.
You're asking essentially what the cultural conventions are in the XML community. The cultural convention is to do your own thing. However, it's worth observing that XSLT and XQuery will serialize a value of type xs:boolean as "true" or "false".
As for elements vs. attributes, it's an old chestnut, and for simple data like this, both forms are perfectly acceptable. Just try to be consistent within a document or family of documents.
XML is so verbose anyway compared to binary formats that it probably doesn't really matter. But for ease of use and clarity, I would write it as true
and false
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With