- From: Andy Davidson <andy_davidson@apple.com>
- Date: Thu, 15 Dec 2011 15:44:50 -0800
- To: Piotr Sipika <piotreks@optonline.net>
- Cc: xml@gnome.org, xmlschema-dev@w3.org
- Message-id: <9FF0C514-E678-4B25-A27B-7D2892DE23E2@apple.com>
Hi Piortr
I still can not validate xml that uses xml schema extensions. I think I figured out what the problem might be, but do not know how to resolve i. I wonder if the problem is with the way I set up my xml namespace?
<zoo:cageRequest xmlns:zoo="http://www.example.org/Zoo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
I am setting up the xml schema namespace the same way eclipse does when you create a new XSD or XML file. I entered http://www.w3.org/2001/XMLSchema-instance in the address bar of my browsers and got quite a surprise!
<xs:annotation>
<xs:documentation><p>This schema should never be used as such:
<a href="http://www.w3.org/TR/xmlschema-1/#no-xsi">the XML
Schema Recommendation</a> forbids the declaration of
attributes in this namespace</p>
</xs:documentation>
</xs:annotation>
http://www.w3.org/TR/xmlschema-1/#no-xsi is very confusing.
where does libxml get the schema lang schema/dtd? As a test I put some typos in my xsd file. libxml generated an error when I tried to validate the xsd file as expected?
what URL should I be using?
Do I need to make a special call to cause the libxml to use this other location?
My app will be running on a private network and not have access to www.w3.org, Do I need to copy a dtd or something to my local env?
thanks in advance
Andy
p.s. Bellow is a long email I was going to send before I got the surprise I mentioned above. There is a nice code example of how how to validate. Its much simpler than the other examples I have seen posted in the past
On Dec 13, 2011, at 7:19 AM, Piotr Sipika wrote:
>
> I wrote a sample program (in C) to attempt to mimic what you have, and
> was able to successfully validate the instance against the schema you
> provided.
>
Would you be willing to send my your sample C program?
I must be missing a function call somewhere? My XML/XSD files that do not use extensions validate so I think my basic code structure is correct. In your original post you mentioned "xmllint". I did not know about that tool. All of my files validate according to xmllint.I stepped through xmllint to see how it worked. Its very complicated. I must have missed something. Looking at the xmllint source I was able to simplify my code and get rid some some memory leaks.
Here is my simplified code listing based on the xmllint source
const char *schemaFileNameStr = ...;
// http://xmlsoft.org/html/libxml-xmlschemas.html#xmlSchemaNewParserCtxt
xmlSchemaParserCtxtPtr ctxt = xmlSchemaNewParserCtxt(schemaFileNameStr);
//http://xmlsoft.org/html/libxml-xmlschemas.html#xmlSchemaSetParserErrors
xmlSchemaSetParserErrors(ctxt,
(xmlSchemaValidityErrorFunc) fprintf,
(xmlSchemaValidityWarningFunc) fprintf,
stderr);
xmlSchemaPtr wxschemas = xmlSchemaParse(ctxt);
if (wxschemas == NULL) {
NSLog(@"******* ERROR schema %@ failed to compile\n", xmlSchemaFilePath);
return ret;
}
xmlSchemaFreeParserCtxt(ctx);
for (all the xml files) {
// http://www.xmlsoft.org/html/libxml-xmlschemas.html#xmlSchemaNewValidCtxt
xmlSchemaValidCtxtPtr vctxt = xmlSchemaNewValidCtxt(wxschemas);
// http://xmlsoft.org/html/libxml-xmlschemas.html#xmlSchemaSetValidErrors
xmlSchemaSetValidErrors(vctxt,
(xmlSchemaValidityErrorFunc) fprintf,
(xmlSchemaValidityWarningFunc) fprintf,
stderr);
// http://xmlsoft.org/html/libxml-xmlschemas.html#xmlSchemaValidateDoc
int error = xmlSchemaValidateDoc(vctxt, doc);
if (error == 0) {
ret = YES;
} else if (error > 0) {
ret = NO;
fprintf(stderr, "%s fails to validate\n", filename);
} else {
ret = NO; // validation generated an internal error
}
xmlSchemaFreeValidCtxt(vctxt);
}
<?xml version="1.0" encoding="UTF-8"?>
<zoo:cageRequest xmlns:zoo="http://www.example.org/Zoo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<animal xsi:type="zoo:Fish">
<name>Blue Fin Tuna</name>
<numberOfFins>4</numberOfFins>
</animal>
</zoo:cageRequest>
element animal: Schemas validity error : Element 'animal', attribute 'xsi:type': The attribute 'xsi:type' is not allowed.
element numberOfFins: Schemas validity error : Element 'numberOfFins': This element is not expected.
DOCUMENT
version=1.0
standalone=true
ELEMENT zoo:cageRequest
namespace zoo href=http://www.example.org/Zoo
namespace xsi href=http://www.w3.org/2001/XMLSchema-instanc...
ELEMENT animal
ATTRIBUTE xsi:type
TEXT
content=zoo:Fish
ELEMENT name
TEXT
content=Blue Fin Tuna
ELEMENT numberOfFins
TEXT
content=4
Attachments
- text/html attachment: stored
- application/octet-stream attachment: ZooRequest.xsd
- text/html attachment: stored
Received on Thursday, 15 December 2011 23:46:06 UTC