XML: Add the possibility to validate a document in using DTD, Relax NG or Schema 23/4823/5
Calixte DENIZET [Thu, 1 Sep 2011 15:16:51 +0000 (17:16 +0200)]
Change-Id: Idf29d4b390dd28cad3cbaa327121b3ddf4a51896

46 files changed:
scilab/modules/helptools/data/configuration/scilab_primitives.txt
scilab/modules/xml/Makefile.am
scilab/modules/xml/Makefile.in
scilab/modules/xml/help/en_US/XMLObjects.xml
scilab/modules/xml/help/en_US/xmlClose.xml
scilab/modules/xml/help/en_US/xmlDTD.xml [new file with mode: 0644]
scilab/modules/xml/help/en_US/xmlGetOpenStreams.xml
scilab/modules/xml/help/en_US/xmlRead.xml
scilab/modules/xml/help/en_US/xmlReadStr.xml
scilab/modules/xml/help/en_US/xmlRelaxNG.xml [new file with mode: 0644]
scilab/modules/xml/help/en_US/xmlSchema.xml [new file with mode: 0644]
scilab/modules/xml/help/en_US/xmlValidate.xml [new file with mode: 0644]
scilab/modules/xml/includes/gw_xml.h
scilab/modules/xml/includes/xml.h
scilab/modules/xml/includes/xml_mlist.h
scilab/modules/xml/sci_gateway/c/gw_xml.c
scilab/modules/xml/sci_gateway/cpp/sci_print.cpp
scilab/modules/xml/sci_gateway/cpp/sci_xmlClose.cpp
scilab/modules/xml/sci_gateway/cpp/sci_xmlGetOpenStreams.cpp
scilab/modules/xml/sci_gateway/cpp/sci_xmlRead.cpp
scilab/modules/xml/sci_gateway/cpp/sci_xmlReadStr.cpp
scilab/modules/xml/sci_gateway/cpp/sci_xmlValidate.cpp [new file with mode: 0644]
scilab/modules/xml/sci_gateway/cpp/sci_xmlValidationFile.cpp [new file with mode: 0644]
scilab/modules/xml/sci_gateway/cpp/sci_xmlXPath.cpp
scilab/modules/xml/sci_gateway/xml_gateway.xml
scilab/modules/xml/src/c/XMLMlistsManagement.c
scilab/modules/xml/src/cpp/XMLDocument.cpp
scilab/modules/xml/src/cpp/XMLDocument.hxx
scilab/modules/xml/src/cpp/XMLElement.cpp
scilab/modules/xml/src/cpp/XMLNodeList.cpp
scilab/modules/xml/src/cpp/XMLValidation.cpp [new file with mode: 0644]
scilab/modules/xml/src/cpp/XMLValidation.hxx [new file with mode: 0644]
scilab/modules/xml/src/cpp/XMLValidationDTD.cpp [new file with mode: 0644]
scilab/modules/xml/src/cpp/XMLValidationDTD.hxx [new file with mode: 0644]
scilab/modules/xml/src/cpp/XMLValidationRelaxNG.cpp [new file with mode: 0644]
scilab/modules/xml/src/cpp/XMLValidationRelaxNG.hxx [new file with mode: 0644]
scilab/modules/xml/src/cpp/XMLValidationSchema.cpp [new file with mode: 0644]
scilab/modules/xml/src/cpp/XMLValidationSchema.hxx [new file with mode: 0644]
scilab/modules/xml/src/cpp/insertion.hpp
scilab/modules/xml/tests/unit_tests/invalid_library.xml [new file with mode: 0644]
scilab/modules/xml/tests/unit_tests/library.dtd [new file with mode: 0644]
scilab/modules/xml/tests/unit_tests/library.rng [new file with mode: 0644]
scilab/modules/xml/tests/unit_tests/library.xml [new file with mode: 0644]
scilab/modules/xml/tests/unit_tests/library.xsd [new file with mode: 0644]
scilab/modules/xml/tests/unit_tests/xmlValidate.dia.ref [new file with mode: 0644]
scilab/modules/xml/tests/unit_tests/xmlValidate.tst [new file with mode: 0644]

index c1924fb..be655e2 100644 (file)
@@ -30,6 +30,7 @@
 %XMLSet_length
 %XMLSet_p
 %XMLSet_size
+%XMLValid_p
 %b_i_XMLList
 %c_i_XMLAttr
 %c_i_XMLDoc
@@ -667,6 +668,7 @@ xls_open
 xls_read
 xmlAddNs
 xmlClose
+xmlDTD
 xmlDocument
 xmlDump
 xmlElement
@@ -677,6 +679,9 @@ xmlGetOpenStreams
 xmlNs
 xmlRead
 xmlReadStr
+xmlRelaxNG
+xmlSchema
+xmlValidate
 xmlWrite
 xmlXPath
 xname
index e9c032d..1028c67 100644 (file)
@@ -40,7 +40,11 @@ XML_CPP_SOURCES = src/cpp/VariableScope.cpp \
                   src/cpp/XMLNodeSet.cpp \
                   src/cpp/XMLXPath.cpp \
                   src/cpp/XMLList.cpp \
-                  src/cpp/XMLNotHandledElement.cpp
+                  src/cpp/XMLNotHandledElement.cpp \
+                  src/cpp/XMLValidation.cpp \
+                 src/cpp/XMLValidationDTD.cpp \
+                 src/cpp/XMLValidationSchema.cpp \
+                 src/cpp/XMLValidationRelaxNG.cpp
 
 GATEWAY_C_SOURCES = sci_gateway/c/gw_xml.c
 
@@ -69,7 +73,9 @@ GATEWAY_CPP_SOURCES = sci_gateway/cpp/sci_xmlRead.cpp \
                      sci_gateway/cpp/sci_xmlGetNsByHref.cpp \
                      sci_gateway/cpp/sci_xmlGetNsByPrefix.cpp \
                      sci_gateway/cpp/sci_xmlWrite.cpp \
-                     sci_gateway/cpp/sci_percent_foo_i_XMLList.cpp
+                     sci_gateway/cpp/sci_percent_foo_i_XMLList.cpp \
+                     sci_gateway/cpp/sci_xmlValidationFile.cpp \
+                     sci_gateway/cpp/sci_xmlValidate.cpp
 
 libscixml_la_CFLAGS= -I$(srcdir)/includes/ \
                     -I$(top_srcdir)/libs/MALLOC/includes/ \
index a5d2907..f400624 100644 (file)
@@ -125,7 +125,11 @@ am__objects_3 = libscixml_algo_la-VariableScope.lo \
        libscixml_algo_la-XMLNs.lo libscixml_algo_la-XMLNodeList.lo \
        libscixml_algo_la-XMLNodeSet.lo libscixml_algo_la-XMLXPath.lo \
        libscixml_algo_la-XMLList.lo \
-       libscixml_algo_la-XMLNotHandledElement.lo
+       libscixml_algo_la-XMLNotHandledElement.lo \
+       libscixml_algo_la-XMLValidation.lo \
+       libscixml_algo_la-XMLValidationDTD.lo \
+       libscixml_algo_la-XMLValidationSchema.lo \
+       libscixml_algo_la-XMLValidationRelaxNG.lo
 am_libscixml_algo_la_OBJECTS = $(am__objects_1) $(am__objects_2) \
        $(am__objects_3)
 libscixml_algo_la_OBJECTS = $(am_libscixml_algo_la_OBJECTS)
@@ -161,7 +165,9 @@ am__objects_5 = libscixml_la-sci_xmlRead.lo \
        libscixml_la-sci_xmlGetNsByHref.lo \
        libscixml_la-sci_xmlGetNsByPrefix.lo \
        libscixml_la-sci_xmlWrite.lo \
-       libscixml_la-sci_percent_foo_i_XMLList.lo
+       libscixml_la-sci_percent_foo_i_XMLList.lo \
+       libscixml_la-sci_xmlValidationFile.lo \
+       libscixml_la-sci_xmlValidate.lo
 am_libscixml_la_OBJECTS = $(am__objects_4) $(am__objects_5)
 libscixml_la_OBJECTS = $(am_libscixml_la_OBJECTS)
 libscixml_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \
@@ -535,7 +541,11 @@ XML_CPP_SOURCES = src/cpp/VariableScope.cpp \
                   src/cpp/XMLNodeSet.cpp \
                   src/cpp/XMLXPath.cpp \
                   src/cpp/XMLList.cpp \
-                  src/cpp/XMLNotHandledElement.cpp
+                  src/cpp/XMLNotHandledElement.cpp \
+                  src/cpp/XMLValidation.cpp \
+                 src/cpp/XMLValidationDTD.cpp \
+                 src/cpp/XMLValidationSchema.cpp \
+                 src/cpp/XMLValidationRelaxNG.cpp
 
 GATEWAY_C_SOURCES = sci_gateway/c/gw_xml.c
 GATEWAY_CPP_SOURCES = sci_gateway/cpp/sci_xmlRead.cpp \
@@ -563,7 +573,9 @@ GATEWAY_CPP_SOURCES = sci_gateway/cpp/sci_xmlRead.cpp \
                      sci_gateway/cpp/sci_xmlGetNsByHref.cpp \
                      sci_gateway/cpp/sci_xmlGetNsByPrefix.cpp \
                      sci_gateway/cpp/sci_xmlWrite.cpp \
-                     sci_gateway/cpp/sci_percent_foo_i_XMLList.cpp
+                     sci_gateway/cpp/sci_percent_foo_i_XMLList.cpp \
+                     sci_gateway/cpp/sci_xmlValidationFile.cpp \
+                     sci_gateway/cpp/sci_xmlValidate.cpp
 
 libscixml_la_CFLAGS = -I$(srcdir)/includes/ \
                     -I$(top_srcdir)/libs/MALLOC/includes/ \
@@ -703,6 +715,10 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_algo_la-XMLNotHandledElement.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_algo_la-XMLNs.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_algo_la-XMLObject.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_algo_la-XMLValidation.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_algo_la-XMLValidationDTD.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_algo_la-XMLValidationRelaxNG.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_algo_la-XMLValidationSchema.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_algo_la-XMLXPath.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-gw_xml.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_extraction.Plo@am__quote@
@@ -729,6 +745,8 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_xmlNs.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_xmlRead.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_xmlReadStr.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_xmlValidate.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_xmlValidationFile.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_xmlWrite.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_xmlXPath.Plo@am__quote@
 
@@ -865,6 +883,34 @@ libscixml_algo_la-XMLNotHandledElement.lo: src/cpp/XMLNotHandledElement.cpp
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixml_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscixml_algo_la-XMLNotHandledElement.lo `test -f 'src/cpp/XMLNotHandledElement.cpp' || echo '$(srcdir)/'`src/cpp/XMLNotHandledElement.cpp
 
