XML: Add two functions to convert the result of a XPath query into a row of doubles... 67/5367/7
Calixte DENIZET [Tue, 8 Nov 2011 10:57:37 +0000 (11:57 +0100)]
Change-Id: I3bbaadbdaaea4bc1cd9a61727efeba94720d08a7

39 files changed:
scilab/modules/string/Makefile.am
scilab/modules/string/Makefile.in
scilab/modules/string/includes/stringToDouble.h [new file with mode: 0644]
scilab/modules/string/src/c/string.vcxproj
scilab/modules/string/src/c/string.vcxproj.filters
scilab/modules/string/src/c/stringToDouble.c [new file with mode: 0644]
scilab/modules/xml/Makefile.am
scilab/modules/xml/Makefile.in
scilab/modules/xml/help/en_US/xmlAsNumber.xml [new file with mode: 0644]
scilab/modules/xml/help/en_US/xmlAsText.xml [new file with mode: 0644]
scilab/modules/xml/help/en_US/xmlXPath.xml
scilab/modules/xml/includes/gw_xml.h
scilab/modules/xml/sci_gateway/c/gw_xml.c
scilab/modules/xml/sci_gateway/cpp/sci_xmlAsNumber.cpp [new file with mode: 0644]
scilab/modules/xml/sci_gateway/cpp/sci_xmlAsText.cpp [new file with mode: 0644]
scilab/modules/xml/sci_gateway/xml_gateway.xml
scilab/modules/xml/src/cpp/XMLAttr.cpp
scilab/modules/xml/src/cpp/XMLAttr.hxx
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/XMLElement.hxx
scilab/modules/xml/src/cpp/XMLNodeList.cpp
scilab/modules/xml/src/cpp/XMLNodeList.hxx
scilab/modules/xml/src/cpp/XMLNodeSet.cpp
scilab/modules/xml/src/cpp/XMLNodeSet.hxx
scilab/modules/xml/src/cpp/XMLNotHandledElement.cpp
scilab/modules/xml/src/cpp/XMLNotHandledElement.hxx
scilab/modules/xml/src/cpp/XMLNs.cpp
scilab/modules/xml/src/cpp/XMLNs.hxx
scilab/modules/xml/src/cpp/XMLObject.hxx
scilab/modules/xml/src/cpp/XMLXPath.cpp
scilab/modules/xml/src/cpp/XMLXPath.hxx
scilab/modules/xml/tests/unit_tests/xmlAsNumber.dia.ref [new file with mode: 0644]
scilab/modules/xml/tests/unit_tests/xmlAsNumber.tst [new file with mode: 0644]
scilab/modules/xml/tests/unit_tests/xmlAsText.dia.ref [new file with mode: 0644]
scilab/modules/xml/tests/unit_tests/xmlAsText.tst [new file with mode: 0644]
scilab/modules/xml/xml.vcxproj
scilab/modules/xml/xml.vcxproj.filters

index d5ac8de..0646eaf 100644 (file)
@@ -25,7 +25,8 @@ src/c/stringsstrrev.c \
 src/c/stringsCompare.c \
 src/c/isalphanum.c \
 src/c/StringConvert.c \
-src/c/scistrtostr.c
+src/c/scistrtostr.c \
+src/c/stringToDouble.c
 
 STRING_FORTRAN_SOURCES =
 
index a8f4d4e..454d307 100644 (file)
@@ -132,7 +132,8 @@ am__objects_1 = libscistring_algo_la-code2str.lo \
        libscistring_algo_la-stringsCompare.lo \
        libscistring_algo_la-isalphanum.lo \
        libscistring_algo_la-StringConvert.lo \
-       libscistring_algo_la-scistrtostr.lo
+       libscistring_algo_la-scistrtostr.lo \
+       libscistring_algo_la-stringToDouble.lo
 am__objects_2 =
 am_libscistring_algo_la_OBJECTS = $(am__objects_1) $(am__objects_2)
 libscistring_algo_la_OBJECTS = $(am_libscistring_algo_la_OBJECTS)
@@ -463,7 +464,8 @@ src/c/stringsstrrev.c \
 src/c/stringsCompare.c \
 src/c/isalphanum.c \
 src/c/StringConvert.c \
-src/c/scistrtostr.c
+src/c/scistrtostr.c \
+src/c/stringToDouble.c
 
 STRING_FORTRAN_SOURCES = 
 GATEWAY_C_SOURCES = sci_gateway/c/gw_string.c \
@@ -701,6 +703,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscistring_algo_la-scistrtostr.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscistring_algo_la-setScilabCharactersCodes.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscistring_algo_la-strcatfunction.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscistring_algo_la-stringToDouble.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscistring_algo_la-stringsCompare.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscistring_algo_la-stringsstrrchr.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscistring_algo_la-stringsstrrev.Plo@am__quote@
@@ -921,6 +924,13 @@ libscistring_algo_la-scistrtostr.lo: src/c/scistrtostr.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libscistring_algo_la_CFLAGS) $(CFLAGS) -c -o libscistring_algo_la-scistrtostr.lo `test -f 'src/c/scistrtostr.c' || echo '$(srcdir)/'`src/c/scistrtostr.c
 
+libscistring_algo_la-stringToDouble.lo: src/c/stringToDouble.c
+@am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libscistring_algo_la_CFLAGS) $(CFLAGS) -MT libscistring_algo_la-stringToDouble.lo -MD -MP -MF $(DEPDIR)/libscistring_algo_la-stringToDouble.Tpo -c -o libscistring_algo_la-stringToDouble.lo `test -f 'src/c/stringToDouble.c' || echo '$(srcdir)/'`src/c/stringToDouble.c
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscistring_algo_la-stringToDouble.Tpo $(DEPDIR)/libscistring_algo_la-stringToDouble.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='src/c/stringToDouble.c' object='libscistring_algo_la-stringToDouble.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libscistring_algo_la_CFLAGS) $(CFLAGS) -c -o libscistring_algo_la-stringToDouble.lo `test -f 'src/c/stringToDouble.c' || echo '$(srcdir)/'`src/c/stringToDouble.c
+
 libscistring_la-gw_string.lo: sci_gateway/c/gw_string.c
 @am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libscistring_la_CFLAGS) $(CFLAGS) -MT libscistring_la-gw_string.lo -MD -MP -MF $(DEPDIR)/libscistring_la-gw_string.Tpo -c -o libscistring_la-gw_string.lo `test -f 'sci_gateway/c/gw_string.c' || echo '$(srcdir)/'`sci_gateway/c/gw_string.c
 @am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscistring_la-gw_string.Tpo $(DEPDIR)/libscistring_la-gw_string.Plo
