'Re: "[xml] How to get elements default values, defined in the schema"'


on 9/1/2004 9:12 AM Zhamak Dehghani wrote:

I've used xmlSchema functions i.e. "xmlSchemaValidateDoc(...)" to validate a xml document.
To read an element's content I have used "xmlNodeGetContent(...)" function.

The schema I use has defined default values for some of the elements i.e. 
"<xsd:element name="AcquirerName" type="xsd:string" default="WESTPAC" minOccurs="0"/>"

I expected after validating a document against the schema, default values get loaded into the document nodes
and xmlNodeGetContent to return default values if an element doesn't appear in the xml document or appear 
an empty content.
However my assumptions don't seem to be correct. xmlNodeGetContent never returns any values if element
appears with empty content i.e. "<AcquirerName></AcquirerName>"

You refer to the post-schema-validation infoset [1]: this is not 
implemented yet with the XML Schema processor of libxml2. I guess the 
PSVI and its API to create, will be one of the tail ends of the whole 
implementation story; although I admit that default and fixed values 
would be really a nice-to-have as early as possible.

and the element node itself doesn't 
even get created on the tree if the element is missing in the document.

Value constraints of element declarations [2] are handled differently to 
those of attribute declarations (i.e. the element, if missing, is not 
expected to appear in the PSVI):

"{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."

I appreciate if you could tell me how I can get the schema default values for the elements which are 
missing or
have empty content in the document?

As "http://www.xmlsoft.org"; states, the XML Schema processor is 
"work-in-progress". There is currently no functionality available to 
fulfill your needs - feel free to bugzilla it [3] to remind us of its need.

[1] http://www.w3.org/TR/2004/PER-xmlschema-1-20040318/#a-schema_default
[3] http://bugzilla.gnome.org/buglist.cgi?product=libxml2



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]