| From: | Tomáš Pospíšil <killteck(at)seznam(dot)cz> |
|---|---|
| To: | pgsql-hackers(at)postgresql(dot)org |
| Cc: | chmelab(at)gmail(dot)com |
| Subject: | PROPOSAL of xmlvalidate |
| Date: | 2010-11-28 10:33:44 |
| Message-ID: | 21461.8645.15439-4124-347694227-1290940424@seznam.cz |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
I am working on patch adding xmlvalidate() functionality. LibXML 2.7.7 improved DTD, XSD, Relax-NG validation, so using that. I have idea of creating system table for holding DTDs, XSDs, Relax-NGs (similar as on ORACLE).
Is that good idea? If so, how to implement that table? pg_attribute and pg_class had changed guite from PostgresSQL 8.0.
Including code, work on progress.
bool
validate_xml_with_xsd(const char* xsd, const char* xml)
{
bool result = false;
xmlSchemaPtr schema = NULL; // pointer to schema
xmlLineNumbersDefault(1); // set line numbering in xml if any errors occurated
//// create xsd
xmlSchemaParserCtxtPtr ctxt;
ctxt = xmlSchemaNewMemParserCtxt((const char*)xsd, strlen(xsd));
xmlSchemaSetParserErrors(ctxt,
(xmlSchemaValidityErrorFunc) fprintf,
(xmlSchemaValidityWarningFunc) fprintf,
stderr);
schema = xmlSchemaParse(ctxt);
xmlSchemaFreeParserCtxt(ctxt);
if (schema == NULL)
{
elog(ERROR, "ERROR with DTD");
}
/// crate XML
xmlDocPtr doc;
doc = xmlReadDoc((char *)xml ,"http://www.w3.org/2001/XMLSchema",NULL,0);
if (doc == NULL)
{
elog(ERROR, "nepodarilo se nacist xml soubor ze vstupu");
} else
{
xmlSchemaValidCtxtPtr ctxt;
int ret;
ctxt = xmlSchemaNewValidCtxt(schema);
xmlSchemaSetValidErrors(ctxt,
(xmlSchemaValidityErrorFunc) fprintf,
(xmlSchemaValidityWarningFunc) fprintf,
stderr);
ret = xmlSchemaValidateDoc(ctxt, doc);
if (ret == 0)
{
result = true;
elog(WARNING, "validation SUCCED");
} else
if (ret > 0) {
result = false;
elog(WARNING, "not validated");
} else
{
result = false;
elog(WARNING, "validation failed with internal error");
}
xmlSchemaFreeValidCtxt(ctxt);
xmlFreeDoc(doc);
}
if (schema != NULL)
{ // free
xmlSchemaFree(schema);
}
return result;
}
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Robert Haas | 2010-11-28 13:06:41 | Re: ALTER OBJECT any_name SET SCHEMA name |
| Previous Message | Robert Haas | 2010-11-28 05:01:59 | Re: profiling connection overhead |