diff --git a/scilab/modules/string/includes/stringToDouble.h b/scilab/modules/string/includes/stringToDouble.h
new file mode 100644 (file)
index 0000000..4352d98
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ *  Copyright (C) 2010-2011 - DIGITEO - Allan CORNET
+ *
+ *  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 __STRINGTODOUBLE_H__
+#define __STRINGTODOUBLE_H__
+
+#include "BOOL.h"
+#include "dynlib_string.h"
+
+#define NanString "Nan"
+#define InfString "Inf"
+#define NegInfString "-Inf"
+#define PosInfString "+Inf"
+#define NegNanString "-Nan" /* no sense but used by some users */
+#define PosNanString "+Nan" /* no sense but used by some users */
+
+typedef enum {
+    STRINGTODOUBLE_NO_ERROR = 0,
+    STRINGTODOUBLE_MEMORY_ALLOCATION = 1,
+    STRINGTODOUBLE_NOT_A_NUMBER = 2,
+    STRINGTODOUBLE_ERROR = 3
+} stringToDoubleError;
+
+STRING_IMPEXP double stringToDouble(const char *pSTR,
+                       BOOL bConvertByNAN,
+                       stringToDoubleError *ierr);
+
+#endif /* __STRINGTODOUBLE_H__ */
+/* ========================================================================== */
index ca6e653..dd2339a 100644 (file)
@@ -258,12 +258,14 @@ lib /DEF:"$(ProjectDir)functions_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platf
     <ClCompile Include="stringsCompare.c" />
     <ClCompile Include="stringsstrrchr.c" />
     <ClCompile Include="stringsstrrev.c" />
+    <ClCompile Include="stringToDouble.c" />
     <ClCompile Include="stripblanks.c" />
     <ClCompile Include="strsplitfunction.c" />
     <ClCompile Include="strsubst.c" />
     <ClCompile Include="tokens.c" />
   </ItemGroup>
   <ItemGroup>
+    <ClInclude Include="..\..\includes\stringToDouble.h" />
     <ClInclude Include="convstr.h" />
     <ClInclude Include="CreateEmptystr.h" />
     <ClInclude Include="..\..\includes\cvstr.h" />
index b49f56b..c2f673d 100644 (file)
     <ClCompile Include="tokens.c">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="stringToDouble.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="convstr.h">
     <ClInclude Include="tokens.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\includes\stringToDouble.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\locales\en_US\string.pot">
diff --git a/scilab/modules/string/src/c/stringToDouble.c b/scilab/modules/string/src/c/stringToDouble.c
new file mode 100644 (file)
index 0000000..9f11a53
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+*  Copyright (C) 2010-2011 - DIGITEO - Allan CORNET
+*
+*  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 <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include "stringToDouble.h"
+#include "MALLOC.h"
+#ifdef  _MSC_VER
+#include "strdup_windows.h"
+#endif
+/* ========================================================================== */
+#ifndef _MSC_VER
+#ifndef stricmp
+#define stricmp strcasecmp
+#endif
+#else
+#define stricmp _stricmp
+#endif
+/* ========================================================================== */
+#define DEFAULT_DOUBLE_MAX_DIGIT_FORMAT "%lg"
+/* ========================================================================== */
+static double returnINF(BOOL bPositive);
+static double returnNAN(void);
+/* ========================================================================== */
+double stringToDouble(const char *pSTR,
+    BOOL bConvertByNAN,
+    stringToDoubleError *ierr)
+{
+    double dValue = 0.0;
+    *ierr = STRINGTODOUBLE_ERROR;
+    if (pSTR)
+    {
+        if ((stricmp(pSTR, NanString) == 0) || (stricmp(pSTR, NegNanString) == 0) ||
+            (stricmp(pSTR, PosNanString) == 0))
+        {
+            dValue = returnNAN();
+        }
+        else if ((stricmp(pSTR, InfString) == 0) || (stricmp(pSTR, PosInfString) == 0))
+        {
+            dValue = returnINF(TRUE);
+        }
+        else if (stricmp(pSTR, NegInfString) == 0)
+        {
+            dValue = returnINF(FALSE);
+        }
+        else
+        {
+            double v = 0.;
+
+            int err = sscanf(pSTR, DEFAULT_DOUBLE_MAX_DIGIT_FORMAT, &v);
+
+            if (err == 1)
+            {
+                double v2 = 0.;
+                char * pEnd = NULL;
+                v2 = strtod(pSTR, &pEnd);
+                if (strcmp(pEnd, "") == 0)
+                {
+                    dValue = v2;
+                }
+                else
+                {
+                    if (bConvertByNAN)
+                    {
+                        dValue = returnNAN();
+                    }
+                    else
+                    {
+                        *ierr = STRINGTODOUBLE_NOT_A_NUMBER;
+                        return (dValue = 0.0);
+                    }
+                }
+            }
+            else
+            {
+                if (bConvertByNAN)
+                {
+                    dValue = returnNAN();
+                }
+                else
+                {
+                    *ierr = STRINGTODOUBLE_NOT_A_NUMBER;
+                    return (dValue = 0.0);
+                }
+            }
+        }
+        *ierr = STRINGTODOUBLE_NO_ERROR;
+    }
+    else
+    {
+        *ierr = STRINGTODOUBLE_MEMORY_ALLOCATION;
+    }
+    return dValue;
+}
+/* ========================================================================== */
+static double returnNAN(void)
+{
+    static int first = 1;
+    static double nan = 1.0;
+
+    if ( first )
+    {
+        nan = (nan - (double) first)/(nan - (double) first);
+        first = 0;
+    }
+    return (nan);
+}
+/* ========================================================================== */
+static double returnINF(BOOL bPositive)
+{
+    double v = 0 - 0;
+    double p = 10;
+    if (!bPositive) p = -10;
+    return (double) p / (double)v;
+}
+/* ========================================================================== */
index abeb981..e9ef2b1 100644 (file)
@@ -76,13 +76,16 @@ GATEWAY_CPP_SOURCES = sci_gateway/cpp/sci_xmlRead.cpp \
                      sci_gateway/cpp/sci_percent_foo_i_XMLList.cpp \
                      sci_gateway/cpp/sci_xmlValidationFile.cpp \
                      sci_gateway/cpp/sci_xmlValidate.cpp \
