Daniel Veillard a écrit :
> [ posting again due to a mail error ]
> On Sat, Nov 28, 2009 at 08:53:53AM +0100, Philippe BOINOT wrote:
>   
>> Hi,
>>
>> I would like to get default attribute value defined by following xsd.
>> I'm using reader API and
>> set  XML_SCHEMA_VAL_VC_I_CREATE value but it doesn't work.
>>
>> What's wrong in my code ?
>>     
>
>   I don't think that works with the Reader. Just when validating a
> existing full document, then those will be added.
>
> Daniel
>
>   
Full document validation is ok for me. It's working now. I put the code
here for other users :

int xmlSchemaValidation(xmlDocPtr xmlDoc, const char *schemaFile) {
  xmlSchemaPtr           schema=NULL;
  xmlSchemaValidCtxtPtr  vctxt=NULL;
  xmlSchemaParserCtxtPtr pctxt=NULL;
  int                    result=ERROR_OCCURED;

  // create parser context
  if ((pctxt = xmlSchemaNewParserCtxt(schemaFile)) == NULL) goto
xmlSchemaValidation_end;
  if ((schema = xmlSchemaParse(pctxt))==NULL)               goto
xmlSchemaValidation_end;
  if ((vctxt = xmlSchemaNewValidCtxt(schema)) == NULL)      goto
xmlSchemaValidation_end;
 
 
xmlSchemaSetValidOptions(vctxt,XML_SCHEMA_VAL_VC_I_CREATE);             
// populate xml tree with default values
  result = (xmlSchemaValidateDoc(vctxt, xmlDoc) == 0 ? VALID :
NOT_VALID); // validate xml

 xmlSchemaValidation_end:
  if (pctxt!=NULL)  xmlSchemaFreeParserCtxt(pctxt);
  if (schema!=NULL) xmlSchemaFree(schema);
  if (vctxt!=NULL)  xmlSchemaFreeValidCtxt(vctxt);
 
  return result;
}

Thanks

Philippe
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
[email protected]
http://mail.gnome.org/mailman/listinfo/xml

Reply via email to