Re: [xml] How to get default value attribute defined in xsd ? [libxml2-2.7.6]
- From: Philippe BOINOT <philippe boinot pertimm com>
- To: veillard redhat com
- Cc: xml gnome org
- Subject: Re: [xml] How to get default value attribute defined in xsd ? [libxml2-2.7.6]
- Date: Fri, 04 Dec 2009 11:29:17 +0100
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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]