- From: Daniel Dui <daniel.dui@gmail.com>
- Date: Fri, 24 Aug 2012 10:48:09 +0100
- To: "xmlschema-dev@w3.org" <xmlschema-dev@w3.org>
- Message-ID: <CAACJ0wZXV3RJ4hZaBERbTq+bBe5H=qB-zt2PdabwAw26QsEypw@mail.gmail.com>
So what should an instance document look like to have the default value "Hello World"? Does this mean that the default value is of no practical use for an xsd:string type? -d On 24 August 2012 10:05, Costello, Roger L. <costello@mitre.org> wrote: > Thank you Michael and Pete for correcting my misunderstanding. > > Allow me to correct the answer to my quiz: > > I wrote this as the answer to my quiz: > > > Answer: the value of Title is the empty string, not the default > value. > > The reason is that the empty string is a valid value of the string > data type. > > However, the correct answer is: > > Answer: the value of Title is the default value ("Hello World"). The XML > Schema specification explains why: > > An element with a non-empty default value whose > simple type definition includes the empty string in > its lexical space will nonetheless never receive that > empty string value, because the default value will > override it. > > /Roger > > > -----Original Message----- > From: Costello, Roger L. > Sent: Thursday, August 23, 2012 5:47 PM > To: xmlschema-dev@w3.org > Subject: XML Schema quiz on default values > > Hello Folks, > > Recall that when you declare an element (or attribute) you can give it a > default value. > > For example, I give the Altitude element a default value of 100: > > <xs:element name="Altitude" type="xs:integer" default="100" /> > > In an instance document, if you wish for Altitude to have the default > value, then you can simply create it as an empty element: > > <Altitude></Altitude> > > The value of Altitude is 100. > > Let's take another example. Here I declare the Title element to be of type > string and give it a default value, "Hello World": > > <xs:element name="Title" type="xs:string" default="Hello World" /> > > Now in my instance document I create an empty Title element: > > <Title></Title> > > Quiz: What is the value of Title? > > Scroll down to see the answer ... > > > > > > > > > > > > > > > > > > > > > > > > > > Answer: the value of Title is the empty string, not the default value. The > reason is that the empty string is a valid value of the string data type. > If you want Title to have the default value then you must explicitly enter > the default value: > > <Title>Hello World</Title> > > /Roger > > -- ____________________________________________________________ Daniel Dui - daniel.dui@gmail.com - skype: danieldui
Received on Friday, 24 August 2012 09:49:26 UTC