tags:

views:

54

answers:

4

How can I represent, true/false as the Boolean and "true"/"false" the strings in XML?

Eg.

<problem>false</problem>
<problem>problem_name</problem>

Or is there a better way to do this?

+1  A: 

It is a common unwritten rule that says in xml as a boolean value we should use: 'true' and 'false'

You can look here for further information: http://www.w3.org/TR/xmlschema-2/#boolean

kogut
That rule looks written to me.
Robert Rossney
So I exaggerate with saying that this rule is unwritten...
kogut
+1  A: 

You want to distinguish between "real" booleans and the texts "true" and "false"?

Well - an attribute might help you - e.g. IsActive. For "text":

<problem>false</problem>

For booleans:

<problem IsActive="false"></problem>
winSharp93
A: 
Chris McCauley
The spec is at http://www.w3.org/TR/xmlschema-2/#boolean
Chris McCauley
One isn't required to use `xs:boolean` for boolean values, however. While there are certainly good reasons for this, there's precedent for doing it differently - e.g. XSLT uses `yes` and `no` consistently, and a corresponding enumeration can be defined in the schema.
Pavel Minaev
+1  A: 

If you use a schema to define an element's type as string, anything using that schema to interpret the element's content will correctly interpret false as being a string.

If you're not using a schema, and processes have to guess at a piece of content's type based on its representation, then you're going to have problems. You have to provide processes with some way of disambiguation, e.g. an attribute that indicates the content's data type, or (shudder) enclosing ambiguous literal values in quotation marks, i.e. "false" for the string and false for the boolean. Any approach you take here will be non-standard and non-portable.

Robert Rossney
Could you provide some example code?
steven
I wouldn't know where to start. Look at how data types are implemented in .NET's XML representation of the ADO.NET data set for a pretty fully-functional real-world example.
Robert Rossney