+libscixml_algo_la-XMLValidation.lo: src/cpp/XMLValidation.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixml_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libscixml_algo_la-XMLValidation.lo -MD -MP -MF $(DEPDIR)/libscixml_algo_la-XMLValidation.Tpo -c -o libscixml_algo_la-XMLValidation.lo `test -f 'src/cpp/XMLValidation.cpp' || echo '$(srcdir)/'`src/cpp/XMLValidation.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscixml_algo_la-XMLValidation.Tpo $(DEPDIR)/libscixml_algo_la-XMLValidation.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='src/cpp/XMLValidation.cpp' object='libscixml_algo_la-XMLValidation.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixml_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscixml_algo_la-XMLValidation.lo `test -f 'src/cpp/XMLValidation.cpp' || echo '$(srcdir)/'`src/cpp/XMLValidation.cpp
+
+libscixml_algo_la-XMLValidationDTD.lo: src/cpp/XMLValidationDTD.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixml_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libscixml_algo_la-XMLValidationDTD.lo -MD -MP -MF $(DEPDIR)/libscixml_algo_la-XMLValidationDTD.Tpo -c -o libscixml_algo_la-XMLValidationDTD.lo `test -f 'src/cpp/XMLValidationDTD.cpp' || echo '$(srcdir)/'`src/cpp/XMLValidationDTD.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscixml_algo_la-XMLValidationDTD.Tpo $(DEPDIR)/libscixml_algo_la-XMLValidationDTD.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='src/cpp/XMLValidationDTD.cpp' object='libscixml_algo_la-XMLValidationDTD.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixml_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscixml_algo_la-XMLValidationDTD.lo `test -f 'src/cpp/XMLValidationDTD.cpp' || echo '$(srcdir)/'`src/cpp/XMLValidationDTD.cpp
+
+libscixml_algo_la-XMLValidationSchema.lo: src/cpp/XMLValidationSchema.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixml_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libscixml_algo_la-XMLValidationSchema.lo -MD -MP -MF $(DEPDIR)/libscixml_algo_la-XMLValidationSchema.Tpo -c -o libscixml_algo_la-XMLValidationSchema.lo `test -f 'src/cpp/XMLValidationSchema.cpp' || echo '$(srcdir)/'`src/cpp/XMLValidationSchema.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscixml_algo_la-XMLValidationSchema.Tpo $(DEPDIR)/libscixml_algo_la-XMLValidationSchema.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='src/cpp/XMLValidationSchema.cpp' object='libscixml_algo_la-XMLValidationSchema.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixml_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscixml_algo_la-XMLValidationSchema.lo `test -f 'src/cpp/XMLValidationSchema.cpp' || echo '$(srcdir)/'`src/cpp/XMLValidationSchema.cpp
+
+libscixml_algo_la-XMLValidationRelaxNG.lo: src/cpp/XMLValidationRelaxNG.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixml_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libscixml_algo_la-XMLValidationRelaxNG.lo -MD -MP -MF $(DEPDIR)/libscixml_algo_la-XMLValidationRelaxNG.Tpo -c -o libscixml_algo_la-XMLValidationRelaxNG.lo `test -f 'src/cpp/XMLValidationRelaxNG.cpp' || echo '$(srcdir)/'`src/cpp/XMLValidationRelaxNG.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscixml_algo_la-XMLValidationRelaxNG.Tpo $(DEPDIR)/libscixml_algo_la-XMLValidationRelaxNG.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='src/cpp/XMLValidationRelaxNG.cpp' object='libscixml_algo_la-XMLValidationRelaxNG.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixml_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscixml_algo_la-XMLValidationRelaxNG.lo `test -f 'src/cpp/XMLValidationRelaxNG.cpp' || echo '$(srcdir)/'`src/cpp/XMLValidationRelaxNG.cpp
+
 libscixml_la-sci_xmlRead.lo: sci_gateway/cpp/sci_xmlRead.cpp
 @am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixml_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libscixml_la-sci_xmlRead.lo -MD -MP -MF $(DEPDIR)/libscixml_la-sci_xmlRead.Tpo -c -o libscixml_la-sci_xmlRead.lo `test -f 'sci_gateway/cpp/sci_xmlRead.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xmlRead.cpp
 @am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscixml_la-sci_xmlRead.Tpo $(DEPDIR)/libscixml_la-sci_xmlRead.Plo
@@ -1047,6 +1093,20 @@ libscixml_la-sci_percent_foo_i_XMLList.lo: sci_gateway/cpp/sci_percent_foo_i_XML
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixml_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscixml_la-sci_percent_foo_i_XMLList.lo `test -f 'sci_gateway/cpp/sci_percent_foo_i_XMLList.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_percent_foo_i_XMLList.cpp
 
+libscixml_la-sci_xmlValidationFile.lo: sci_gateway/cpp/sci_xmlValidationFile.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixml_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libscixml_la-sci_xmlValidationFile.lo -MD -MP -MF $(DEPDIR)/libscixml_la-sci_xmlValidationFile.Tpo -c -o libscixml_la-sci_xmlValidationFile.lo `test -f 'sci_gateway/cpp/sci_xmlValidationFile.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xmlValidationFile.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscixml_la-sci_xmlValidationFile.Tpo $(DEPDIR)/libscixml_la-sci_xmlValidationFile.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_xmlValidationFile.cpp' object='libscixml_la-sci_xmlValidationFile.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixml_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscixml_la-sci_xmlValidationFile.lo `test -f 'sci_gateway/cpp/sci_xmlValidationFile.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xmlValidationFile.cpp
+
+libscixml_la-sci_xmlValidate.lo: sci_gateway/cpp/sci_xmlValidate.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixml_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libscixml_la-sci_xmlValidate.lo -MD -MP -MF $(DEPDIR)/libscixml_la-sci_xmlValidate.Tpo -c -o libscixml_la-sci_xmlValidate.lo `test -f 'sci_gateway/cpp/sci_xmlValidate.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xmlValidate.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscixml_la-sci_xmlValidate.Tpo $(DEPDIR)/libscixml_la-sci_xmlValidate.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_xmlValidate.cpp' object='libscixml_la-sci_xmlValidate.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixml_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscixml_la-sci_xmlValidate.lo `test -f 'sci_gateway/cpp/sci_xmlValidate.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xmlValidate.cpp
+
 mostlyclean-libtool:
        -rm -f *.lo
 
index 3cf6895..d25c0b9 100644 (file)
           <link linkend="XMLNodeSet">XML XPath result set</link>
         </para>
       </listitem>
+      <listitem>
+        <para>
+          <link linkend="XMLValid">XML Validation file</link>
+        </para>
+      </listitem>
     </itemizedlist>
   </refsection>
 
     ]]></programlisting>
   </refsection>
 
+  <refsection id="XMLValid">
+    <title>XML Validation file</title>
+
+    <para>A XML Validation file is an object used to validate a document. It is possible to validate in using DTD, Relax NG or schema.</para>
+    <programlisting role="example"><![CDATA[
+    doc = xmlRead("SCI/modules/xml/tests/unit_tests/library.xml");
+    dtd = xmlDTD("SCI/modules/xml/tests/unit_tests/library.dtd");
+    schema = xmlSchema("SCI/modules/xml/tests/unit_tests/library.xsd");
+    rng = xmlRelaxNG("SCI/modules/xml/tests/unit_tests/library.rng");
+
+    // Validation
+    xmlValidate(doc, dtd);
+    xmlValidate(doc, rng);
+    xmlValidate(doc, schema);
+
+    xmlClose("all");
+    ]]></programlisting>
+  </refsection>
+
   <refsection role="see also">
     <title>See Also</title>
     <simplelist type="inline">
       <member>
         <link linkend="xmlNs">xmlNs</link>
       </member>
+      <member>
+        <link linkend="xmlDTD">xmlDTD</link>
+      </member>
+      <member>
+        <link linkend="xmlSchema">xmlSchema</link>
+      </member>
+      <member>
+        <link linkend="xmlRelaxNG">xmlRelaxNG</link>
+      </member>
     </simplelist>
   </refsection>
 
index 3ef3e7d..fd4aeb4 100644 (file)
@@ -30,7 +30,7 @@
     <title>Calling Sequence</title>
 
     <synopsis>
-      xmlClose(doc1 [, doc2, [...]])
+      xmlClose(obj1 [, obj2, [...]])
       xmlClose("all")
     </synopsis>
   </refsynopsisdiv>
@@ -40,9 +40,9 @@
 
     <variablelist>
       <varlistentry>
-        <term>doci</term>
+        <term>obji</term>
         <listitem>
-          <para>a mlist type XMLDoc, the document to close</para>
+          <para>a mlist type XMLDoc or XMLValid, the document to close</para>
         </listitem>
       </varlistentry>
     </variablelist>
@@ -51,8 +51,8 @@
   <refsection>
     <title>Description</title>
 
-    <para>Close a document (in fact free all the memory associated with this document).</para>
-    <para>When the syntax xmlClose("all") is used, all the open documents will be closed.</para>
+    <para>Close a document or a validation file (in fact free all the memory associated with this object).</para>
+    <para>When the syntax xmlClose("all") is used, all the open streams will be closed.</para>
   </refsection>
 
   <refsection>
diff --git a/scilab/modules/xml/help/en_US/xmlDTD.xml b/scilab/modules/xml/help/en_US/xmlDTD.xml
new file mode 100644 (file)
index 0000000..406de6c
--- /dev/null
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+*
+* This file must be used under the terms of the CeCILL.
+* This source file is licensed as described in the file COPYING, which
+* you should have received as part of this distribution.  The terms
+* are also available at
+* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+-->
+<refentry version="5.0-subset Scilab" xml:id="xmlDTD" xml:lang="en"
+          xmlns="http://docbook.org/ns/docbook"
+          xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg"
+          xmlns:ns5="http://www.w3.org/1999/xhtml"
+          xmlns:mml="http://www.w3.org/1998/Math/MathML"
+          xmlns:db="http://docbook.org/ns/docbook">
+  <info>
+    <pubdate>$LastChangedDate$</pubdate>
+  </info>
+
+  <refnamediv>
+    <refname>xmlDTD</refname>
+    <refpurpose>Create a XML DTD object</refpurpose>
+  </refnamediv>
+
+  <refsynopsisdiv>
+    <title>Calling Sequence</title>
+
+    <synopsis>
+      dtd = xmlDTD(path)
+    </synopsis>
+  </refsynopsisdiv>
+
+  <refsection>
+    <title>Arguments</title>
+
+    <variablelist>
+      <varlistentry>
+        <term>path</term>
+        <listitem>
+          <para>a string giving the path of the validation file</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>dtd</term>
+        <listitem>
+          <para>a mlist typed XMLValid</para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsection>
+
+  <refsection>
+    <title>Description</title>
+
+    <para>Useful to validate a document with a DTD.</para>
+  </refsection>
+
+  <refsection>
+    <title>Examples</title>
+    <programlisting role="example"><![CDATA[
+    doc = xmlRead("SCI/modules/xml/tests/unit_tests/library.xml");
+    dtd = xmlDTD("SCI/modules/xml/tests/unit_tests/library.dtd");
+
+    // We test if the document is valid
+    // If no error the file is valid
+
+    xmlValidate(doc, dtd);
+
+    xmlClose(doc, dtd);
+    ]]></programlisting>
+  </refsection>
+
+  <refsection role="see also">
+    <title>See Also</title>
+    <simplelist type="inline">
+      <member>
+        <link linkend="xmlValidate">xmlValidate</link>
+      </member>
+    </simplelist>
+  </refsection>
+
+  <refsection>
+    <title>Author</title>
+    <para>Calixte DENIZET</para>
+  </refsection>
+</refentry>
\ No newline at end of file
index 9f2b109..8bafd78 100644 (file)
@@ -23,7 +23,7 @@
 
   <refnamediv>
     <refname>xmlGetOpenStreams</refname>
-    <refpurpose>Get all open XML documents</refpurpose>
+    <refpurpose>Get all open XML documents or all open XML Validation files.</refpurpose>
   </refnamediv>
 
   <refsynopsisdiv>
@@ -41,7 +41,7 @@
       <varlistentry>
         <term>list</term>
         <listitem>
-          <para>list, a list containing all the open documents</para>
+          <para>list, a list containing all the open documents or XML Validation files</para>
         </listitem>
       </varlistentry>
     </variablelist>
@@ -50,7 +50,7 @@
   <refsection>
     <title>Description</title>
 
-    <para>Get all the open documents. This function is useful to close documents.</para>
+    <para>This function is useful to close open streams (and essentially to free the memory).</para>
   </refsection>
 
   <refsection>
index 7de2ba6..ebbd75e 100644 (file)
@@ -30,7 +30,7 @@
     <title>Calling Sequence</title>
 
     <synopsis>
-      doc = xmlRead(path)
+      doc = xmlRead(path [, validateDTD])
     </synopsis>
   </refsynopsisdiv>
 
       </varlistentry>
 
       <varlistentry>
+        <term>validateDTD</term>
+        <listitem>
+          <para>a boolean to indicate if the document must be validated.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
         <term>doc</term>
         <listitem>
           <para>a mlist typed XMLDoc</para>
@@ -58,7 +65,7 @@
     <title>Description</title>
 
     <para>Read and parse a XML file. The returned document allows to access to the DOM tree which is kept in memory.</para>
