You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Roy Y Katz <ro...@fanniemae.com> on 2002/08/12 17:41:57 UTC

default= validation

Hello,

I have written before regarding XML revalidation; my question now is
whether Xerces can supply default attributes.  I ran across this
paragraph in the Schema definition (http://www.w3.org/TR/xmlschema-1/)

  {value constraint} establishes a default or fixed value for an
element. If default is specified, and if the element
  being ·validated· is empty, then the canonical form of the supplied
constraint value becomes the [schema
  normalized value] of the ·validated· element in the
post-schema-validation infoset. If fixed is specified, then
  the element's content must either be empty, in which case fixed
behaves as default, or its value must match the
  supplied constraint value.

    NOTE: The provision of defaults for elements goes beyond what is
possible in XML 1.0 DTDs,
    and does not exactly correspond to defaults for attributes. In
particular, an element with a
    non-empty {value constraint} whose simple type definition includes
the empty string in its lexical
    space will nonetheless never receive that value, because the {value
constraint} will override it. 

Supposing I had Xerces' validation turned on and loaded a DOM. 
Does this imply that Xerces should fill in the empty elements with their
defaults from the Schema?
If I have:

--- Schema ---

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"   attributeFormDefault="unqualified">
  <xs:element name="ROOT">
     <xs:complexType>
        <xs:sequence>
          <xs:element name="test" default="DEFAULT"/>
        </xs:sequence>
     </xs:complexType>
  </xs:element>
</xs:schema>

--- XML input ---

<?xml version="1.0" encoding="UTF-8"?>
<ROOT xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
xsi:noNameSpaceSchemaLocation="/home/test/example-schema.xsd">
   <test/>
</ROOT>

----

Then I expect that loading the above XML file would be the same as
loading

  .
  .
  .
  <test>DEFAULT</test>
  .
  .
  .

and that calling <test>.getNodeValue() would return "DEFAULT".
Are my assumptions correct?


Thanks!
Roey Katz


[disclaimer:  the opinions expressed above are my own and not of my
employer]


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org