-                     sci_gateway/cpp/sci_xmlIsValidObject.cpp
+                     sci_gateway/cpp/sci_xmlIsValidObject.cpp \
+                     sci_gateway/cpp/sci_xmlAsNumber.cpp \
+                     sci_gateway/cpp/sci_xmlAsText.cpp
 
 libscixml_la_CFLAGS= -I$(srcdir)/includes/ \
                     -I$(top_srcdir)/libs/MALLOC/includes/ \
                      -I$(top_srcdir)/modules/core/includes \
                     -I$(top_srcdir)/modules/api_scilab/includes \
                     -I$(top_srcdir)/modules/output_stream/includes \
+                    -I$(top_srcdir)/modules/string/includes \
                     -I$(top_srcdir)/modules/fileio/includes
 
 
@@ -91,6 +94,7 @@ libscixml_la_CPPFLAGS = -I$(srcdir)/includes/ \
     -I$(srcdir)/src/c/ \
     -I$(top_srcdir)/modules/api_scilab/includes \
     -I$(top_srcdir)/modules/output_stream/includes \
+    -I$(top_srcdir)/modules/string/includes \
     -I$(top_srcdir)/modules/fileio/includes \
     $(XML_FLAGS)
 
@@ -110,6 +114,8 @@ libscixml_la_LIBADD = libscixml-algo.la
 CHECK_SRC= $(XML_C_SOURCES) $(GATEWAY_C_SOURCES)
 INCLUDE_FLAGS = $(libscixml_la_CFLAGS)
 
+#### xml : include files ####
+libscixml_la_includedir=$(pkgincludedir)
 
 #### xml : gateway declaration ####
 libscixml_la_sci_gatewaydir = $(mydatadir)/sci_gateway
index 97a1274..c0f7b4b 100644 (file)
@@ -157,7 +157,8 @@ am__objects_5 = libscixml_la-sci_xmlRead.lo \
        libscixml_la-sci_percent_foo_i_XMLList.lo \
        libscixml_la-sci_xmlValidationFile.lo \
        libscixml_la-sci_xmlValidate.lo \
-       libscixml_la-sci_xmlIsValidObject.lo
+       libscixml_la-sci_xmlIsValidObject.lo \
+       libscixml_la-sci_xmlAsNumber.lo libscixml_la-sci_xmlAsText.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) \
@@ -563,13 +564,16 @@ GATEWAY_CPP_SOURCES = sci_gateway/cpp/sci_xmlRead.cpp \
                      sci_gateway/cpp/sci_percent_foo_i_XMLList.cpp \
                      sci_gateway/cpp/sci_xmlValidationFile.cpp \
                      sci_gateway/cpp/sci_xmlValidate.cpp \
-                     sci_gateway/cpp/sci_xmlIsValidObject.cpp
+                     sci_gateway/cpp/sci_xmlIsValidObject.cpp \
+                     sci_gateway/cpp/sci_xmlAsNumber.cpp \
+                     sci_gateway/cpp/sci_xmlAsText.cpp
 
 libscixml_la_CFLAGS = -I$(srcdir)/includes/ \
                     -I$(top_srcdir)/libs/MALLOC/includes/ \
                      -I$(top_srcdir)/modules/core/includes \
                     -I$(top_srcdir)/modules/api_scilab/includes \
                     -I$(top_srcdir)/modules/output_stream/includes \
+                    -I$(top_srcdir)/modules/string/includes \
                     -I$(top_srcdir)/modules/fileio/includes
 
 libscixml_la_CPPFLAGS = -I$(srcdir)/includes/ \
@@ -577,6 +581,7 @@ libscixml_la_CPPFLAGS = -I$(srcdir)/includes/ \
     -I$(srcdir)/src/c/ \
     -I$(top_srcdir)/modules/api_scilab/includes \
     -I$(top_srcdir)/modules/output_stream/includes \
+    -I$(top_srcdir)/modules/string/includes \
     -I$(top_srcdir)/modules/fileio/includes \
     $(XML_FLAGS)
 
@@ -593,6 +598,9 @@ libscixml_la_LIBADD = libscixml-algo.la
 CHECK_SRC = $(XML_C_SOURCES) $(GATEWAY_C_SOURCES)
 INCLUDE_FLAGS = $(libscixml_la_CFLAGS)
 
+#### xml : include files ####
+libscixml_la_includedir = $(pkgincludedir)
+
 #### xml : gateway declaration ####
 libscixml_la_sci_gatewaydir = $(mydatadir)/sci_gateway
 libscixml_la_sci_gateway_DATA = sci_gateway/xml_gateway.xml
