PROPOSAL of xmlvalidate

Поиск
Список
Период
Сортировка
От Tomáš Pospíšil
Тема PROPOSAL of xmlvalidate
Дата
Msg-id 21461.8645.15439-4124-347694227-1290940424@seznam.cz
обсуждение исходный текст
Ответы Re: PROPOSAL of xmlvalidate  (Andrew Dunstan <andrew@dunslane.net>)
Re: PROPOSAL of xmlvalidate  (Robert Haas <robertmhaas@gmail.com>)
Список 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;
}








В списке pgsql-hackers по дате отправления:

Предыдущее
От: Robert Haas
Дата:
Сообщение: Re: profiling connection overhead
Следующее
От: Robert Haas
Дата:
Сообщение: Re: ALTER OBJECT any_name SET SCHEMA name