-
+    <para>If validateDTD is set to true, the document will be validated or not during the parsing operation.</para>
     <para>It is important to notice that the tree must be freed (to avoid memory leaks) with the function <link linkend="xmlClose">xmlClose</link>.</para>
   </refsection>
 
       <member>
         <link linkend="xmlXPath">xmlXPath</link>
       </member>
+      <member>
+        <link linkend="xmlValidate">xmlValidate</link>
+      </member>
     </simplelist>
   </refsection>
 
index b49b09b..663f3d8 100644 (file)
@@ -30,7 +30,7 @@
     <title>Calling Sequence</title>
 
     <synopsis>
-      doc = xmlRead(string)
+      doc = xmlReadStr(string [, validateDTD])
     </synopsis>
   </refsynopsisdiv>
 
       </varlistentry>
 
       <varlistentry>
+        <term>validateDTD</term>
+        <listitem>
+          <para>a boolean to indicate if the document must be validated.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
         <term>doc</term>
         <listitem>
           <para>a mlist typed XMLDoc</para>
@@ -58,6 +65,7 @@
     <title>Description</title>
 
     <para>Read and parse a XML string. The returned document allows to access to the DOM tree which is kept in memory.</para>
+    <para>If validateDTD is set to true, the document will be validated or not during the parsing operation.</para>
 
     <para>It is important to notice that the tree must be freed (to avoid memory leaks) with the function <link linkend="xmlClose">xmlClose</link>.</para>
   </refsection>
       <member>
         <link linkend="xmlDocument">xmlDocument</link>
       </member>
+      <member>
+        <link linkend="xmlValidate">xmlValidate</link>
+      </member>
     </simplelist>
   </refsection>
 
diff --git a/scilab/modules/xml/help/en_US/xmlRelaxNG.xml b/scilab/modules/xml/help/en_US/xmlRelaxNG.xml
new file mode 100644 (file)
index 0000000..7bf5774
--- /dev/null
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+*
+* This file must be used under the terms of the CeCILL.
+* This source file is licensed as described in the file COPYING, which
+* you should have received as part of this distribution.  The terms
+* are also available at
+* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+-->
+<refentry version="5.0-subset Scilab" xml:id="xmlRelaxNG" xml:lang="en"
+          xmlns="http://docbook.org/ns/docbook"
+          xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg"
+          xmlns:ns5="http://www.w3.org/1999/xhtml"
+          xmlns:mml="http://www.w3.org/1998/Math/MathML"
+          xmlns:db="http://docbook.org/ns/docbook">
+  <info>
+    <pubdate>$LastChangedDate$</pubdate>
+  </info>
+
+  <refnamediv>
+    <refname>xmlRelaxNG</refname>
+    <refpurpose>Create a XML Relax NG object</refpurpose>
+  </refnamediv>
+
+  <refsynopsisdiv>
+    <title>Calling Sequence</title>
+
+    <synopsis>
+      schema = xmlRelaxNG(path)
+    </synopsis>
+  </refsynopsisdiv>
+
+  <refsection>
+    <title>Arguments</title>
+
+    <variablelist>
+      <varlistentry>
+        <term>path</term>
+        <listitem>
+          <para>a string giving the path of the validation file</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>dtd</term>
+        <listitem>
+          <para>a mlist typed XMLValid</para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsection>
+
+  <refsection>
+    <title>Description</title>
+
+    <para>Useful to validate a document with a Relax NG.</para>
+  </refsection>
+
+  <refsection>
+    <title>Examples</title>
+    <programlisting role="example"><![CDATA[
+    doc = xmlRead("SCI/modules/xml/tests/unit_tests/library.xml");
+    rng = xmlRelaxNG("SCI/modules/xml/tests/unit_tests/library.rng");
+
+    // We test if the document is valid
+    // If no error the file is valid
+
+    xmlValidate(doc, rng);
+
+    xmlClose(doc, rng);
+    ]]></programlisting>
+  </refsection>
+
+  <refsection role="see also">
+    <title>See Also</title>
+    <simplelist type="inline">
+      <member>
+        <link linkend="xmlValidate">xmlValidate</link>
+      </member>
+    </simplelist>
+  </refsection>
+
+  <refsection>
+    <title>Author</title>
+    <para>Calixte DENIZET</para>
+  </refsection>
+</refentry>
\ No newline at end of file
diff --git a/scilab/modules/xml/help/en_US/xmlSchema.xml b/scilab/modules/xml/help/en_US/xmlSchema.xml
new file mode 100644 (file)
index 0000000..1ac5494
--- /dev/null
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+*
+* This file must be used under the terms of the CeCILL.
+* This source file is licensed as described in the file COPYING, which
+* you should have received as part of this distribution.  The terms
+* are also available at
+* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+-->
+<refentry version="5.0-subset Scilab" xml:id="xmlSchema" xml:lang="en"
+          xmlns="http://docbook.org/ns/docbook"
+          xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg"
+          xmlns:ns5="http://www.w3.org/1999/xhtml"
+          xmlns:mml="http://www.w3.org/1998/Math/MathML"
+          xmlns:db="http://docbook.org/ns/docbook">
+  <info>
+    <pubdate>$LastChangedDate$</pubdate>
+  </info>
+
+  <refnamediv>
+    <refname>xmlSchema</refname>
+    <refpurpose>Create a XML Schema object</refpurpose>
+  </refnamediv>
+
+  <refsynopsisdiv>
+    <title>Calling Sequence</title>
+
+    <synopsis>
+      schema = xmlSchema(path)
+    </synopsis>
+  </refsynopsisdiv>
+
+  <refsection>
+    <title>Arguments</title>
+
+    <variablelist>
+      <varlistentry>
+        <term>path</term>
+        <listitem>
+          <para>a string giving the path of the validation file</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>dtd</term>
+        <listitem>
+          <para>a mlist typed XMLValid</para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsection>
+
+  <refsection>
+    <title>Description</title>
+
+    <para>Useful to validate a document with a Schema.</para>
+  </refsection>
+
+  <refsection>
+    <title>Examples</title>
+    <programlisting role="example"><![CDATA[
+    doc = xmlRead("SCI/modules/xml/tests/unit_tests/library.xml");
+    schema = xmlSchema("SCI/modules/xml/tests/unit_tests/library.xsd");
+
+    // We test if the document is valid
+    // If no error the file is valid
+
+    xmlValidate(doc, schema);
+
+    xmlClose(doc, schema);
+    ]]></programlisting>
+  </refsection>
+
+  <refsection role="see also">
+    <title>See Also</title>
+    <simplelist type="inline">
+      <member>
+        <link linkend="xmlValidate">xmlValidate</link>
+      </member>
+    </simplelist>
+  </refsection>
+
+  <refsection>
+    <title>Author</title>
+    <para>Calixte DENIZET</para>
+  </refsection>
+</refentry>
\ No newline at end of file
diff --git a/scilab/modules/xml/help/en_US/xmlValidate.xml b/scilab/modules/xml/help/en_US/xmlValidate.xml
new file mode 100644 (file)
index 0000000..f70002e
--- /dev/null
@@ -0,0 +1,125 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+*
+* This file must be used under the terms of the CeCILL.
+* This source file is licensed as described in the file COPYING, which
+* you should have received as part of this distribution.  The terms
+* are also available at
+* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+-->
+<refentry version="5.0-subset Scilab" xml:id="xmlValidate" xml:lang="en"
+          xmlns="http://docbook.org/ns/docbook"
+          xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg"
+          xmlns:ns5="http://www.w3.org/1999/xhtml"
+          xmlns:mml="http://www.w3.org/1998/Math/MathML"
+          xmlns:db="http://docbook.org/ns/docbook">
+  <info>
+    <pubdate>$LastChangedDate$</pubdate>
+  </info>
+
+  <refnamediv>
+    <refname>xmlValidate</refname>
+    <refpurpose>Validate a document in using a DTD, a Relax NG or a Schema.</refpurpose>
+  </refnamediv>
+
+  <refsynopsisdiv>
+    <title>Calling Sequence</title>
+
+    <synopsis>
+      xmlValidate(docs [, valid])
+    </synopsis>
+  </refsynopsisdiv>
+
+  <refsection>
+    <title>Arguments</title>
+
+    <variablelist>
+      <varlistentry>
+        <term>docs</term>
+        <listitem>
+          <para>a mlist typed XMLDoc or a matrix of string containing path to XML documents</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>valid</term>
+        <listitem>
+          <para>a mlist typed XMLValid.</para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsection>
+
+  <refsection>
+    <title>Description</title>
+
+    <para>Validate a already parsed document or a set of documents with given paths with a DTD, a Relax NG or a Schema. To know if a document is valid or not, you just have to put the xmlValidate in a try...catch statement.</para>
+    <para>Validate a document with its path can improve performance and reduce the memory consumption.</para>
+    <para>It is not possible for the moment to validate a document against an external DTD. The only way to do this is to include in your XML file someting like <![CDATA[<!DOCTYPE foo SYSTEM "foo.dtd">]]> and to use xmlValidate without second argument.</para>
+  </refsection>
+
+  <refsection>
+    <title>Examples</title>
+    <programlisting role="example"><![CDATA[
+    doc = xmlRead("SCI/modules/xml/tests/unit_tests/library.xml");
+    dtd = xmlDTD("SCI/modules/xml/tests/unit_tests/library.dtd");
+    schema = xmlSchema("SCI/modules/xml/tests/unit_tests/library.xsd");
+    rng = xmlRelaxNG("SCI/modules/xml/tests/unit_tests/library.rng");
+
+    // We test if the document is valid
+    // If no error the file is valid
+
+    // DTD
+    xmlValidate(doc, dtd);
+
+    // Relax NG
+    xmlValidate(doc, rng);
+
+    // Schema
+    xmlValidate(doc, schema);
+
+    // All is ok... now we add a new element to the document
+    doc.root.children(3) = "<a>error</a>"
+
+    // Now the validations go to fail
+    xmlValidate(doc, dtd);
+    xmlValidate(doc, rng);
+    xmlValidate(doc, schema);
+
+    // You can validate a document with its path
+    xmlValidate("SCI/modules/xml/tests/unit_tests/library.xml")
+    xmlValidate("SCI/modules/xml/tests/unit_tests/invalid_library.xml")
+
+    xmlValidate("SCI/modules/xml/tests/unit_tests/library.xml", schema)
+    xmlValidate("SCI/modules/xml/tests/unit_tests/invalid_library.xml", rng)
+
+    // We close the all the open streams
+    xmlClose(doc, dtd, schema, rng);
+    ]]></programlisting>
+
+  </refsection>
+
+  <refsection role="see also">
+    <title>See Also</title>
+    <simplelist type="inline">
+      <member>
+        <link linkend="xmlDTD">xmlDTD</link>
+      </member>
+      <member>
+        <link linkend="xmlSchema">xmlSchema</link>
+      </member>
+      <member>
+        <link linkend="xmlRelaxNG">xmlRelaxNG</link>
+      </member>
+    </simplelist>
+  </refsection>
+
+  <refsection>
+    <title>Author</title>
+    <para>Calixte DENIZET</para>
+  </refsection>
+</refentry>
index 72bc4c2..f257bda 100644 (file)
@@ -61,6 +61,11 @@ int sci_xmlGetNsByPrefix(char *fname, unsigned long fname_len);
 int sci_xmlWrite(char *fname, unsigned long fname_len);
 int sci_percent_XMLList_length(char *fname, unsigned long fname_len);
 int sci_percent_XMLAttr_length(char *fname, unsigned long fname_len);
+int sci_xmlDTD(char *fname, unsigned long fname_len);
+int sci_xmlSchema(char *fname, unsigned long fname_len);
+int sci_xmlRelaxNG(char *fname, unsigned long fname_len);
+int sci_xmlValidate(char *fname, unsigned long fname_len);
+int sci_percent_XMLValid_p(char *fname, unsigned long fname_len);
 /*--------------------------------------------------------------------------*/
 #endif /* __GW_XML_H__ */
 /*--------------------------------------------------------------------------*/
index e8782cb..f889c44 100644 (file)
@@ -16,4 +16,9 @@ extern "C"
 #include <libxml/parser.h>
 #include <libxml/xpath.h>
 #include <libxml/xpathInternals.h>