@@ -711,6 +719,8 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_percent_s_i_XMLList.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_print.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_xmlAddNs.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_xmlAsNumber.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_xmlAsText.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_xmlClose.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_xmlDocument.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_xmlDump.Plo@am__quote@
@@ -1092,6 +1102,20 @@ libscixml_la-sci_xmlIsValidObject.lo: sci_gateway/cpp/sci_xmlIsValidObject.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_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscixml_la-sci_xmlIsValidObject.lo `test -f 'sci_gateway/cpp/sci_xmlIsValidObject.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xmlIsValidObject.cpp
 
+libscixml_la-sci_xmlAsNumber.lo: sci_gateway/cpp/sci_xmlAsNumber.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_xmlAsNumber.lo -MD -MP -MF $(DEPDIR)/libscixml_la-sci_xmlAsNumber.Tpo -c -o libscixml_la-sci_xmlAsNumber.lo `test -f 'sci_gateway/cpp/sci_xmlAsNumber.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xmlAsNumber.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscixml_la-sci_xmlAsNumber.Tpo $(DEPDIR)/libscixml_la-sci_xmlAsNumber.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_xmlAsNumber.cpp' object='libscixml_la-sci_xmlAsNumber.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_xmlAsNumber.lo `test -f 'sci_gateway/cpp/sci_xmlAsNumber.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xmlAsNumber.cpp
+
+libscixml_la-sci_xmlAsText.lo: sci_gateway/cpp/sci_xmlAsText.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_xmlAsText.lo -MD -MP -MF $(DEPDIR)/libscixml_la-sci_xmlAsText.Tpo -c -o libscixml_la-sci_xmlAsText.lo `test -f 'sci_gateway/cpp/sci_xmlAsText.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xmlAsText.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscixml_la-sci_xmlAsText.Tpo $(DEPDIR)/libscixml_la-sci_xmlAsText.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_xmlAsText.cpp' object='libscixml_la-sci_xmlAsText.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_xmlAsText.lo `test -f 'sci_gateway/cpp/sci_xmlAsText.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xmlAsText.cpp
+
 mostlyclean-libtool:
        -rm -f *.lo
 
diff --git a/scilab/modules/xml/help/en_US/xmlAsNumber.xml b/scilab/modules/xml/help/en_US/xmlAsNumber.xml
new file mode 100644 (file)
index 0000000..8d8bb93
--- /dev/null
@@ -0,0 +1,86 @@
+<?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 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" version="5.0-subset Scilab" xml:id="xmlAsNumber" xml:lang="en">
+  <info>
+    <pubdate>$LastChangedDate$</pubdate>
+  </info>
+  <refnamediv>
+    <refname>xmlAsNumber</refname>
+    <refpurpose>Convert the result of a XPath query into a row of numbers</refpurpose>
+  </refnamediv>
+  <refsynopsisdiv>
+    <title>Calling Sequence</title>
+    <synopsis>
+      nums = xmlAsNumber(xp)
+    </synopsis>
+  </refsynopsisdiv>
+  <refsection>
+    <title>Arguments</title>
+    <variablelist>
+      <varlistentry>
+        <term>xp</term>
+        <listitem>
+          <para>xp, a XML mlist typed XMLSet</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term>nums</term>
+        <listitem>
+          <para>nums, a single row of doubles</para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsection>
+  <refsection>
+    <title>Description</title>
+    <para>The result of a XPath query can be a set of XMLElements which contains numbers, so the aim of this function is to convert the contents of each nodes into a double.</para>
+  </refsection>
+  <refsection>
+    <title>Examples</title>
+    <programlisting role="example"><![CDATA[
+    doc = xmlReadStr("<root><a>12</a><a>13</a><a>1.2345678</a><a>45e3</a><a>.23E-2</a></root>");
+
+    // Retrieve the content of the nodes with name equals to "a"
+    xp = xmlXPath(doc, "//a/text()");
+
+    // convert the result into doubles
+    data = xmlAsNumber(xp)
+
+    xmlClose(doc);
+    ]]></programlisting>
+  </refsection>
+  <refsection role="see also">
+    <title>See Also</title>
+    <simplelist type="inline">
+      <member>
+        <link linkend="xmlXPath">xmlXPath</link>
+      </member>
+      <member>
+        <link linkend="xmlAsText">xmlAsText</link>
+      </member>
+    </simplelist>
+  </refsection>
+  <refsection>
+    <title>Author</title>
+    <para>Calixte DENIZET</para>
+  </refsection>
+  <refsection>
+    <title>History</title>
+    <revhistory>
+      <revision>
+        <revnumber>5.4.0</revnumber>
+        <revremark>XML module introduced.</revremark>
+      </revision>
+    </revhistory>
+  </refsection>
+</refentry>
diff --git a/scilab/modules/xml/help/en_US/xmlAsText.xml b/scilab/modules/xml/help/en_US/xmlAsText.xml
new file mode 100644 (file)
index 0000000..d19698d
--- /dev/null
@@ -0,0 +1,86 @@
+<?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 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" version="5.0-subset Scilab" xml:id="xmlAsText" xml:lang="en">
+  <info>
+    <pubdate>$LastChangedDate$</pubdate>
+  </info>
+  <refnamediv>
+    <refname>xmlAsText</refname>
+    <refpurpose>Convert the result of a XPath query into a row of strings</refpurpose>
+  </refnamediv>
+  <refsynopsisdiv>
+    <title>Calling Sequence</title>
+    <synopsis>
+      strings = xmlAsText(xp)
+    </synopsis>
+  </refsynopsisdiv>
+  <refsection>
+    <title>Arguments</title>
+    <variablelist>
+      <varlistentry>
+        <term>xp</term>
+        <listitem>
+          <para>xp, a XML mlist typed XMLSet</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term>strings</term>
+        <listitem>
+          <para>strings, a single row of strings</para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsection>
+  <refsection>
+    <title>Description</title>
+    <para>The result of a XPath query can be a set of XMLElements, so the aim of this function is to convert the contents of each nodes into a string.</para>
+  </refsection>
+  <refsection>
+    <title>Examples</title>
+    <programlisting role="example"><![CDATA[
+    doc = xmlReadStr("<root><a>Hello</a><a>Scilab</a><a>World</a></root>");
+
+    // Retrieve the content of the nodes with name equals to "a"
+    xp = xmlXPath(doc, "//a/text()");
+
+    // convert the result into a row of strings
+    data = xmlAsText(xp)
+
+    xmlClose(doc);
+    ]]></programlisting>
+  </refsection>
+  <refsection role="see also">
+    <title>See Also</title>
+    <simplelist type="inline">
+      <member>
+        <link linkend="xmlXPath">xmlXPath</link>
+      </member>
+      <member>
+        <link linkend="xmlAsNumber">xmlAsNumber</link>
+      </member>
+    </simplelist>
+  </refsection>
+  <refsection>
+    <title>Author</title>
+    <para>Calixte DENIZET</para>
+  </refsection>
+  <refsection>
+    <title>History</title>
+    <revhistory>
+      <revision>
+        <revnumber>5.4.0</revnumber>
+        <revremark>XML module introduced.</revremark>
+      </revision>
+    </revhistory>
+  </refsection>
+</refentry>
index c415d1b..66f325e 100644 (file)
@@ -21,7 +21,7 @@
   <refsynopsisdiv>
     <title>Calling Sequence</title>
     <synopsis>
