00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00027 #include <stdio.h>
00028
00029 #include <glib.h>
00030
00031 #include "erreglog.h"
00032 #include "erreg.h"
00033 #include "erregxsd.h"
00034 #include "erregxml.h"
00035 #include "erregtypes_f.h"
00036
00037 gboolean xsdLoad(regSchema_t * pXsdCxt, const char *szXsdFile)
00038 {
00039 ERREG_XSD_LOGPRINTF("entry %p %s", pXsdCxt, szXsdFile);
00040
00041 if (NULL == pXsdCxt || NULL == szXsdFile)
00042 {
00043 ERREG_XSD_ERRORPRINTF("invalid arguments");
00044 return FALSE;
00045 }
00046
00047 pXsdCxt->pDoc = xmlParseFile(szXsdFile);
00048 if (pXsdCxt->pDoc)
00049 {
00050 pXsdCxt->pParser = xmlSchemaNewDocParserCtxt(pXsdCxt->pDoc);
00051 if (pXsdCxt->pParser)
00052 {
00053 pXsdCxt->pCxt = xmlSchemaParse(pXsdCxt->pParser);
00054 if (pXsdCxt->pCxt)
00055 {
00056 pXsdCxt->pValid = xmlSchemaNewValidCtxt(pXsdCxt->pCxt);
00057 if (pXsdCxt->pValid)
00058 {
00059 pXsdCxt->szFileName = g_strdup(szXsdFile);
00060 return TRUE;
00061 }
00062 }
00063 }
00064 }
00065
00066 xsdUnload(pXsdCxt);
00067 return FALSE;
00068 }
00069
00070 void xsdUnload(regSchema_t * pXsdCxt)
00071 {
00072 ERREG_XSD_LOGPRINTF("entry %p", pXsdCxt);
00073
00074 if (pXsdCxt)
00075 {
00076 if (pXsdCxt->pDoc)
00077 {
00078 xmlFreeDoc(pXsdCxt->pDoc);
00079 pXsdCxt->pDoc = NULL;
00080 }
00081
00082 if (pXsdCxt->pParser)
00083 {
00084 xmlSchemaFreeParserCtxt(pXsdCxt->pParser);
00085 pXsdCxt->pParser = NULL;
00086 }
00087
00088 if (pXsdCxt->pCxt)
00089 {
00090 xmlSchemaFree(pXsdCxt->pCxt);
00091 pXsdCxt->pCxt = NULL;
00092 }
00093
00094 if (pXsdCxt->pValid)
00095 {
00096 xmlSchemaFreeValidCtxt(pXsdCxt->pValid);
00097 pXsdCxt->pValid = NULL;
00098 }
00099
00100 if (pXsdCxt->szFileName)
00101 {
00102 g_free(pXsdCxt->szFileName);
00103 pXsdCxt->szFileName = NULL;
00104 }
00105 }
00106 }
00107
00108 gboolean xsdValidateXmlDoc(regSchema_t * pXsdCxt, xmlDocPtr pDoc)
00109 {
00110 gboolean bRet = FALSE;
00111
00112 ERREG_XSD_LOGPRINTF("entry %p %p", pXsdCxt, pDoc);
00113
00114 if (pXsdCxt && pXsdCxt->pValid && pDoc)
00115 {
00116 int nRet = xmlSchemaValidateDoc(pXsdCxt->pValid, pDoc);
00117 if (0 == nRet)
00118 {
00119 bRet = TRUE;
00120 }
00121 }
00122 ERREG_XSD_LOGPRINTF("Returns [%d]", bRet);
00123 return bRet;
00124 }