+#include <libxml/valid.h>
+#include <libxml/schemasInternals.h>
+#include <libxml/xmlschemas.h>
+#include <libxml/relaxng.h>
+#include <libxml/xmlreader.h>
 }
index 25c1482..1863826 100644 (file)
@@ -20,6 +20,7 @@
 #define XMLLIST 5
 #define XMLNOTHANDLED 6
 #define XMLSET 7
+#define XMLVALID 8
 
 /**
  * Creates an XML object at a given position in the stack
@@ -102,6 +103,13 @@ int isXMLSet(int * mlist);
  * @param mlist the mlist address
  * @return 1 if the mlist has the good type, else 0.
  */
+int isXMLValid(int * mlist);
+
+/**
+ * Get the XMLObject field _id
+ * @param mlist the mlist address
+ * @return the object id.
+ */
 int getXMLObjectId(int * mlist);
 
 #endif /* __XML_MLIST_H__ */
index 0480156..43f7d05 100644 (file)
@@ -87,7 +87,12 @@ static gw_generic_table Tab[] =
     {sci_xmlWrite, "xmlWrite"},
     {sci_percent_XMLList_length, "%XMLList_length"},
     {sci_percent_XMLList_length, "%XMLSet_length"},
-    {sci_percent_XMLAttr_length, "%XMLAttr_length"}
+    {sci_percent_XMLAttr_length, "%XMLAttr_length"},
+    {sci_xmlDTD, "xmlDTD"},
+    {sci_xmlSchema, "xmlSchema"},
+    {sci_xmlRelaxNG, "xmlRelaxNG"},
+    {sci_xmlValidate, "xmlValidate"},
+    {sci_percent_XMLValid_p, "%XMLValid_p"}
 };
 /*--------------------------------------------------------------------------*/
 int gw_xml(void)
index 5114296..adffc5b 100644 (file)
@@ -91,3 +91,8 @@ int sci_percent_XMLSet_p(char *fname, unsigned long fname_len)
     return sci_print(fname, fname_len);
 }
 /*--------------------------------------------------------------------------*/
+int sci_percent_XMLValid_p(char *fname, unsigned long fname_len)
+{
+    return sci_print(fname, fname_len);
+}
+/*--------------------------------------------------------------------------*/
index ef74108..b9fd795 100644 (file)
@@ -12,6 +12,7 @@
 
 #include "XMLObject.hxx"
 #include "XMLDocument.hxx"
+#include "XMLValidation.hxx"
 
 extern "C"
 {
@@ -31,7 +32,8 @@ int sci_xmlClose(char * fname, unsigned long fname_len)
     int id;
     SciErr err;
     int * addr = 0;
-    org_modules_xml::XMLDocument * doc;
+    org_modules_xml::XMLDocument * doc = 0;
+    XMLValidation * vf = 0;
     char * com = 0;
 
     CheckLhs(1, 1);
@@ -55,6 +57,7 @@ int sci_xmlClose(char * fname, unsigned long fname_len)
         if (!strcmp(com, "all"))
         {
             org_modules_xml::XMLDocument::closeAllDocuments();
+            XMLValidation::closeAllValidationFiles();
         }
         freeAllocatedSingleString(com);
     }
@@ -80,6 +83,17 @@ int sci_xmlClose(char * fname, unsigned long fname_len)
                 }
                 delete doc;
             }
+            else if (isXMLValid(addr))
+            {
+                id = getXMLObjectId(addr);
+                vf = XMLObject::getFromId<XMLValidation>(id);
+                if (!vf)
+                {
+                    Scierror(999, gettext("%s: XML validation file does not exist.\n"), fname);
+                    return 0;
+                }
+                delete vf;
+            }
             else
             {
                 Scierror(999, gettext("%s: Wrong type for input argument #%i: A %s expected\n"), fname, 1, "XMLDoc");
index f277034..5ac9635 100644 (file)
@@ -12,6 +12,7 @@
 
 #include "XMLObject.hxx"
 #include "XMLDocument.hxx"
+#include "XMLValidation.hxx"
 
 extern "C"
 {
@@ -34,20 +35,26 @@ int sci_xmlGetOpenStreams(char *fname, unsigned long fname_len)
     CheckLhs(1, 1);
     CheckRhs(0, 0);
 
-    std::list<org_modules_xml::XMLDocument *> & openDocs = org_modules_xml::XMLDocument::getOpenDocuments();
+    const std::list<org_modules_xml::XMLDocument *> & openDocs = org_modules_xml::XMLDocument::getOpenDocuments();
+    const std::list<org_modules_xml::XMLValidation *> & openValidationFiles = org_modules_xml::XMLValidation::getOpenValidationFiles();
 
-    err = createList(pvApiCtx, Rhs + 1, (int)openDocs.size(), &addr);
+    err = createList(pvApiCtx, Rhs + 1, (int)openDocs.size() + (int)openValidationFiles.size(), &addr);
     if (err.iErr)
     {
         printError(&err, 0);
         return 0;
     }
 
-    for (std::list<org_modules_xml::XMLDocument *>::iterator i = openDocs.begin(); i != openDocs.end(); i++, j++)
+    for (std::list<org_modules_xml::XMLDocument *>::const_iterator i = openDocs.begin(); i != openDocs.end(); i++, j++)
     {
         createXMLObjectAtPosInList(addr, Rhs + 1, XMLDOCUMENT, j, (*i)->getId());
     }
 
+    for (std::list<org_modules_xml::XMLValidation *>::const_iterator i = openValidationFiles.begin(); i != openValidationFiles.end(); i++, j++)
+    {
+        createXMLObjectAtPosInList(addr, Rhs + 1, XMLVALID, j, (*i)->getId());
+    }
+
     LhsVar(1) = Rhs + 1;
     PutLhsVar();
     return 0;
index 461c573..290d947 100644 (file)
@@ -27,7 +27,6 @@ extern "C"
 #include "XMLObject.hxx"
 #include "XMLDocument.hxx"
 
-
 using namespace org_modules_xml;
 
 /*--------------------------------------------------------------------------*/
@@ -37,7 +36,7 @@ int sci_xmlRead(char * fname, unsigned long fname_len)
     SciErr err;
     int * addr = 0;
     char * path = 0;
-    char * error = 0;
+    std::string error;
     bool validate = false;
     int validateParam;
 
@@ -82,10 +81,10 @@ int sci_xmlRead(char * fname, unsigned long fname_len)
     doc = new org_modules_xml::XMLDocument((const char *)path, validate, &error);
     freeAllocatedSingleString(path);
 
-    if (error)
+    if (!error.empty())
     {
         delete doc;
-        Scierror(999, gettext("%s: Cannot read the file:\n%s"), fname, error);
+        Scierror(999, gettext("%s: Cannot read the file:\n%s"), fname, error.c_str());
         return 0;
     }
 
index 786a2ca..d1b0f5c 100644 (file)
@@ -13,7 +13,6 @@
 #include "XMLObject.hxx"
 #include "XMLDocument.hxx"
 #include "XMLRhsValue.hxx"
-#include <iostream>
 
 extern "C"
 {
@@ -34,7 +33,7 @@ int sci_xmlReadStr(char * fname, unsigned long fname_len)
     SciErr err;
     int * addr = 0;
     std::string * code;
-    char * error = 0;
+    std::string error;
     bool validate = false;
     int validateParam;
 
@@ -83,10 +82,10 @@ int sci_xmlReadStr(char * fname, unsigned long fname_len)
     doc = new org_modules_xml::XMLDocument(*code, validate, &error);
     delete code;
 
-    if (error)
+    if (!error.empty())
     {
         delete doc;
-        Scierror(999, gettext("%s: Cannot parse the string:\n%s"), fname, error);
+        Scierror(999, gettext("%s: Cannot parse the string:\n%s"), fname, error.c_str());
         return 0;
     }
 
diff --git a/scilab/modules/xml/sci_gateway/cpp/sci_xmlValidate.cpp b/scilab/modules/xml/sci_gateway/cpp/sci_xmlValidate.cpp
new file mode 100644 (file)
index 0000000..e1e79c5
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#include "XMLObject.hxx"
+#include "XMLDocument.hxx"
+
+extern "C"
+{
+#include "xml.h"
+#include "gw_xml.h"
+#include "stack-c.h"
+#include "Scierror.h"
+#include "api_scilab.h"
+#include "xml_mlist.h"
+#include "localization.h"
+}
+
+#include "XMLObject.hxx"
+#include "XMLDocument.hxx"
+#include "XMLValidation.hxx"
+#include "XMLValidationDTD.hxx"
+
+using namespace org_modules_xml;
+
+/*--------------------------------------------------------------------------*/
+int sci_xmlValidate(char * fname, unsigned long fname_len)
+{
+    XMLValidation * validation = 0;
+    org_modules_xml::XMLDocument * doc = 0;
+    SciErr err;
+    int * addr = 0;
+    std::string error;
+    int id;
+    bool isValid;
+    char ** path = 0;
+    int row = 0;
+    int col = 0;
+
+    CheckLhs(1, 1);
+    CheckRhs(1, 2);
+
+    err = getVarAddressFromPosition(pvApiCtx, 1, &addr);
+    if (err.iErr)
+    {
+        printError(&err, 0);
+        return 0;
+    }
+
+    if (isStringType(pvApiCtx, addr))
+    {
+        getAllocatedMatrixOfString(pvApiCtx, addr, &row, &col, &path);
+    }
+    else if (isXMLDoc(addr))
+    {
+        id = getXMLObjectId(addr);
+        doc = XMLObject::getFromId<org_modules_xml::XMLDocument>(id);
+        if (!doc)
+        {
+            Scierror(999, gettext("%s: XML document does not exist\n"), fname);
+            return 0;
+        }
+    }
+    else
+    {
+        Scierror(999, gettext("%s: Wrong type for input argument #%i: A matrix of strings or a XMLDoc expected.\n"), fname, 1);
+        return 0;
+    }
+
+    if (Rhs == 2)
+    {
+        err = getVarAddressFromPosition(pvApiCtx, 2, &addr);
+        if (err.iErr)
+        {
+            printError(&err, 0);
+            return 0;
+        }
+
+        if (!isXMLValid(addr))
+        {
+            Scierror(999, gettext("%s: Wrong type for input argument #%i: A %s expected.\n"), fname, 1, "XMLValid");
+            return 0;
+        }
+
+        id = getXMLObjectId(addr);
+        validation = XMLObject::getFromId<XMLValidation>(id);
+        if (!validation)
+        {
+            Scierror(999, gettext("%s: XML validation file does not exist.\n"), fname);
+            return 0;
+        }
+    }
+    else
+    {
+       validation = new XMLValidationDTD(&error);
+    }
+
+    if (path)
+    {
+        std::string msg = std::string("");
+        for (int i = 0; i < row * col; i++)
+        {
+            isValid = validation->validate(path[i], &error);
+            if (!isValid)
+            {
+                char * s = new char[strlen(gettext("The file %s is not valid:\n%s\n")) + strlen(path[i]) + error.size() + 1];
+                sprintf(s, gettext("The file %s is not valid:\n%s\n"), path[i], error.c_str());
+                msg.append(s);
+                delete [] s;
+            }
+        }
+        if (!msg.empty())
+        {
+            Scierror(999, "%s: %s", fname, msg.c_str());
+            return 0;
+        }
+    }
+    else
+    {
+        isValid = validation->validate(*doc, &error);
+        if (!isValid)
+        {
+            Scierror(999, gettext("%s: The file is not valid:\n%s"), fname, error.c_str());
+            return 0;
+        }
+    }
+
+    LhsVar(1) = 0;
+    PutLhsVar();
+
+    return 0;
+}
+/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/xml/sci_gateway/cpp/sci_xmlValidationFile.cpp b/scilab/modules/xml/sci_gateway/cpp/sci_xmlValidationFile.cpp
new file mode 100644 (file)
index 0000000..e1fb605
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#include "XMLObject.hxx"
+#include "XMLDocument.hxx"
+
+extern "C"
+{
+#include "xml.h"
+#include "gw_xml.h"
+#include "stack-c.h"
+#include "Scierror.h"
+#include "api_scilab.h"
+#include "xml_mlist.h"
+#include "localization.h"
+}
+
+#include "XMLObject.hxx"
+#include "XMLValidation.hxx"
+#include "XMLValidationDTD.hxx"
+#include "XMLValidationSchema.hxx"
+#include "XMLValidationRelaxNG.hxx"
+
+using namespace org_modules_xml;
+
+/*--------------------------------------------------------------------------*/
+template <class T>
+int sci_xmlValidationFile(char * fname, unsigned long fname_len)
+{
+    T * validation = 0;
+    SciErr err;
+    int * addr = 0;
+    char * path = 0;
+    std::string error;
+
+    CheckLhs(1, 1);
+    CheckRhs(1, 1);
+
+    err = getVarAddressFromPosition(pvApiCtx, 1, &addr);
+    if (err.iErr)
+    {
+        printError(&err, 0);
+        return 0;
+    }
+
+    if (!isStringType(pvApiCtx, addr))
+    {
+        Scierror(999, gettext("%s: Wrong type for input argument #%i: A string expected.\n"), fname, 1);
+        return 0;
+    }
+    getAllocatedSingleString(pvApiCtx, addr, &path);
+
+    validation = new T((const char *)path, &error);
+    freeAllocatedSingleString(path);
+
+    if (!error.empty())
+    {
+        delete validation;
+        Scierror(999, gettext("%s: Cannot read the file:\n%s"), fname, error.c_str());
+        return 0;
+    }
+
+    if (!validation->createOnStack(Rhs + 1))
+    {
+        return 0;
+    }
+
+    LhsVar(1) = Rhs + 1;
+    PutLhsVar();
+    return 0;
+}
+/*--------------------------------------------------------------------------*/
+int sci_xmlDTD(char * fname, unsigned long fname_len)
+{
+    return sci_xmlValidationFile<XMLValidationDTD>(fname, fname_len);
+}
+/*--------------------------------------------------------------------------*/
+int sci_xmlRelaxNG(char * fname, unsigned long fname_len)
+{
+    return sci_xmlValidationFile<XMLValidationRelaxNG>(fname, fname_len);
+}
+/*--------------------------------------------------------------------------*/
+int sci_xmlSchema(char * fname, unsigned long fname_len)
+{
+    return sci_xmlValidationFile<XMLValidationSchema>(fname, fname_len);
+}
+/*--------------------------------------------------------------------------*/
index f31dc47..94f1097 100644 (file)
@@ -38,7 +38,7 @@ int sci_xmlXPath(char * fname, unsigned long fname_len)
     const XMLXPath * xpath;
     int * addr = 0;
     char * query = 0;
-    char * error = 0;
+    std::string error;
     int row = 0;
     int col = 0;
     char ** namespaces = 0;
@@ -123,9 +123,9 @@ int sci_xmlXPath(char * fname, unsigned long fname_len)
         freeAllocatedMatrixOfString(row, col, namespaces);
     }
 
-    if (error)
+    if (!error.empty())
     {
-        Scierror(999, gettext("%s: Bad XPath query:\n%s"), fname, error);
+        Scierror(999, gettext("%s: Bad XPath query:\n%s"), fname, error.c_str());
         return 0;
     }
 
index 61ec095..d702645 100644 (file)
@@ -97,4 +97,9 @@
 <PRIMITIVE gatewayId="68" primitiveId="66" primitiveName="%XMLList_length" />
 <PRIMITIVE gatewayId="68" primitiveId="67" primitiveName="%XMLSet_length" />
 <PRIMITIVE gatewayId="68" primitiveId="68" primitiveName="%XMLAttr_length" />
+<PRIMITIVE gatewayId="68" primitiveId="69" primitiveName="xmlDTD" />
+<PRIMITIVE gatewayId="68" primitiveId="70" primitiveName="xmlSchema" />
+<PRIMITIVE gatewayId="68" primitiveId="71" primitiveName="xmlRelaxNG" />
+<PRIMITIVE gatewayId="68" primitiveId="72" primitiveName="xmlValidate" />
+<PRIMITIVE gatewayId="68" primitiveId="73" primitiveName="%XMLValid_p" />
 </GATEWAY>
index 7d08e07..47f5338 100644 (file)
 #include "Scierror.h"
 #include "MALLOC.h"
 
-#define NB_XMLOBJECTS 7
-static const char *XMLObjects[] = { "XMLDoc", "XMLElem", "XMLAttr", "XMLNs", "XMLList", "XMLNH", "XMLSet" };
+#define NB_XMLOBJECTS 8
+static const char * XMLObjects[] = { "XMLDoc", "XMLElem", "XMLAttr", "XMLNs", "XMLList", "XMLNH", "XMLSet", "XMLValid" };
 
-static const char *_XMLDoc[] = { "XMLDoc", "_id" };
-static const char *_XMLElem[] = { "XMLElem", "_id" };
-static const char *_XMLAttr[] = { "XMLAttr", "_id" };
-static const char *_XMLNs[] = { "XMLNs", "_id" };
-static const char *_XMLList[] = { "XMLList", "_id" };
-static const char *_XMLNotHandled[] = { "XMLNH", "_id" };
-static const char *_XMLSet[] = { "XMLSet", "_id" };
+static const char * _XMLDoc[] = { "XMLDoc", "_id" };
+static const char * _XMLElem[] = { "XMLElem", "_id" };
+static const char * _XMLAttr[] = { "XMLAttr", "_id" };
+static const char * _XMLNs[] = { "XMLNs", "_id" };
+static const char * _XMLList[] = { "XMLList", "_id" };
+static const char * _XMLNotHandled[] = { "XMLNH", "_id" };
+static const char * _XMLSet[] = { "XMLSet", "_id" };
+static const char * _XMLValid[] = { "XMLValid", "_id" };
 
 static int compareStrToMlistType(const char ** str, int nb, int * mlist);
 
@@ -59,6 +60,9 @@ int createXMLObjectAtPos(int type, int pos, int id)
     case XMLSET:;
         fields = _XMLSet;
         break;
+    case XMLVALID:;
+        fields = _XMLValid;
+        break;
     }
 
     err = createMList(pvApiCtx, pos, 2, &mlistaddr);
@@ -122,6 +126,9 @@ int createXMLObjectAtPosInList(int * list, int stackPos, int type, int pos, int
     case XMLSET:;
         fields = _XMLSet;
         break;
+    case XMLVALID:;
+        fields = _XMLValid;
+        break;
     }
 
     err = createMatrixOfStringInList(pvApiCtx, stackPos, mlistaddr, 1, 1, 2, fields);
@@ -176,6 +183,10 @@ int isXMLSet(int * mlist)
     return compareStrToMlistType(XMLObjects + 6, 1, mlist);
 }
 /*--------------------------------------------------------------------------*/