-      xmlNodeSet = xmlXPath(xmlDoc, queryStr [, namespaces])
+      result = xmlXPath(xmlDoc, queryStr [, namespaces])
     </synopsis>
   </refsynopsisdiv>
   <refsection>
           <para>namespaces, an optional matrix nx2 of strings</para>
         </listitem>
       </varlistentry>
+      <varlistentry>
+        <term>result</term>
+        <listitem>
+          <para>result can be a set of XMLElements or a number or a string or a boolean</para>
+        </listitem>
+      </varlistentry>
     </variablelist>
   </refsection>
   <refsection>
@@ -61,7 +67,7 @@
     xp = xmlXPath(doc, "//note");
     s = size(xp);
     for i=1:s(2)
-        xmlDump(xp(i))
+    xmlDump(xp(i))
     end
 
     // Count the nodes with name equals to "note"
     xp = xmlXPath(doc, "//*[@id=""Philosophy""]");
     s = size(xp);
     if (s(2) <> 0) then
-        xmlDump(xp(1))
+    xmlDump(xp(1))
     end
 
     // Retrieve the nodes with an attribute num equals to the number 5
     xp = xmlXPath(doc, "//*[number(@num)=5]");
     s = size(xp);
     if (s(2) <> 0) then
-        xmlDump(xp(1))
+    xmlDump(xp(1))
     end
 
     xmlClose(doc);
index 2956ffc..315191c 100644 (file)
@@ -67,6 +67,8 @@ 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);
 int sci_xmlIsValidObject(char *fname, unsigned long fname_len);
+int sci_xmlAsNumber(char *fname, unsigned long fname_len);
+int sci_xmlAsText(char *fname, unsigned long fname_len);
 /*--------------------------------------------------------------------------*/
 #endif /* __GW_XML_H__ */
 /*--------------------------------------------------------------------------*/
index acff650..fcb9f51 100644 (file)
@@ -93,7 +93,9 @@ static gw_generic_table Tab[] =
     {sci_xmlRelaxNG, "xmlRelaxNG"},
     {sci_xmlValidate, "xmlValidate"},
     {sci_percent_XMLValid_p, "%XMLValid_p"},
-    {sci_xmlIsValidObject, "xmlIsValidObject"}
+    {sci_xmlIsValidObject, "xmlIsValidObject"},
+    {sci_xmlAsNumber, "xmlAsNumber"},
+    {sci_xmlAsText, "xmlAsText"}
 };
 /*--------------------------------------------------------------------------*/
 int gw_xml(void)
