Обсуждение: PROPOSAL of xmlvalidate
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; }
On 11/28/2010 05:33 AM, Tomáš Pospíšil wrote: > Hi, > > I am working on patch adding xmlvalidate() functionality. LibXML 2.7.7 improved DTD, XSD, Relax-NG validation, so usingthat. 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. > > In the first place you need to tell us why you think it should go in a catalog table at all. Unless you intend to use some sort of typmod with the xml type, to indicate the validation object, it seems quite unnecessary. cheers andrew
On Sun, Nov 28, 2010 at 5:33 AM, Tomáš Pospíšil <killteck@seznam.cz> wrote: > I have idea of creating system table for holding DTDs, XSDs, Relax-NGs (similar as on ORACLE). > > Is that good idea? I doubt it. Why would we want to do that? -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
2010/11/29 Robert Haas <robertmhaas@gmail.com>: > On Sun, Nov 28, 2010 at 5:33 AM, Tomáš Pospíšil <killteck@seznam.cz> wrote: >> I have idea of creating system table for holding DTDs, XSDs, Relax-NGs (similar as on ORACLE). >> >> Is that good idea? > > I doubt it. Why would we want to do that? If I understand, it allows a local copy of DTD, .. so then is possible to provide a fast DTD checking. Regards Pavel Stehule > > -- > Robert Haas > EnterpriseDB: http://www.enterprisedb.com > The Enterprise PostgreSQL Company > > -- > Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-hackers >
On Mon, Nov 29, 2010 at 12:18 PM, Pavel Stehule <pavel.stehule@gmail.com> wrote: > 2010/11/29 Robert Haas <robertmhaas@gmail.com>: >> On Sun, Nov 28, 2010 at 5:33 AM, Tomáš Pospíšil <killteck@seznam.cz> wrote: >>> I have idea of creating system table for holding DTDs, XSDs, Relax-NGs (similar as on ORACLE). >>> >>> Is that good idea? >> >> I doubt it. Why would we want to do that? > > If I understand, it allows a local copy of DTD, .. so then is possible > to provide a fast DTD checking. But that could equally well be stored in a user table rather than a system table. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
2010/11/29 Robert Haas <robertmhaas@gmail.com>: > On Mon, Nov 29, 2010 at 12:18 PM, Pavel Stehule <pavel.stehule@gmail.com> wrote: >> 2010/11/29 Robert Haas <robertmhaas@gmail.com>: >>> On Sun, Nov 28, 2010 at 5:33 AM, Tomáš Pospíšil <killteck@seznam.cz> wrote: >>>> I have idea of creating system table for holding DTDs, XSDs, Relax-NGs (similar as on ORACLE). >>>> >>>> Is that good idea? >>> >>> I doubt it. Why would we want to do that? >> >> If I understand, it allows a local copy of DTD, .. so then is possible >> to provide a fast DTD checking. > > But that could equally well be stored in a user table rather than a > system table. > yes or now. If we have a some integrated rule for xml validation, but I can't to imagine a dependency on custom table. More - system table can be better cached. So it depends on level of integration to system. Probably it needs a deep discuss about SQL/XML and other questions. It can mean a not optional dependency on libxml2. Pavel > -- > Robert Haas > EnterpriseDB: http://www.enterprisedb.com > The Enterprise PostgreSQL Company >
On 11/29/2010 12:36 PM, Robert Haas wrote: > On Mon, Nov 29, 2010 at 12:18 PM, Pavel Stehule<pavel.stehule@gmail.com> wrote: >> 2010/11/29 Robert Haas<robertmhaas@gmail.com>: >>> On Sun, Nov 28, 2010 at 5:33 AM, Tomáš Pospíšil<killteck@seznam.cz> wrote: >>>> I have idea of creating system table for holding DTDs, XSDs, Relax-NGs (similar as on ORACLE). >>>> >>>> Is that good idea? >>> I doubt it. Why would we want to do that? >> If I understand, it allows a local copy of DTD, .. so then is possible >> to provide a fast DTD checking. > But that could equally well be stored in a user table rather than a > system table. > Yeah. The trouble is you won't be able to use that reliably in a check constraint, which I imagine is one of the principal intended purposes. I'm not sure how we should go about that. cheers andrew
On Mon, Nov 29, 2010 at 12:56 PM, Andrew Dunstan <andrew@dunslane.net> wrote: > On 11/29/2010 12:36 PM, Robert Haas wrote: >> On Mon, Nov 29, 2010 at 12:18 PM, Pavel Stehule<pavel.stehule@gmail.com> >> wrote: >>> 2010/11/29 Robert Haas<robertmhaas@gmail.com>: >>>> On Sun, Nov 28, 2010 at 5:33 AM, Tomáš Pospíšil<killteck@seznam.cz> >>>> wrote: >>>>> I have idea of creating system table for holding DTDs, XSDs, Relax-NGs >>>>> (similar as on ORACLE). >>>>> >>>>> Is that good idea? >>>> >>>> I doubt it. Why would we want to do that? >>> >>> If I understand, it allows a local copy of DTD, .. so then is possible >>> to provide a fast DTD checking. >> >> But that could equally well be stored in a user table rather than a >> system table. > > Yeah. The trouble is you won't be able to use that reliably in a check > constraint, which I imagine is one of the principal intended purposes. I'm > not sure how we should go about that. There is a whole category of things where you might want to write a check constraint that involves accessing data in some other table, and therefore it falls down because this makes the constraint non-immutable. But not infrequently one knows that, while in theory the other table could change, in practice it will not, or only in ways that won't cause the CHECK constraint to be violated. We need to think about a sensible way of handling this class of problems. Putting the data into a system table doesn't really accomplish anything; system tables aren't read-only either. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
Andrew Dunstan <andrew@dunslane.net> writes: > On 11/29/2010 12:36 PM, Robert Haas wrote: >> But that could equally well be stored in a user table rather than a >> system table. > Yeah. The trouble is you won't be able to use that reliably in a check > constraint, which I imagine is one of the principal intended purposes. Moving the same data to a system table doesn't fix that, unless you require that the system table be immutable ... which'd seem to make the idea useless. regards, tom lane
On 11/29/2010 01:30 PM, Tom Lane wrote: > Andrew Dunstan<andrew@dunslane.net> writes: >> On 11/29/2010 12:36 PM, Robert Haas wrote: >>> But that could equally well be stored in a user table rather than a >>> system table. >> Yeah. The trouble is you won't be able to use that reliably in a check >> constraint, which I imagine is one of the principal intended purposes. > Moving the same data to a system table doesn't fix that, unless you > require that the system table be immutable ... which'd seem to make > the idea useless. > > Oh, yes, I agree. cheers andrew