+int isXMLValid(int * mlist)
+{
+    return compareStrToMlistType(XMLObjects + 7, 1, mlist);
+}/*--------------------------------------------------------------------------*/
 int isXMLObject(int * mlist)
 {
     return compareStrToMlistType(XMLObjects, NB_XMLOBJECTS, mlist);
index 8df7be8..1841e88 100644 (file)
 #include "XMLDocument.hxx"
 #include "XMLElement.hxx"
 #include "XMLXPath.hxx"
+#include "XMLValidation.hxx"
+#include "XMLValidationRelaxNG.hxx"
 #include "VariableScope.hxx"
 
 extern "C" {
 #include "expandPathVariable.h"
 #include "MALLOC.h"
+#include "localization.h"
 }
 
 #define BUFFER_SIZE 1024
@@ -30,7 +33,7 @@ namespace org_modules_xml
     std::string * XMLDocument::errorXPathBuffer = 0;
     std::list<XMLDocument *> & XMLDocument::openDocs = *new std::list<XMLDocument *>();
 
-    XMLDocument::XMLDocument(const char * path, bool validate, char ** error) : XMLObject()
+    XMLDocument::XMLDocument(const char * path, bool validate, std::string * error) : XMLObject()
     {
         char * expandedPath = expandPathVariable(const_cast<char *>(path));
         document = readDocument(const_cast<const char *>(expandedPath), validate, error);
@@ -44,7 +47,7 @@ namespace org_modules_xml
         scilabType = XMLDOCUMENT;
     }
 
-    XMLDocument::XMLDocument(const std::string & xmlCode, bool validate, char ** error) : XMLObject()
+    XMLDocument::XMLDocument(const std::string & xmlCode, bool validate, std::string * error) : XMLObject()
     {
         document = readDocument(xmlCode, validate, error);
         if (document)
@@ -89,7 +92,7 @@ namespace org_modules_xml
         if (document)
         {
             openDocs.remove(this);
-            if (openDocs.size() == 0)
+            if (openDocs.size() == 0 && XMLValidation::getOpenValidationFiles().size() == 0)
             {
                 resetScope();
             }
@@ -107,7 +110,7 @@ namespace org_modules_xml
         }
     }
 
-    const XMLXPath * XMLDocument::makeXPathQuery(const char * query, char ** namespaces, int length, char ** error)
+    const XMLXPath * XMLDocument::makeXPathQuery(const char * query, char ** namespaces, int length, std::string * error)
     {
         if (errorXPathBuffer)
         {
@@ -118,7 +121,8 @@ namespace org_modules_xml
         xmlXPathContext * ctxt = xmlXPathNewContext(document);
         if (!ctxt)
         {
-            *error = const_cast<char *>("Cannot create a parser context");
+            errorXPathBuffer->append(gettext("Cannot create a parser context"));
+            *error = *errorXPathBuffer;
             return 0;
         }
 
@@ -134,14 +138,14 @@ namespace org_modules_xml
         xmlXPathCompExpr * expr = xmlXPathCtxtCompile(ctxt, (const xmlChar *)query);
         if (!expr)
         {
-            *error = const_cast<char *>(errorXPathBuffer->c_str());
+            *error = *errorXPathBuffer;
             return 0;
         }
 
         xmlXPathObject * xpath = xmlXPathCompiledEval(expr, ctxt);
         if (!xpath)
         {
-            *error = const_cast<char *>(errorXPathBuffer->c_str());
+            *error = *errorXPathBuffer;
             return 0;
         }
 
@@ -195,11 +199,11 @@ namespace org_modules_xml
         }
     }
 
-    void XMLDocument::setRoot(const std::string & xmlCode, char ** error) const
+    void XMLDocument::setRoot(const std::string & xmlCode, std::string * error) const
     {
         XMLDocument doc = XMLDocument(xmlCode, false, error);
 
-        if (!*error)
+        if (error->empty())
         {
             setRoot(*doc.getRoot());
         }
@@ -233,7 +237,7 @@ namespace org_modules_xml
         }
     }
 
-    std::list<XMLDocument *> & XMLDocument::getOpenDocuments()
+    const std::list<XMLDocument *> & XMLDocument::getOpenDocuments()
     {
         return openDocs;
     }
@@ -254,7 +258,7 @@ namespace org_modules_xml
         delete [] arr;
     }
 