diff --git a/scilab/modules/xml/sci_gateway/cpp/sci_xmlAsNumber.cpp b/scilab/modules/xml/sci_gateway/cpp/sci_xmlAsNumber.cpp
new file mode 100644 (file)
index 0000000..037dfc3
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * 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 <cstdlib>
+
+#include "XMLObject.hxx"
+#include "XMLNodeSet.hxx"
+
+extern "C"
+{
+#include "gw_xml.h"
+#include "stack-c.h"
+#include "Scierror.h"
+#include "api_scilab.h"
+#include "xml_mlist.h"
+#include "localization.h"
+#include "stringToDouble.h"
+}
+
+using namespace org_modules_xml;
+
+/*--------------------------------------------------------------------------*/
+int sci_xmlAsNumber(char * fname, unsigned long fname_len)
+{
+    int id;
+    SciErr err;
+    int * addr = 0;
+    XMLNodeSet * set = 0;
+    xmlNodeSet * realSet = 0;
+    double * pdblReal = 0;
+
+    CheckLhs(1, 1);
+    CheckRhs(1, 1);
+
+    err = getVarAddressFromPosition(pvApiCtx, 1, &addr);
+    if (err.iErr)
+    {
+        printError(&err, 0);
+        return 0;
+    }
+
+    if (!isXMLSet(addr, pvApiCtx))
+    {
+        Scierror(999, gettext("%s: Wrong type for input argument #%i: XMLSet expected.\n"), fname, 1);
+        return 0;
+
+    }
+
+    id = getXMLObjectId(addr, pvApiCtx);
+    set = XMLObject::getFromId<XMLNodeSet>(id);
+    if (!set)
+    {
+        Scierror(999, gettext("%s: XMLSet does not exist.\n"), fname);
+        return 0;
+    }
+
+    err = allocMatrixOfDouble(pvApiCtx, Rhs + 1, 1, set->getSize(), &pdblReal);
+    realSet = static_cast<xmlNodeSet *>(set->getRealXMLPointer());
+
+    for (int i = 0; i < set->getSize(); i++)
+    {
+        xmlNode * node = realSet->nodeTab[i];
+        const char * content = (const char *)xmlNodeGetContent(node);
+        stringToDoubleError convErr = STRINGTODOUBLE_NO_ERROR;
+        pdblReal[i] = stringToDouble(content, TRUE, &convErr);
+    }
+
+    LhsVar(1) = Rhs + 1;
+    PutLhsVar();
+    return 0;
+}
+/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/xml/sci_gateway/cpp/sci_xmlAsText.cpp b/scilab/modules/xml/sci_gateway/cpp/sci_xmlAsText.cpp
new file mode 100644 (file)
index 0000000..b782178
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * 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 <cstdlib>
+
+#include "XMLObject.hxx"
+#include "XMLNodeSet.hxx"
+
+extern "C"
+{
+#include "gw_xml.h"
+#include "stack-c.h"
+#include "Scierror.h"
+#include "api_scilab.h"
+#include "xml_mlist.h"
+#include "localization.h"
+}
+
+using namespace org_modules_xml;
+
+/*--------------------------------------------------------------------------*/
+int sci_xmlAsText(char * fname, unsigned long fname_len)
+{
+    int id;
+    SciErr err;
+    int * addr = 0;
+    XMLNodeSet * set = 0;
+    xmlNodeSet * realSet = 0;
+    const char ** pstStrings = 0;
+
+    CheckLhs(1, 1);
+    CheckRhs(1, 1);
+
+    err = getVarAddressFromPosition(pvApiCtx, 1, &addr);
+    if (err.iErr)
+    {
+        printError(&err, 0);
+        return 0;
+    }
+
+    if (!isXMLSet(addr, pvApiCtx))
+    {
+        Scierror(999, gettext("%s: Wrong type for input argument #%i: XMLSet expected.\n"), fname, 1);
+        return 0;
+
+    }
+
+    id = getXMLObjectId(addr, pvApiCtx);
+    set = XMLObject::getFromId<XMLNodeSet>(id);
+    if (!set)
+    {
+        Scierror(999, gettext("%s: XMLSet does not exist.\n"), fname);
+        return 0;
+    }
+
+    realSet = static_cast<xmlNodeSet *>(set->getRealXMLPointer());
+    pstStrings = new const char*[set->getSize()];
+
+    for (int i = 0; i < set->getSize(); i++)
+    {
+        xmlNode * node = realSet->nodeTab[i];
+        pstStrings[i] = (const char *)xmlNodeGetContent(node);
+    }
+
+    err = createMatrixOfString(pvApiCtx, Rhs + 1, 1, set->getSize(), const_cast<const char * const *>(pstStrings));
+    delete[] pstStrings;
+    if (err.iErr)
+    {
+        printError(&err, 0);
+        return 0;
+    }
+
+    LhsVar(1) = Rhs + 1;
+    PutLhsVar();
+    return 0;
+}
+/*--------------------------------------------------------------------------*/
index 8c6c97f..d80f2b8 100644 (file)
 <PRIMITIVE gatewayId="68" primitiveId="72" primitiveName="xmlValidate" />
 <PRIMITIVE gatewayId="68" primitiveId="73" primitiveName="%XMLValid_p" />
 <PRIMITIVE gatewayId="68" primitiveId="74" primitiveName="xmlIsValidObject" />
+<PRIMITIVE gatewayId="68" primitiveId="75" primitiveName="xmlAsNumber" />
+<PRIMITIVE gatewayId="68" primitiveId="76" primitiveName="xmlAsText" />
 </GATEWAY>
index f9bf687..a5ff350 100644 (file)
@@ -34,6 +34,11 @@ namespace org_modules_xml
         scope->removeId(id);
     }
 
+    void * XMLAttr::getRealXMLPointer() const
+    {
+        return static_cast<void *>(elem.getRealNode()->properties);
+    }
+
     const XMLObject * XMLAttr::getXMLObjectParent() const
     {
         return &elem;
index 708750e..2697a42 100644 (file)
@@ -36,6 +36,12 @@ namespace org_modules_xml
 
         ~XMLAttr();
 
+        void * getRealXMLPointer() const;
+
+        /**
+         * Get the number of attributes
+         * @return the attributes number
+         */
         int getSize() const;
 
         /**
index e7a82e8..1ce88d9 100644 (file)
@@ -110,6 +110,11 @@ namespace org_modules_xml
         }
     }
 
+    void * XMLDocument::getRealXMLPointer() const
+    {
+        return static_cast<void *>(document);
+    }
+
     const XMLXPath * XMLDocument::makeXPathQuery(const char * query, char ** namespaces, int length, std::string * error)
     {
         if (errorXPathBuffer)
index f7b0a69..ad65ad7 100644 (file)
@@ -84,6 +84,8 @@ namespace org_modules_xml
 
         ~XMLDocument();
 
+        void * getRealXMLPointer() const;
+
         /**
          * @return the xmlDoc behind this XMLDocument
          */
index d260bf7..69c8327 100644 (file)
@@ -47,6 +47,11 @@ namespace org_modules_xml
         scope->removeId(id);
     }
 
+    void * XMLElement::getRealXMLPointer() const
+    {
+        return static_cast<void *>(node);
+    }
+
     const XMLObject * XMLElement::getXMLObjectParent() const
     {
         return &doc;
index 8edc82e..1139297 100644 (file)
@@ -53,6 +53,8 @@ namespace org_modules_xml
 
         ~XMLElement();
 
+        void * getRealXMLPointer() const;
+
         /**
          * @return the node name
          */
index 58aa567..0edda4a 100644 (file)
@@ -37,6 +37,11 @@ namespace org_modules_xml
         scope->removeId(id);
     }
 
