Pregunta

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.

¿Fue útil?

Solución

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.

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top