-    xmlDoc * XMLDocument::readDocument(const char * filename, bool validate, char ** error)
+    xmlDoc * XMLDocument::readDocument(const char * filename, bool validate, std::string * error)
     {
         xmlParserCtxt * ctxt = initContext(error, validate);
         xmlDoc * doc;
@@ -273,9 +277,10 @@ namespace org_modules_xml
         doc = xmlCtxtReadFile(ctxt, filename, 0, options);
         if (!doc || !ctxt->valid)
         {
-            *error = const_cast<char *>(errorBuffer->c_str());
+            *error = *errorBuffer;
         }
 
+        xmlSetGenericErrorFunc(ctxt, 0);
         xmlFreeParserCtxt(ctxt);
 
         return doc;
@@ -287,7 +292,7 @@ namespace org_modules_xml
      * @param error a string where to write the parsing errors
      * @return a pointer on a xmlDoc
      */
-    xmlDoc * XMLDocument::readDocument(const std::string & xmlCode, bool validate, char ** error)
+    xmlDoc * XMLDocument::readDocument(const std::string & xmlCode, bool validate, std::string * error)
     {
         xmlParserCtxt * ctxt = initContext(error, validate);
         xmlDoc * doc;
@@ -306,15 +311,16 @@ namespace org_modules_xml
         doc = xmlCtxtReadDoc(ctxt, (const xmlChar *)xmlCode.c_str(), 0, 0, options);
         if (!doc || !ctxt->valid)
         {
-            *error = const_cast<char *>(errorBuffer->c_str());
+            *error = *errorBuffer;
         }
 
+        xmlSetGenericErrorFunc(ctxt, 0);
         xmlFreeParserCtxt(ctxt);
 
         return doc;
     }
 
-    xmlParserCtxt * XMLDocument::initContext(char ** error, bool validate)
+    xmlParserCtxt * XMLDocument::initContext(std::string * error, bool validate)
     {
         xmlParserCtxt * ctxt;
 
@@ -327,13 +333,14 @@ namespace org_modules_xml
         ctxt = xmlNewParserCtxt();
         if (!ctxt)
         {
-            *error = const_cast<char *>("Cannot create a parser context");
+            errorBuffer->append(gettext("Cannot create a parser context"));
+            *error = *errorBuffer;
             return 0;
         }
 
         if (validate)
         {
-            ctxt->vctxt.error = (xmlValidityErrorFunc) errorFunction;
+            ctxt->vctxt.error = (xmlValidityErrorFunc)errorFunction;
         }
 
         xmlSetGenericErrorFunc(ctxt, XMLDocument::errorFunction);
index 5376268..f7b0a69 100644 (file)
@@ -32,6 +32,7 @@ namespace org_modules_xml
     class XMLElement;
     class XMLObject;
     class XMLXPath;
+    class XMLValidation;
 
     /**
      * @file
@@ -51,7 +52,7 @@ namespace org_modules_xml
          * Gets the list of open docs
          * @return the list
          */
-        static std::list<XMLDocument *> & getOpenDocuments();
+        static const std::list<XMLDocument *> & getOpenDocuments();
 
         /**
          * Closes all the open documents
@@ -64,7 +65,7 @@ namespace org_modules_xml
          * @param validate a boolean to indicate if the document must be validated in using a DTD
          * @param error a pointer to a string which will receive the error message
          */
-        XMLDocument(const char * path, bool validate, char ** error);
+        XMLDocument(const char * path, bool validate, std::string * error);
 
         /**
          * Builds a document with a given code
@@ -72,7 +73,7 @@ namespace org_modules_xml
          * @param validate a boolean to indicate if the document must be validated in using a DTD
          * @param error a pointer to a string which will receive the error message
          */
-        XMLDocument(const std::string & xmlCode, bool validate, char ** error);
+        XMLDocument(const std::string & xmlCode, bool validate, std::string * error);
 
         /**
          * Builds a simple document
@@ -103,7 +104,7 @@ namespace org_modules_xml
          * @param xmlCode the XML code
          * @param error a pointer to a string which will receive the error message
          */
-        void setRoot(const std::string & xmlCode, char ** error) const;
+        void setRoot(const std::string & xmlCode, std::string * error) const;
 
         /**
          * @return the document URL
@@ -123,7 +124,7 @@ namespace org_modules_xml
          * @param error a pointer to a string which will receive the error message
          * @return a pointer on a XPath object
          */
-        const XMLXPath * makeXPathQuery(const char * query, char ** namespaces, int length, char ** error);
+        const XMLXPath * makeXPathQuery(const char * query, char ** namespaces, int length, std::string * error);
 
         const XMLObject * getXMLObjectParent() const;
         const std::string dump() const;
@@ -150,7 +151,7 @@ namespace org_modules_xml
          * @param error a string where to write the parsing errors
          * @return a pointer on a xmlDoc
          */
-        static xmlDoc * readDocument(const char * filename, bool validate, char ** error);
+        static xmlDoc * readDocument(const char * filename, bool validate, std::string * error);
 
         /**
          * Read and parse a document given in a string.
@@ -159,7 +160,7 @@ namespace org_modules_xml
          * @param error a string where to write the parsing errors
          * @return a pointer on a xmlDoc
          */
-        static xmlDoc * readDocument(const std::string & xmlCode, bool validate, char ** error);
+        static xmlDoc * readDocument(const std::string & xmlCode, bool validate, std::string * error);
 
         /**
          * Initializes the context
@@ -167,7 +168,7 @@ namespace org_modules_xml
          * @param validate a boolean to indicate if the document must be validated in using a DTD
          * @return a pointer on a context
          */
-        static xmlParserCtxt * initContext(char ** error, bool validate);
+        static xmlParserCtxt * initContext(std::string * error, bool validate);
 
         static std::string * errorBuffer;
         static std::string * errorXPathBuffer;
index c2ade4d..ffcda42 100644 (file)
@@ -120,10 +120,10 @@ namespace org_modules_xml
 
     void XMLElement::setChildren(const std::string & xmlCode) const
     {
-        char * error = 0;
+       std::string error;
         XMLDocument document = XMLDocument(xmlCode, false, &error);
 
-        if (!error)
+        if (error.empty())
         {
             setChildren(*document.getRoot());
         }
index 474a7cd..2b10654 100644 (file)
@@ -143,10 +143,10 @@ namespace org_modules_xml
 
     void XMLNodeList::setElementAtPosition(double index, const std::string & xmlCode)
     {
-        char * error = 0;
+       std::string error;
         XMLDocument document = XMLDocument(xmlCode, false, &error);
 
-        if (!error)
+        if (error.empty())
         {
             setElementAtPosition(index, document);
         }
diff --git a/scilab/modules/xml/src/cpp/XMLValidation.cpp b/scilab/modules/xml/src/cpp/XMLValidation.cpp
new file mode 100644 (file)
index 0000000..4619f58
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#include "XMLObject.hxx"
+#include "XMLValidation.hxx"
+
+extern "C" {
+#include "expandPathVariable.h"
+#include "MALLOC.h"
+}
+
+#define BUFFER_SIZE 1024
+
+namespace org_modules_xml
+{
+
+    std::string * XMLValidation::errorBuffer = 0;
+    std::list<XMLValidation *> & XMLValidation::openValidationFiles = *new std::list<XMLValidation *>();
+
+    XMLValidation::XMLValidation() : XMLObject()
+    {
+        scilabType = XMLVALID;
+    }
+
+    void XMLValidation::errorFunction(void * ctx, const char * msg, ...)
+    {
+        char str[BUFFER_SIZE];
+        va_list args;
+
+        va_start(args, msg);
+        std::vsnprintf(str, BUFFER_SIZE, msg, args);
+        va_end(args);
+        errorBuffer->append(str);
+    }
+
+    bool XMLValidation::validate(const std::string & xmlCode, std::string * error) const
+    {
+        xmlParserInputBuffer * buffer = xmlParserInputBufferCreateMem(xmlCode.c_str(), xmlCode.size(), (xmlCharEncoding)0);
+        bool valid = validate(xmlNewTextReader(buffer, 0), error);
+        xmlFreeParserInputBuffer(buffer);
+
+        return valid;
+    }
+
+    bool XMLValidation::validate(const char * path, std::string * error) const
+    {
+        char * expandedPath = expandPathVariable(const_cast<char *>(path));
+        xmlTextReader * reader = xmlNewTextReaderFilename(expandedPath);
+        FREE(expandedPath);
+        return validate(reader, error);
+    }
+
+    const std::list<XMLValidation *> & XMLValidation::getOpenValidationFiles()
+    {
+        return openValidationFiles;
+    }
+
+    void XMLValidation::closeAllValidationFiles()
+    {
+        int size = (int)openValidationFiles.size();
+        XMLValidation ** arr = new XMLValidation*[size];
+        int j = 0;
+        for (std::list<XMLValidation *>::iterator i = openValidationFiles.begin(); i != openValidationFiles.end(); i++, j++)
+        {
+            arr[j] = *i;
+        }
+        for (j = 0; j < size; j++)
+        {
+            delete arr[j];
+        }
+        delete [] arr;
+    }
+}
diff --git a/scilab/modules/xml/src/cpp/XMLValidation.hxx b/scilab/modules/xml/src/cpp/XMLValidation.hxx
new file mode 100644 (file)
index 0000000..01b2e21
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#ifndef __XMLVALIDATION_HXX__
+#define __XMLVALIDATION_HXX__
+
+#include <cstdio>
+#include <list>
+#include <string>
+
+#include "xml.h"
+
+namespace org_modules_xml
+{
+    class XMLObject;
+    class XMLDocument;
+
+    /**
+     * @file
+     * @author Calixte DENIZET <calixte.denizet@scilab.org>
+     *
+     * Base class for the XML validation.
+     */
+    class XMLValidation : public XMLObject
+    {
+
+    public :
+
+        /**
+         * Retrieve all the open validation files
+         * @return a list containing the validation objects
+         */
+        static const std::list<XMLValidation *> & getOpenValidationFiles();
+
+        /**
+         * Close all the validation files
+         */
+        static void closeAllValidationFiles();
+
+        /**
+         * Default constructor
+         */
+        XMLValidation();
+
+        /**
+         * Validate an already parsed document
+         * @param doc the document to validate
+         * @param error a string which will contain error messages
+         */
+        virtual bool validate(const XMLDocument & doc, std::string * error) const = 0;
+
+        /**
+         * Validate a document accessed via a xmlTextReader
+         * @param reader the reader to use
+         * @param error a string which will contain error messages
+         */
+        virtual bool validate(xmlTextReader * reader, std::string * error) const = 0;
+
+        /**
+         * Validate a document with a given path
+         * @param path the document path
+         * @param error a string which will contain error messages
+         */
+        bool validate(const char * path, std::string * error) const;
+
+        /**
+         * Validate a document with a given content as string
+         * @param xmlCode the document code
+         * @param error a string which will contain error messages
+         */
+        bool validate(const std::string & xmlCode, std::string * error) const;
+
+        /**
+         * @return the validation file
+         */
+        template <typename T>
+        T * getValidationFile() const { return (T *)validationFile; }
+
+    protected :
+
+        static std::string * errorBuffer;
+        static std::list<XMLValidation *> & openValidationFiles;
+
+        /**
+         * Error function for the XML parser
+         * @see http://xmlsoft.org/html/libxml-xmlerror.html#xmlGenericErrorFunc
+         */
+        static void errorFunction(void * ctx, const char * msg, ...);
+
+        void * validationFile;
+    };
+}
+
+#endif
diff --git a/scilab/modules/xml/src/cpp/XMLValidationDTD.cpp b/scilab/modules/xml/src/cpp/XMLValidationDTD.cpp
new file mode 100644 (file)
index 0000000..811c529
--- /dev/null
@@ -0,0 +1,164 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#include "XMLObject.hxx"
+#include "XMLValidation.hxx"
+#include "XMLValidationDTD.hxx"
+#include "XMLDocument.hxx"
+#include "VariableScope.hxx"
+
+extern "C" {
+#include "expandPathVariable.h"
+#include "MALLOC.h"
+#include "localization.h"
+}
+
+namespace org_modules_xml
+{
+
+    XMLValidationDTD::XMLValidationDTD(const char * path, std::string * error) : XMLValidation()
+    {
+        internalValidate = false;
+        char * expandedPath = expandPathVariable(const_cast<char *>(path));
+        validationFile = (void *)xmlParseDTD(0, (const xmlChar *)expandedPath);
+        FREE(expandedPath);
+        if (!validationFile)
+        {
+            if (errorBuffer)
+            {
+                delete errorBuffer;
+            }
+            errorBuffer = new std::string(gettext("Cannot parse the DTD"));
+            *error = *errorBuffer;
+        }
+        else
+        {
+            openValidationFiles.push_back(this);
+        }
+        scope->registerPointers(validationFile, this);
+        id = scope->getVariableId(*this);
+    }
+
+    XMLValidationDTD::XMLValidationDTD(std::string * error) : XMLValidation()
+    {
+        validationFile = 0;
+        internalValidate = true;
+        id = scope->getVariableId(*this);
+        openValidationFiles.push_back(this);
+    }
+
+    XMLValidationDTD::~XMLValidationDTD()
+    {
+        scope->unregisterPointer(validationFile);
+        scope->removeId(id);
+
+        if (validationFile)
+        {
+            xmlFreeDtd(getValidationFile<xmlDtd>());
+        }
+
+        if (validationFile || internalValidate)
+        {
+            openValidationFiles.remove(this);
+            if (openValidationFiles.size() == 0 && XMLDocument::getOpenDocuments().size() == 0)
+            {
+                resetScope();
+            }
+        }
+
+        if (errorBuffer)
+        {
+            delete errorBuffer;
+            errorBuffer = 0;
+        }
+    }
+
+    bool XMLValidationDTD::validate(const XMLDocument & doc, std::string * error) const
+    {
+        bool ret;
+        xmlValidCtxt * vctxt = xmlNewValidCtxt();
+
+        if (errorBuffer)
+        {
+            delete errorBuffer;
+        }
+        errorBuffer = new std::string("");
+
+        if (!vctxt)
+        {
+            errorBuffer->append(gettext("Cannot create a valid context"));
+            *error = *errorBuffer;
+            return false;
+        }
+
+        vctxt->error = (xmlValidityErrorFunc)XMLValidation::errorFunction;
+
+        ret = xmlValidateDtd(vctxt, doc.getRealDocument(), getValidationFile<xmlDtd>()) == 1;
+
+        vctxt->error = 0;
+        xmlFreeValidCtxt(vctxt);
+
+        if (!ret)
+        {
+            *error = *errorBuffer;
+        }
+
+        return ret;
+    }
+
+    bool XMLValidationDTD::validate(xmlTextReader * reader, std::string * error) const
+    {
+        int last;
+        int valid;
+
+        if (errorBuffer)
+        {
+            delete errorBuffer;
+        }
+        errorBuffer = new std::string("");
+
+        if (!internalValidate)
+        {
+            errorBuffer->append(gettext("Due to a libxml2 limitation, it is not possible to validate a document against an external DTD\nPlease see help xmlValidate.\n"));
+            *error = *errorBuffer;
+            return false;
+        }
+
+        xmlTextReaderSetParserProp(reader, XML_PARSER_VALIDATE, 1);
+        xmlTextReaderSetErrorHandler(reader, (xmlTextReaderErrorFunc)XMLValidation::errorFunction, 0);
+        while ((last = xmlTextReaderRead(reader)) == 1);
+        valid = xmlTextReaderIsValid(reader);
+
+        xmlTextReaderSetErrorHandler(reader, 0, 0);
+        xmlFreeTextReader(reader);
+
+        if (last == -1 || valid != 1)
+        {
+            *error = *errorBuffer;
+            return false;
+        }
+
+        return true;
+    }
+
+    const std::string XMLValidationDTD::toString() const
+    {
+        xmlDtd * dtd = getValidationFile<xmlDtd>();
+
+        std::string str = "XML DTD\n";
+        str += "name: " + std::string(dtd->name ? (const char *)dtd->name : "") + "\n";
+        str += "external ID: " + std::string(dtd->ExternalID ? (const char *)dtd->ExternalID : "") + "\n";
+        str += "system ID: " + std::string(dtd->SystemID ? (const char *)dtd->SystemID : "");
+
+        return str;
+    }
+}
diff --git a/scilab/modules/xml/src/cpp/XMLValidationDTD.hxx b/scilab/modules/xml/src/cpp/XMLValidationDTD.hxx
new file mode 100644 (file)
index 0000000..36f5e92
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#ifndef __XMLVALIDATIONDTD_HXX__
+#define __XMLVALIDATIONDTD_HXX__
+
+#include <string>
+
+#include "xml.h"
+
+namespace org_modules_xml
+{
+
+    class XMLValidation;
+    class XMLDocument;
+
+    /**
+     * @file
+     * @author Calixte DENIZET <calixte.denizet@scilab.org>
+     *
+     * Class to handle DTD validation.
+     */
+    class XMLValidationDTD : public XMLValidation
+    {
+
+    public :
+
+        /**
+         * @param path the path of the validation file
+         * @param error a string which will contain error messages
+         */
+        XMLValidationDTD(const char * path, std::string * error);
+
+        /**
+         * @param error a string which will contain error messages
+         */
+        XMLValidationDTD(std::string * error);
+
+        ~XMLValidationDTD();
+
+        bool validate(const XMLDocument & doc, std::string * error) const;
+        bool validate(xmlTextReader * reader, std::string * error) const;
+
+        const std::string toString() const;
+
+    private :
+        bool internalValidate;
+    };
+}
+
+#endif
diff --git a/scilab/modules/xml/src/cpp/XMLValidationRelaxNG.cpp b/scilab/modules/xml/src/cpp/XMLValidationRelaxNG.cpp
new file mode 100644 (file)
index 0000000..980d3ed
--- /dev/null
@@ -0,0 +1,154 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#include "XMLObject.hxx"
+#include "XMLValidation.hxx"
+#include "XMLValidationRelaxNG.hxx"
+#include "XMLDocument.hxx"
+#include "VariableScope.hxx"
+
+extern "C" {
+#include "expandPathVariable.h"
+#include "MALLOC.h"
+#include "localization.h"
+}
+
+namespace org_modules_xml
+{
+
+    XMLValidationRelaxNG::XMLValidationRelaxNG(const char * path, std::string * error) : XMLValidation()
+    {
+        char * expandedPath = expandPathVariable(const_cast<char *>(path));
+        xmlRelaxNGParserCtxt * pctxt = xmlRelaxNGNewParserCtxt(expandedPath);
+        FREE(expandedPath);
+        if (!pctxt)
+        {
+            if (errorBuffer)
+            {
+                delete errorBuffer;
+            }
+            errorBuffer = new std::string(gettext("Cannot create a validation context"));
+            *error = *errorBuffer;
+        }
+        else
+        {
+            validationFile = (void *)xmlRelaxNGParse(pctxt);
+            xmlRelaxNGFreeParserCtxt(pctxt);
+            if (!validationFile)
+            {
+                if (errorBuffer)
+                {
+                    delete errorBuffer;
+                }
+                errorBuffer = new std::string(gettext("Cannot parse the Relax NG grammar"));
+                *error = *errorBuffer;
+            }
+            else
+            {
+                openValidationFiles.push_back(this);
+            }
+        }
+        scope->registerPointers(validationFile, this);
+        id = scope->getVariableId(*this);
+    }
+
+    XMLValidationRelaxNG::~XMLValidationRelaxNG()
+    {
+        scope->unregisterPointer(validationFile);
+        scope->removeId(id);
+        if (validationFile)
+        {
+            xmlRelaxNGFree((xmlRelaxNG *)validationFile);
+            openValidationFiles.remove(this);
+            if (openValidationFiles.size() == 0 && XMLDocument::getOpenDocuments().size() == 0)
+            {
+                resetScope();
+            }
+        }
+
+        if (errorBuffer)
+        {
+            delete errorBuffer;
+            errorBuffer = 0;
+        }
+    }
+
+    bool XMLValidationRelaxNG::validate(const XMLDocument & doc, std::string * error) const
+    {
+        bool ret;
+        xmlRelaxNGValidCtxt * vctxt = xmlRelaxNGNewValidCtxt((xmlRelaxNG *)validationFile);
+
+        if (errorBuffer)
+        {
+            delete errorBuffer;
+        }
+        errorBuffer = new std::string("");
+
+        if (!vctxt)
+        {
+            errorBuffer->append(gettext("Cannot create a validation context"));
+            *error = *errorBuffer;
+            return false;
+        }
+
+        xmlRelaxNGSetValidErrors(vctxt, (xmlRelaxNGValidityErrorFunc)XMLValidation::errorFunction, 0, 0);
+
+        ret = xmlRelaxNGValidateDoc(vctxt, doc.getRealDocument());
+
+        xmlRelaxNGSetValidErrors(vctxt, 0, 0, 0);
+        xmlRelaxNGFreeValidCtxt(vctxt);
+
+        if (ret)
+        {
+            *error = *errorBuffer;
+        }
+
+        return ret == 0;
+    }
+
+    bool XMLValidationRelaxNG::validate(xmlTextReader * reader, std::string * error) const
+    {
+        int last;
+        int valid;
+
+        if (errorBuffer)
+        {
+            delete errorBuffer;
+        }
+        errorBuffer = new std::string();
+
+        xmlTextReaderSetErrorHandler(reader, (xmlTextReaderErrorFunc)XMLValidation::errorFunction, 0);
+        xmlTextReaderRelaxNGSetSchema(reader, getValidationFile<xmlRelaxNG>());
+
+        while ((last = xmlTextReaderRead(reader)) == 1);
+        valid = xmlTextReaderIsValid(reader);
+
+        xmlTextReaderSetErrorHandler(reader, 0, 0);
+        xmlFreeTextReader(reader);
+
+        if (last == -1 || valid != 1)
+        {
+            *error = *errorBuffer;
+            return false;
+        }
+
+        return true;
+    }
+
+    const std::string XMLValidationRelaxNG::toString() const
+    {
+        std::string str = "XML Relax NG\n";
+        str += "No public informations";
+
+        return str;
+    }
+}
diff --git a/scilab/modules/xml/src/cpp/XMLValidationRelaxNG.hxx b/scilab/modules/xml/src/cpp/XMLValidationRelaxNG.hxx
new file mode 100644 (file)
index 0000000..8233ac2
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#ifndef __XMLVALIDATIONRELAXNG_HXX__
+#define __XMLVALIDATIONRELAXNG_HXX__
+
+#include <string>
+
+#include "xml.h"
+
+namespace org_modules_xml
+{
+
+    class XMLValidation;
+    class XMLDocument;
+
+    /**
+     * @file
+     * @author Calixte DENIZET <calixte.denizet@scilab.org>
+     *
+     * Class to handle Relax NG validation.
+     */
+    class XMLValidationRelaxNG : public XMLValidation
+    {
+
+    public :
+
+        /**
+         * @param path the path of the validation file
+         * @param error a string which will contain error messages
+         */
+        XMLValidationRelaxNG(const char * path, std::string * error);
+
+        ~XMLValidationRelaxNG();
+
+        bool validate(const XMLDocument & doc, std::string * error) const;
+        bool validate(xmlTextReader * reader, std::string * error) const;
+
+        const std::string toString() const;
+    };
+}
+
+#endif
diff --git a/scilab/modules/xml/src/cpp/XMLValidationSchema.cpp b/scilab/modules/xml/src/cpp/XMLValidationSchema.cpp
new file mode 100644 (file)
index 0000000..27d484d
--- /dev/null
@@ -0,0 +1,178 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#include "XMLObject.hxx"
+#include "XMLValidation.hxx"
+#include "XMLValidationSchema.hxx"
+#include "XMLDocument.hxx"
+#include "VariableScope.hxx"
+
+extern "C" {
+#include "expandPathVariable.h"
+#include "MALLOC.h"
+#include "localization.h"
+}
+
+namespace org_modules_xml
+{
+
+    XMLValidationSchema::XMLValidationSchema(const char * path, std::string * error) : XMLValidation()
+    {
+        char * expandedPath = expandPathVariable(const_cast<char *>(path));
+        xmlSchemaParserCtxt * pctxt = xmlSchemaNewParserCtxt(expandedPath);
+        FREE(expandedPath);
+        if (!pctxt)
+        {
+            if (errorBuffer)
+            {
+                delete errorBuffer;
+            }
+            errorBuffer = new std::string(gettext("Cannot create a validation context"));
+            *error = *errorBuffer;
+        }
+        else
+        {
+            validationFile = (void *)xmlSchemaParse(pctxt);
+            xmlSchemaFreeParserCtxt(pctxt);
+            if (!validationFile)
+            {
+                if (errorBuffer)
+                {
+                    delete errorBuffer;
+                }
+                errorBuffer = new std::string(gettext("Cannot parse the schema"));
+                *error = *errorBuffer;
+            }
+            else
+            {
+                openValidationFiles.push_back(this);
+            }
+        }
+        scope->registerPointers(validationFile, this);
+        id = scope->getVariableId(*this);
+    }
+
+    XMLValidationSchema::~XMLValidationSchema()
+    {
+        scope->unregisterPointer(validationFile);
+        scope->removeId(id);
+        if (validationFile)
+        {
+            xmlSchemaFree((xmlSchema *)validationFile);
+            openValidationFiles.remove(this);
+            if (openValidationFiles.size() == 0 && XMLDocument::getOpenDocuments().size() == 0)
+            {
+                resetScope();
+            }
+        }
+
+        if (errorBuffer)
+        {
+            delete errorBuffer;
+            errorBuffer = 0;
+        }
+    }
+
+    bool XMLValidationSchema::validate(const XMLDocument & doc, std::string * error) const
+    {
+        bool ret;
+        xmlSchemaValidCtxt * vctxt = xmlSchemaNewValidCtxt((xmlSchema *)validationFile);
+
+        if (errorBuffer)
+        {
+            delete errorBuffer;
+        }
+        errorBuffer = new std::string("");
+
+        if (!vctxt)
+        {
+            errorBuffer->append(gettext("Cannot create a validation context"));
+            *error = *errorBuffer;
+            return false;
+        }
+
+        xmlSchemaSetValidErrors(vctxt, (xmlSchemaValidityErrorFunc)XMLValidation::errorFunction, 0, 0);
+
+        ret = xmlSchemaValidateDoc(vctxt, doc.getRealDocument());
+
+        xmlSchemaSetValidErrors(vctxt, 0, 0, 0);
+        xmlSchemaFreeValidCtxt(vctxt);
+
+        if (ret)
+        {
+            *error = *errorBuffer;
+        }
+
+        return ret == 0;
+    }
+
+    bool XMLValidationSchema::validate(xmlTextReader * reader, std::string * error) const
+    {
+        xmlSchemaValidCtxt * vctxt = 0;
+        int last;
+        int valid;
+
+        if (errorBuffer)
+        {
+            delete errorBuffer;
+        }
+        errorBuffer = new std::string();
+
+        if (!reader)
+        {
+            errorBuffer->append(gettext("Cannot read the stream"));
+            *error = *errorBuffer;
+            return false;
+        }
+
+        vctxt = xmlSchemaNewValidCtxt(getValidationFile<xmlSchema>());
+        if (!vctxt)
+        {
+            errorBuffer->append(gettext("Cannot create a validation context"));
+            *error = *errorBuffer;
+            return false;
+        }
+
+        xmlSchemaSetValidErrors(vctxt, (xmlSchemaValidityErrorFunc)XMLValidation::errorFunction, 0, 0);
+        xmlTextReaderSetErrorHandler(reader, (xmlTextReaderErrorFunc)XMLValidation::errorFunction, 0);
+        xmlTextReaderSchemaValidateCtxt(reader, vctxt, 0);
+
+        while ((last = xmlTextReaderRead(reader)) == 1);
+        valid = xmlTextReaderIsValid(reader);
+
+        xmlTextReaderSetErrorHandler(reader, 0, 0);
+        xmlSchemaSetValidErrors(vctxt, 0, 0, 0);
+        xmlFreeTextReader(reader);
+        xmlSchemaFreeValidCtxt(vctxt);
+
+        if (last == -1 || valid != 1)
+        {
+            *error = *errorBuffer;
+            return false;
+        }
+
+        return true;
+    }
+
+    const std::string XMLValidationSchema::toString() const
+    {
+        xmlSchema * schema = getValidationFile<xmlSchema>();
+
+        std::string str = "XML Schema\n";
+        str += "name: " + std::string(schema->name ? (const char *)schema->name : "") + "\n";
+        str += "target namespace: " + std::string(schema->targetNamespace ? (const char *)schema->targetNamespace : "") + "\n";
+        str += "version: " + std::string(schema->version ? (const char *)schema->version : "");
+
+        return str;
+    }
+
+}
diff --git a/scilab/modules/xml/src/cpp/XMLValidationSchema.hxx b/scilab/modules/xml/src/cpp/XMLValidationSchema.hxx
new file mode 100644 (file)
index 0000000..9f56b87
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#ifndef __XMLVALIDATIONSCHEMA_HXX__
+#define __XMLVALIDATIONSCHEMA_HXX__
+
+#include <string>
+
+#include "xml.h"
+
+namespace org_modules_xml
+{
+
+    class XMLValidation;
+    class XMLDocument;
+
+    /**
+     * @file
+     * @author Calixte DENIZET <calixte.denizet@scilab.org>
+     *
+     * Class to handle Schema validation.
+     */
+    class XMLValidationSchema : public XMLValidation
+    {
+
+    public :
+
+        /**
+         * @param path the path of the validation file
+         * @param error a string which will contain error messages
+         */
+        XMLValidationSchema(const char * path, std::string * error);
+
+        ~XMLValidationSchema();
+
+        bool validate(const XMLDocument & doc, std::string * error) const;
+        bool validate(xmlTextReader * reader, std::string * error) const;
+
+        const std::string toString() const;
+    };
+}
+
+#endif
index 96696a3..9ed65a4 100644 (file)
@@ -60,9 +60,9 @@ bool setProperty(char * fname, org_modules_xml::XMLDocument & doc, const char *
         }
         else
         {
-            char * error = 0;
+            std::string error;
             doc.setRoot((std::string &)value, &error);
-            if (error)
+            if (!error.empty())
             {
                 Scierror(999, gettext("%s: Not valid xml for root.\n"), fname);
                 return false;
diff --git a/scilab/modules/xml/tests/unit_tests/invalid_library.xml b/scilab/modules/xml/tests/unit_tests/invalid_library.xml
new file mode 100644 (file)
index 0000000..85b91a8
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE library SYSTEM "library.dtd">
+<library>
+    <book title="Ulysses">
+        <author>James Joyce</author>
+        <hero>Leopold Bloom</hero>
+    </book>
+    <book title="Don Quichotte">
+        <author>Miguel de Cervantes</author>
+        <hero>Don Quichotte de la Mancha</hero>
+    </book><a/>
+</library>
\ No newline at end of file
diff --git a/scilab/modules/xml/tests/unit_tests/library.dtd b/scilab/modules/xml/tests/unit_tests/library.dtd
new file mode 100644 (file)
index 0000000..511a211
--- /dev/null
@@ -0,0 +1,5 @@
+<!ELEMENT library (book)+>
+<!ELEMENT book (author,hero)>
+<!ATTLIST book title CDATA #REQUIRED>
+<!ELEMENT author (#PCDATA)>
+<!ELEMENT hero (#PCDATA)>
diff --git a/scilab/modules/xml/tests/unit_tests/library.rng b/scilab/modules/xml/tests/unit_tests/library.rng
new file mode 100644 (file)
index 0000000..1306f16
--- /dev/null
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
+    <start>
+        <ref name="library"/>
+    </start>
+    <define name="library">
+        <element name="library">
+            <zeroOrMore>
+                <ref name="book"/>
+            </zeroOrMore>
+        </element>
+    </define>
+    <define name="book">
+        <element name="book">
+            <attribute name="title">
+                <text/>
+            </attribute>
+            <interleave>
+                <ref name="author"/>
+                <ref name="hero"/>
+            </interleave>
+        </element>
+    </define>
+    <define name="author">
+        <element name="author">
+            <text/>
+        </element>
+    </define>
+    <define name="hero">
+        <element name="hero">
+            <text/>
+        </element>
+    </define>
+</grammar>
\ No newline at end of file
diff --git a/scilab/modules/xml/tests/unit_tests/library.xml b/scilab/modules/xml/tests/unit_tests/library.xml
new file mode 100644 (file)
index 0000000..5fd9814
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE library SYSTEM "library.dtd">
+<library>
+    <book title="Ulysses">
+        <author>James Joyce</author>
+        <hero>Leopold Bloom</hero>
+    </book>
+    <book title="Don Quichotte">
+        <author>Miguel de Cervantes</author>
+        <hero>Don Quichotte de la Mancha</hero>
+    </book>
+</library>
\ No newline at end of file
diff --git a/scilab/modules/xml/tests/unit_tests/library.xsd b/scilab/modules/xml/tests/unit_tests/library.xsd
new file mode 100644 (file)
index 0000000..8f94076
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
+    <xs:element name="library" type="TypeLibrary"/>
+    <xs:complexType name="TypeLibrary">
+        <xs:sequence maxOccurs="unbounded" minOccurs="1">
+            <xs:element name="book" type="TypeBook"/>
+        </xs:sequence>
+    </xs:complexType>
+    <xs:complexType name="TypeBook">
+        <xs:sequence>
+            <xs:element name="author" type="xs:string"/>
+            <xs:element name="hero" type="xs:string"/>
+        </xs:sequence>
+        <xs:attribute name="title" type="xs:string" use="required"/>
+    </xs:complexType>
+</xs:schema>
\ No newline at end of file
diff --git a/scilab/modules/xml/tests/unit_tests/xmlValidate.dia.ref b/scilab/modules/xml/tests/unit_tests/xmlValidate.dia.ref
new file mode 100644 (file)
index 0000000..8dab3d0
--- /dev/null
@@ -0,0 +1,24 @@
+// ===========================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU
+//
+//  This file is distributed under the same license as the Scilab package.
+// ===========================================================================
+doc = xmlRead("SCI/modules/xml/tests/unit_tests/library.xml");
+dtd = xmlDTD("SCI/modules/xml/tests/unit_tests/library.dtd");
+schema = xmlSchema("SCI/modules/xml/tests/unit_tests/library.xsd");
+rng = xmlRelaxNG("SCI/modules/xml/tests/unit_tests/library.rng");
+assert_checkequal(doc.root.children.size,2);
+xmlValidate(doc, dtd);
+xmlValidate(doc, rng);
+xmlValidate(doc, schema);
+xmlValidate("SCI/modules/xml/tests/unit_tests/library.xml")
+//xmlValidate("SCI/modules/xml/tests/unit_tests/invalid_library.xml")
+xmlValidate("SCI/modules/xml/tests/unit_tests/library.xml", schema)
+//xmlValidate("SCI/modules/xml/tests/unit_tests/invalid_library.xml", rng)
+// Commented because I don't know how to check that now
+//doc.root.children(3) = "<a>error</a>"
+xmlValidate(doc, dtd);
+xmlValidate(doc, rng);
+xmlValidate(doc, schema);
+xmlClose(doc, dtd, schema, rng);
diff --git a/scilab/modules/xml/tests/unit_tests/xmlValidate.tst b/scilab/modules/xml/tests/unit_tests/xmlValidate.tst
new file mode 100644 (file)
index 0000000..6701f56
--- /dev/null
@@ -0,0 +1,33 @@
+// ===========================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU
+//
+//  This file is distributed under the same license as the Scilab package.
+// ===========================================================================
+
+doc = xmlRead("SCI/modules/xml/tests/unit_tests/library.xml");
+dtd = xmlDTD("SCI/modules/xml/tests/unit_tests/library.dtd");
+schema = xmlSchema("SCI/modules/xml/tests/unit_tests/library.xsd");
+rng = xmlRelaxNG("SCI/modules/xml/tests/unit_tests/library.rng");
+assert_checkequal(doc.root.children.size,2);
+xmlValidate(doc, dtd);
+
+xmlValidate(doc, rng);
+
+xmlValidate(doc, schema);
+
+xmlValidate("SCI/modules/xml/tests/unit_tests/library.xml")
+//xmlValidate("SCI/modules/xml/tests/unit_tests/invalid_library.xml")
+
+xmlValidate("SCI/modules/xml/tests/unit_tests/library.xml", schema)
+//xmlValidate("SCI/modules/xml/tests/unit_tests/invalid_library.xml", rng)
+
+// Commented because I don't know how to check that now
+//doc.root.children(3) = "<a>error</a>"
+
+xmlValidate(doc, dtd);
+xmlValidate(doc, rng);
+xmlValidate(doc, schema);
+
+
+xmlClose(doc, dtd, schema, rng);
\ No newline at end of file