+    void * XMLNodeList::getRealXMLPointer() const
+    {
+        return static_cast<void *>(parent->children);
+    }
+
     const XMLObject * XMLNodeList::getXMLObjectParent() const
     {
         return &doc;
@@ -143,7 +148,7 @@ namespace org_modules_xml
 
     void XMLNodeList::setElementAtPosition(double index, const std::string & xmlCode)
     {
-       std::string error;
+        std::string error;
         XMLDocument document = XMLDocument(xmlCode, false, &error);
 
         if (error.empty())
index 159f624..0b0a583 100644 (file)
@@ -46,6 +46,8 @@ namespace org_modules_xml
 
         ~XMLNodeList();
 
+        void * getRealXMLPointer() const;
+
         /**
          * Removes an element
          * @param index the index of the element to remove
index 081a70b..8a38c9c 100644 (file)
@@ -46,6 +46,11 @@ namespace org_modules_xml
         scope->removeId(id);
     }
 
+    void * XMLNodeSet::getRealXMLPointer() const
+    {
+        return static_cast<void *>(nodeSet);
+    }
+
     const XMLObject * XMLNodeSet::getXMLObjectParent() const
     {
         return &doc;
index 9334ab5..6a62c4b 100644 (file)
@@ -44,6 +44,8 @@ namespace org_modules_xml
 
         ~XMLNodeSet();
 
+        void * getRealXMLPointer() const;
+
         const XMLObject * getXMLObjectParent() const;
         const XMLObject * getListElement(int index);
     };
index dfa4ae1..75251da 100644 (file)
@@ -34,6 +34,11 @@ namespace org_modules_xml
         scope->removeId(id);
     }
 
+    void * XMLNotHandledElement::getRealXMLPointer() const
+    {
+        return static_cast<void *>(node);
+    }
+
     const XMLObject * XMLNotHandledElement::getXMLObjectParent() const
     {
         return &parent;
index 5072295..d0f994e 100644 (file)
@@ -42,6 +42,8 @@ namespace org_modules_xml
 
         ~XMLNotHandledElement();
 
+        void * getRealXMLPointer() const;
+
         const XMLObject * getXMLObjectParent() const;
         const std::string toString() const;
     };
index 2a05604..7c722be 100644 (file)
@@ -40,6 +40,11 @@ namespace org_modules_xml
         scope->removeId(id);
     }
 
+    void * XMLNs::getRealXMLPointer() const
+    {
+        return static_cast<void *>(ns);
+    }
+
     const XMLObject * XMLNs::getXMLObjectParent() const
     {
         return &parent;
index 70c55f3..64c0e3b 100644 (file)
@@ -52,6 +52,8 @@ namespace org_modules_xml
 
         ~XMLNs();
 
+        void * getRealXMLPointer() const;
+
         /**
          * @return the namespace href
          */
index af08b7e..23fde1d 100644 (file)
@@ -48,6 +48,12 @@ namespace org_modules_xml
         virtual ~XMLObject() { }
 
         /**
+         * Get the libxml2 pointer
+         * @return the pointer
+         */
+        virtual void * getRealXMLPointer() const { return 0; }
+
+        /**
          * Gets a XML parent object. A set of dependencies is created between the objects
          * to be sure that all the XML objects will be freed when a document will be destroyed.
          * @return the parent XMLObject
index 86cbc38..41c0981 100644 (file)
@@ -32,6 +32,11 @@ namespace org_modules_xml
         scope->removeId(id);
     }
 
+    void * XMLXPath::getRealXMLPointer() const
+    {
+        return static_cast<void *>(xpath);
+    }
+
     const XMLObject * XMLXPath::getXMLObjectParent() const
     {
         return &doc;
index 15e93ba..bf25cae 100644 (file)
@@ -28,7 +28,9 @@ namespace org_modules_xml
 
     public:
         XMLXPath(const XMLDocument & doc, xmlXPathObject * xpath);
-       ~XMLXPath();
+        ~XMLXPath();
+
+        void * getRealXMLPointer() const;
 
         int getBooleanValue() const { return xpath->boolval; }
         double getFloatValue() const { return xpath->floatval; }
diff --git a/scilab/modules/xml/tests/unit_tests/xmlAsNumber.dia.ref b/scilab/modules/xml/tests/unit_tests/xmlAsNumber.dia.ref
new file mode 100644 (file)
index 0000000..a4234bd
--- /dev/null
@@ -0,0 +1,12 @@
+// ===========================================================================
+// 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 = xmlReadStr("<root><a>bug</a><a>13</a><a>1.2345678</a><a>b</a><a>.23E-2</a></root>");
+xp = xmlXPath(doc, "//a/text()");
+assert_checkequal(xmlAsNumber(xp), [%nan,13,1.2345678,%nan,0.0023]);
+xmlFile=xmlRead(SCI+"/modules/xml/tests/unit_tests/w3cExample.xml");
+plop=xmlXPath(xmlFile, "/bookstore/book/price");
+assert_checkequal(xmlAsNumber(plop), [30,29.99,49.99,39.95,0]);
diff --git a/scilab/modules/xml/tests/unit_tests/xmlAsNumber.tst b/scilab/modules/xml/tests/unit_tests/xmlAsNumber.tst
new file mode 100644 (file)
index 0000000..510d02b
--- /dev/null
@@ -0,0 +1,16 @@
+// ===========================================================================
+// 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 = xmlReadStr("<root><a>bug</a><a>13</a><a>1.2345678</a><a>b</a><a>.23E-2</a></root>");
+xp = xmlXPath(doc, "//a/text()");
+assert_checkequal(xmlAsNumber(xp), [%nan,13,1.2345678,%nan,0.0023]);
+
+xmlFile=xmlRead(SCI+"/modules/xml/tests/unit_tests/w3cExample.xml");
+plop=xmlXPath(xmlFile, "/bookstore/book/price");
+assert_checkequal(xmlAsNumber(plop), [30,29.99,49.99,39.95,0]);
+
diff --git a/scilab/modules/xml/tests/unit_tests/xmlAsText.dia.ref b/scilab/modules/xml/tests/unit_tests/xmlAsText.dia.ref
new file mode 100644 (file)
index 0000000..0cefc0f
--- /dev/null
@@ -0,0 +1,15 @@
+// ===========================================================================
+// 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 = xmlReadStr("<root><a>bug</a><a>13</a><a>1.2345678</a><a>b</a><a>.23E-2</a></root>");
+xp = xmlXPath(doc, "//a/text()");
+assert_checkequal(xmlAsText(xp),  ["bug","13","1.2345678","b",".23E-2"]);
+xmlFile=xmlRead(SCI+"/modules/xml/tests/unit_tests/w3cExample.xml");
+plop=xmlXPath(xmlFile, "/bookstore/book/price");
+assert_checkequal(xmlAsText(plop),  ["30.00","29.99","49.99","39.95","0.0"])
+ ans  =
+  T  
diff --git a/scilab/modules/xml/tests/unit_tests/xmlAsText.tst b/scilab/modules/xml/tests/unit_tests/xmlAsText.tst
new file mode 100644 (file)
index 0000000..d7cb71b
--- /dev/null
@@ -0,0 +1,16 @@
+// ===========================================================================
+// 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 = xmlReadStr("<root><a>bug</a><a>13</a><a>1.2345678</a><a>b</a><a>.23E-2</a></root>");
+xp = xmlXPath(doc, "//a/text()");
+assert_checkequal(xmlAsText(xp),  ["bug","13","1.2345678","b",".23E-2"]);
+
+xmlFile=xmlRead(SCI+"/modules/xml/tests/unit_tests/w3cExample.xml");
+plop=xmlXPath(xmlFile, "/bookstore/book/price");
+assert_checkequal(xmlAsText(plop),  ["30.00","29.99","49.99","39.95","0.0"])
+
index a410363..f4fd8ae 100644 (file)
@@ -76,7 +76,7 @@
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <ClCompile>
       <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>includes;src/c;src/cpp;../core/includes;../output_stream/includes;../fileio/includes;../localization/includes;../../libs/MALLOC/includes;../../libs/intl;../../libs/libxml2;../api_scilab/includes;../windows_tools/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>includes;src/c;src/cpp;../core/includes;../output_stream/includes;../string/includes;../fileio/includes;../localization/includes;../../libs/MALLOC/includes;../../libs/intl;../../libs/libxml2;../api_scilab/includes;../windows_tools/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>FORDLL;_DEBUG;_WINDOWS;_USRDLL;XML_SCILAB_EXPORTS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
       <WarningLevel>Level3</WarningLevel>
     </Midl>
     <ClCompile>
       <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>includes;src/c;src/cpp;../core/includes;../output_stream/includes;../fileio/includes;../localization/includes;../../libs/MALLOC/includes;../../libs/intl;../../libs/libxml2;../api_scilab/includes;../windows_tools/includes;../windows_tools/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>includes;src/c;src/cpp;../core/includes;../output_stream/includes;../string/includes;../fileio/includes;../localization/includes;../../libs/MALLOC/includes;../../libs/intl;../../libs/libxml2;../api_scilab/includes;../windows_tools/includes;../windows_tools/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>FORDLL;_DEBUG;_WINDOWS;_USRDLL;XML_SCILAB_EXPORTS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
       <WarningLevel>Level3</WarningLevel>
     <ClCompile>
       <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
       <WholeProgramOptimization>false</WholeProgramOptimization>
-      <AdditionalIncludeDirectories>includes;src/c;src/cpp;../core/includes;../output_stream/includes;../fileio/includes;../localization/includes;../../libs/MALLOC/includes;../../libs/intl;../../libs/libxml2;../api_scilab/includes;../windows_tools/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>includes;src/c;src/cpp;../core/includes;../output_stream/includes;../string/includes;../fileio/includes;../localization/includes;../../libs/MALLOC/includes;../../libs/intl;../../libs/libxml2;../api_scilab/includes;../windows_tools/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>FORDLL;NDEBUG;_WINDOWS;_USRDLL;XML_SCILAB_EXPORTS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <StringPooling>true</StringPooling>
       <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
     <ClCompile>
       <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
       <WholeProgramOptimization>false</WholeProgramOptimization>
-      <AdditionalIncludeDirectories>includes;src/c;src/cpp;../core/includes;../output_stream/includes;../fileio/includes;../localization/includes;../../libs/MALLOC/includes;../../libs/intl;../../libs/libxml2;../api_scilab/includes;../windows_tools/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>includes;src/c;src/cpp;../core/includes;../output_stream/includes;../string/includes;../fileio/includes;../localization/includes;../../libs/MALLOC/includes;../../libs/intl;../../libs/libxml2;../api_scilab/includes;../windows_tools/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>FORDLL;NDEBUG;_WINDOWS;_USRDLL;XML_SCILAB_EXPORTS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <StringPooling>true</StringPooling>
       <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
       <Project>{a5911cd7-f8e8-440c-a23e-4843a0636f3a}</Project>
       <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
     </ProjectReference>
+    <ProjectReference Include="..\string\src\c\string.vcxproj">
+      <Project>{8d45767a-9b03-4905-97f6-d2f3f79141ea}</Project>
+    </ProjectReference>
     <ProjectReference Include="..\windows_tools\src\c\scilab_windows\scilab_windows.vcxproj">
       <Project>{8028f371-6a94-4a26-8804-6e7f05f1d1aa}</Project>
     </ProjectReference>
     <ClCompile Include="sci_gateway\cpp\sci_xmlValidationFile.cpp" />
     <ClCompile Include="sci_gateway\cpp\sci_xmlWrite.cpp" />
     <ClCompile Include="sci_gateway\cpp\sci_xmlXPath.cpp" />
+    <ClCompile Include="sci_gateway\cpp\sci_xmlXPathNumber.cpp" />
+    <ClCompile Include="sci_gateway\cpp\sci_xmlXPathText.cpp" />
     <ClCompile Include="sci_gateway\c\gw_xml.c" />
     <ClCompile Include="src\cpp\VariableScope.cpp" />
     <ClCompile Include="src\cpp\XMLAttr.cpp" />
index 645711f..1e711bb 100644 (file)
     <ClCompile Include="sci_gateway\cpp\sci_xmlIsValidObject.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="sci_gateway\cpp\sci_xmlXPathNumber.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="sci_gateway\cpp\sci_xmlXPathText.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>
\ No newline at end of file