XML: add a function xmlName to retrieve easily names of XPath query or elements 57/9557/3
Calixte DENIZET [Mon, 29 Oct 2012 18:08:38 +0000 (19:08 +0100)]
Change-Id: I614ba41a88c524dff6d19dff175c5b017914dd9d

15 files changed:
scilab/modules/xml/Makefile.am
scilab/modules/xml/Makefile.in
scilab/modules/xml/help/en_US/xmlAsNumber.xml
scilab/modules/xml/help/en_US/xmlAsText.xml
scilab/modules/xml/help/en_US/xmlName.xml [new file with mode: 0644]
scilab/modules/xml/includes/gw_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_xmlName.cpp [new file with mode: 0644]
scilab/modules/xml/sci_gateway/xml_gateway.xml
scilab/modules/xml/src/c/XMLMlistsManagement.c
scilab/modules/xml/tests/unit_tests/xmlName.dia.ref [new file with mode: 0644]
scilab/modules/xml/tests/unit_tests/xmlName.tst [new file with mode: 0644]
scilab/modules/xml/xml.vcxproj
scilab/modules/xml/xml.vcxproj.filters

index 4c1cfa0..861f4b4 100644 (file)
@@ -79,7 +79,8 @@ GATEWAY_CXX_SOURCES = sci_gateway/cpp/sci_xmlRead.cpp \
                      sci_gateway/cpp/sci_xmlAsNumber.cpp \
                      sci_gateway/cpp/sci_xmlAsText.cpp \
                      sci_gateway/cpp/sci_xmlRemove.cpp \
-                     sci_gateway/cpp/sci_xmlSetAttributes.cpp
+                     sci_gateway/cpp/sci_xmlSetAttributes.cpp \
+                     sci_gateway/cpp/sci_xmlName.cpp
 
 libscixml_la_CPPFLAGS = -I$(srcdir)/includes/ \
     -I$(srcdir)/src/cpp/ \
index 5ba72d9..ce6aa86 100644 (file)
@@ -183,7 +183,8 @@ am__objects_5 = libscixml_la-sci_xmlRead.lo \
        libscixml_la-sci_xmlIsValidObject.lo \
        libscixml_la-sci_xmlAsNumber.lo libscixml_la-sci_xmlAsText.lo \
        libscixml_la-sci_xmlRemove.lo \
-       libscixml_la-sci_xmlSetAttributes.lo
+       libscixml_la-sci_xmlSetAttributes.lo \
+       libscixml_la-sci_xmlName.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) \
@@ -613,7 +614,8 @@ GATEWAY_CXX_SOURCES = sci_gateway/cpp/sci_xmlRead.cpp \
                      sci_gateway/cpp/sci_xmlAsNumber.cpp \
                      sci_gateway/cpp/sci_xmlAsText.cpp \
                      sci_gateway/cpp/sci_xmlRemove.cpp \
-                     sci_gateway/cpp/sci_xmlSetAttributes.cpp
+                     sci_gateway/cpp/sci_xmlSetAttributes.cpp \
+                     sci_gateway/cpp/sci_xmlName.cpp
 
 libscixml_la_CPPFLAGS = -I$(srcdir)/includes/ \
     -I$(srcdir)/src/cpp/ \
@@ -774,6 +776,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_xmlGetNsByPrefix.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_xmlGetOpenDocs.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_xmlIsValidObject.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_xmlName.Plo@am__quote@
 @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@
@@ -1176,6 +1179,13 @@ libscixml_la-sci_xmlSetAttributes.lo: sci_gateway/cpp/sci_xmlSetAttributes.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_xmlSetAttributes.lo `test -f 'sci_gateway/cpp/sci_xmlSetAttributes.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xmlSetAttributes.cpp
 
+libscixml_la-sci_xmlName.lo: sci_gateway/cpp/sci_xmlName.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_xmlName.lo -MD -MP -MF $(DEPDIR)/libscixml_la-sci_xmlName.Tpo -c -o libscixml_la-sci_xmlName.lo `test -f 'sci_gateway/cpp/sci_xmlName.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xmlName.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscixml_la-sci_xmlName.Tpo $(DEPDIR)/libscixml_la-sci_xmlName.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_xmlName.cpp' object='libscixml_la-sci_xmlName.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_xmlName.lo `test -f 'sci_gateway/cpp/sci_xmlName.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xmlName.cpp
+
 mostlyclean-libtool:
        -rm -f *.lo
 
index 06beb4a..0b2a3be 100644 (file)
@@ -65,6 +65,9 @@
             <member>
                 <link linkend="xmlAsText">xmlAsText</link>
             </member>
+            <member>
+                <link linkend="xmlName">xmlName</link>
+            </member>
         </simplelist>
     </refsection>
     <refsection>
index de2e102..2da9339 100644 (file)
@@ -65,6 +65,9 @@
             <member>
                 <link linkend="xmlAsNumber">xmlAsNumber</link>
             </member>
+            <member>
+                <link linkend="xmlName">xmlName</link>
+            </member>
         </simplelist>
     </refsection>
     <refsection>
diff --git a/scilab/modules/xml/help/en_US/xmlName.xml b/scilab/modules/xml/help/en_US/xmlName.xml
new file mode 100644 (file)
index 0000000..ca9f339
--- /dev/null
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2012 - Scilab Enterprises - 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" xmlns:scilab="http://www.scilab.org" xml:id="xmlName" xml:lang="en">
+    <refnamediv>
+        <refname>xmlName</refname>
+        <refpurpose>Retrieve the name of the elements.</refpurpose>
+    </refnamediv>
+    <refsynopsisdiv>
+        <title>Calling Sequence</title>
+        <synopsis>
+            names = xmlName(obj)
+        </synopsis>
+    </refsynopsisdiv>
+    <refsection>
+        <title>Arguments</title>
+        <variablelist>
+            <varlistentry>
+                <term>obj</term>
+                <listitem>
+                    <para>obj, a XML mlist typed XMLSet or XMLList or XMLElem or XMLAttr</para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>name</term>
+                <listitem>
+                    <para>names, a single row of strings</para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    <refsection>
+        <title>Description</title>
+        <para>Retrieve the name(s) of the elements composing the XMLObject.</para>
+    </refsection>
+    <refsection>
+        <title>Examples</title>
+        <programlisting role="example"><![CDATA[
+       doc = xmlReadStr("<root><foo a=""123"" b=""456"" c=""789""/></root>")
+
+       // Retrieve the name of a single element
+       xmlName(doc.root.children(1))
+
+       // Retrieve the names of an attributes list
+       xmlName(doc.root.children(1).attributes)
+
+       // Retrieve the names of the result of an XPath query
+       xmlName(xmlXPath(doc,"//foo/@*"))       
+       
+       xmlDelete(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>
+            <member>
+                <link linkend="xmlAsNumber">xmlAsNumber</link>
+            </member>
+        </simplelist>
+    </refsection>
+    <refsection>
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>5.4.0</revnumber>
+                <revremark>XML module introduced.</revremark>
+            </revision>
+        </revhistory>
+    </refsection>
+</refentry>
index ec96e4c..57a9a15 100644 (file)
@@ -72,6 +72,7 @@ int sci_xmlAsNumber(char *fname, unsigned long fname_len);
 int sci_xmlAsText(char *fname, unsigned long fname_len);
 int sci_xmlRemove(char *fname, unsigned long fname_len);
 int sci_xmlSetAttributes(char *fname, unsigned long fname_len);
+int sci_xmlName(char *fname, unsigned long fname_len);
 
 /*--------------------------------------------------------------------------*/
 #endif /* __GW_XML_H__ */
index 16af038..5fd6dcc 100644 (file)
@@ -91,6 +91,13 @@ XML_SCILAB_IMPEXP int isXMLObject(int *mlist, void *pvApiCtx);
  * @param mlist the mlist address
  * @return 1 if the mlist has the good type, else 0.
  */
+XML_SCILAB_IMPEXP int isXMLObjects(const char ** types, int nb, int *mlist, void *pvApiCtx);
+
+/**
+ * Checks if a mlist has the good type
+ * @param mlist the mlist address
+ * @return 1 if the mlist has the good type, else 0.
+ */
 XML_SCILAB_IMPEXP int isXMLNotHandled(int *mlist, void *pvApiCtx);
 
 /**
@@ -112,6 +119,6 @@ XML_SCILAB_IMPEXP int isXMLValid(int *mlist, void *pvApiCtx);
  * @param mlist the mlist address
  * @return the object id.
  */
- XML_SCILAB_IMPEXP int getXMLObjectId(int *mlist, void *pvApiCtx);
+XML_SCILAB_IMPEXP int getXMLObjectId(int *mlist, void *pvApiCtx);
 
 #endif /* __XML_MLIST_H__ */
index 8a2c329..49aa9f5 100644 (file)
@@ -17,7 +17,8 @@
 /*--------------------------------------------------------------------------*/
 /*  interface function */
 /*--------------------------------------------------------------------------*/
-static gw_generic_table Tab[] = {
+static gw_generic_table Tab[] =
+{
     {sci_xmlRead, "xmlRead"},
     {sci_xmlDelete, "xmlDelete"},
     {sci_xmlDump, "xmlDump"},
@@ -95,7 +96,8 @@ static gw_generic_table Tab[] = {
     {sci_xmlAsNumber, "xmlAsNumber"},
     {sci_xmlAsText, "xmlAsText"},
     {sci_xmlRemove, "xmlRemove"},
-    {sci_xmlSetAttributes, "xmlSetAttributes"}
+    {sci_xmlSetAttributes, "xmlSetAttributes"},
+    {sci_xmlName, "xmlName"}
 };
 
 /*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/xml/sci_gateway/cpp/sci_xmlName.cpp b/scilab/modules/xml/sci_gateway/cpp/sci_xmlName.cpp
new file mode 100644 (file)
index 0000000..a77a2df
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - Scilab Enterprises - 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 "XMLList.hxx"
+#include "XMLElement.hxx"
+#include "XMLAttr.hxx"
+
+extern "C"
+{
+#include "gw_xml.h"
+#include "Scierror.h"
+#include "api_scilab.h"
+#include "xml_mlist.h"
+#include "localization.h"
+}
+
+#include <iostream>
+
+using namespace org_modules_xml;
+
+/*--------------------------------------------------------------------------*/
+int sci_xmlName(char *fname, unsigned long fname_len)
+{
+    int id;
+    SciErr err;
+    int *addr = 0;
+    const char **pstStrings = 0;
+    const char * types[] = {"XMLAttr", "XMLList", "XMLSet", "XMLElem"};
+    int type;
+    int size;
+
+    CheckLhs(1, 1);
+    CheckRhs(1, 1);
+
+    err = getVarAddressFromPosition(pvApiCtx, 1, &addr);
+    if (err.iErr)
+    {
+        printError(&err, 0);
+        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
+        return 0;
+    }
+
+    type = isXMLObjects(types, 4, addr, pvApiCtx);
+    if (!type)
+    {
+        Scierror(999, gettext("%s: Wrong type for input argument #%i: XMLSet, XMLList, XMLAttr or XMLElem expected.\n"), fname, 1);
+        return 0;
+    }
+    type--;
+
+    id = getXMLObjectId(addr, pvApiCtx);
+
+    if (type == 1 || type == 2)
+    {
+        XMLList * list = XMLObject::getFromId < XMLList > (id);
+        if (!list)
+        {
+            Scierror(999, gettext("%s: XMLSet or XMLList does not exist.\n"), fname);
+            return 0;
+        }
+
+        pstStrings = list->getNameFromList();
+        size = list->getSize();
+    }
+    else if (type == 0)
+    {
+        XMLAttr * attrs = XMLObject::getFromId<XMLAttr>(id);
+        if (!attrs)
+        {
+            Scierror(999, gettext("%s: XMLAttr does not exist.\n"), fname);
+            return 0;
+        }
+
+        pstStrings = attrs->getNames();
+        size = attrs->getSize();
+    }
+    else
+    {
+        XMLElement * elem = XMLObject::getFromId<XMLElement>(id);
+        if (!elem)
+        {
+            Scierror(999, gettext("%s: XMLElem does not exist.\n"), fname);
+            return 0;
+        }
+
+        pstStrings = new const char *[1];
+        pstStrings[0] = elem->getNodeName();
+        size = 1;
+    }
+
+    if (size)
+    {
+        err = createMatrixOfString(pvApiCtx, Rhs + 1, 1, size, const_cast < const char * const *>(pstStrings));
+        delete[]pstStrings;
+        if (err.iErr)
+        {
+            printError(&err, 0);
+            Scierror(999, _("%s: Memory allocation error.\n"), fname);
+            return 0;
+        }
+    }
+    else
+    {
+        createEmptyMatrix(pvApiCtx, Rhs + 1);
+    }
+
+    LhsVar(1) = Rhs + 1;
+    PutLhsVar();
+    return 0;
+}
+
+/*--------------------------------------------------------------------------*/
index bc5cc01..c7af05c 100644 (file)
@@ -12,8 +12,8 @@
  -->
 <!DOCTYPE GATEWAY SYSTEM "../../functions/xml/gateway.dtd">
 <GATEWAY name="xml">
-  
-  <!--
+    
+    <!--
  Scilab
  Interface description. In this file, we define the list of the function which
  will be available into Scilab and the link to the "native" function.
  Don't touch if you do not know what you are doing
 
 -->
-  <PRIMITIVE gatewayId="68" primitiveId="1" primitiveName="xmlRead" />
-  <PRIMITIVE gatewayId="68" primitiveId="2" primitiveName="xmlDelete" />
-  <PRIMITIVE gatewayId="68" primitiveId="3" primitiveName="xmlDump" />
-  <PRIMITIVE gatewayId="68" primitiveId="4" primitiveName="xmlGetOpenDocs" />
-  <PRIMITIVE gatewayId="68" primitiveId="5" primitiveName="xmlXPath" />
-  <PRIMITIVE gatewayId="68" primitiveId="6" primitiveName="%XMLDoc_e" />
-  <PRIMITIVE gatewayId="68" primitiveId="7" primitiveName="%XMLElem_e" />
-  <PRIMITIVE gatewayId="68" primitiveId="8" primitiveName="%XMLNs_e" />
-  <PRIMITIVE gatewayId="68" primitiveId="9" primitiveName="%XMLAttr_e" />
-  <PRIMITIVE gatewayId="68" primitiveId="10" primitiveName="%XMLList_e" />
-  <PRIMITIVE gatewayId="68" primitiveId="11" primitiveName="%XMLSet_e" />
-  <PRIMITIVE gatewayId="68" primitiveId="12" primitiveName="%XMLDoc_p" />
-  <PRIMITIVE gatewayId="68" primitiveId="13" primitiveName="%XMLElem_p" />
-  <PRIMITIVE gatewayId="68" primitiveId="14" primitiveName="%XMLNs_p" />
-  <PRIMITIVE gatewayId="68" primitiveId="15" primitiveName="%XMLList_p" />
-  <PRIMITIVE gatewayId="68" primitiveId="16" primitiveName="%XMLAttr_p" />
-  <PRIMITIVE gatewayId="68" primitiveId="17" primitiveName="%XMLSet_p" />
-  <PRIMITIVE gatewayId="68" primitiveId="18" primitiveName="%XMLList_size" />
-  <PRIMITIVE gatewayId="68" primitiveId="19" primitiveName="%XMLSet_size" />
-  <PRIMITIVE gatewayId="68" primitiveId="20" primitiveName="%XMLAttr_size" />
-  <PRIMITIVE gatewayId="68" primitiveId="21" primitiveName="%c_i_XMLDoc" />
-  <PRIMITIVE gatewayId="68" primitiveId="22" primitiveName="%XMLElem_i_XMLDoc" />
-  <PRIMITIVE gatewayId="68" primitiveId="23" primitiveName="%c_i_XMLElem" />
-  <PRIMITIVE gatewayId="68" primitiveId="24" primitiveName="%XMLElem_i_XMLElem" />
-  <PRIMITIVE gatewayId="68" primitiveId="25" primitiveName="%XMLAttr_i_XMLElem" />
-  <PRIMITIVE gatewayId="68" primitiveId="26" primitiveName="%XMLList_i_XMLElem" />
-  <PRIMITIVE gatewayId="68" primitiveId="27" primitiveName="%XMLNs_i_XMLElem" />
-  <PRIMITIVE gatewayId="68" primitiveId="28" primitiveName="%c_i_XMLAttr" />
-  <PRIMITIVE gatewayId="68" primitiveId="29" primitiveName="%XMLElem_i_XMLList" />
-  <PRIMITIVE gatewayId="68" primitiveId="30" primitiveName="%XMLDoc_i_XMLList" />
-  <PRIMITIVE gatewayId="68" primitiveId="31" primitiveName="%c_i_XMLList" />
-  <PRIMITIVE gatewayId="68" primitiveId="32" primitiveName="%s_i_XMLList" />
-  <PRIMITIVE gatewayId="68" primitiveId="33" primitiveName="%p_i_XMLList" />
-  <PRIMITIVE gatewayId="68" primitiveId="34" primitiveName="%b_i_XMLList" />
-  <PRIMITIVE gatewayId="68" primitiveId="35" primitiveName="%sp_i_XMLList" />
-  <PRIMITIVE gatewayId="68" primitiveId="36" primitiveName="%spb_i_XMLList" />
-  <PRIMITIVE gatewayId="68" primitiveId="37" primitiveName="%msp_i_XMLList" />
-  <PRIMITIVE gatewayId="68" primitiveId="38" primitiveName="%i_i_XMLList" />
-  <PRIMITIVE gatewayId="68" primitiveId="39" primitiveName="%h_i_XMLList" />
-  <PRIMITIVE gatewayId="68" primitiveId="40" primitiveName="%fptr_i_XMLList" />
-  <PRIMITIVE gatewayId="68" primitiveId="41" primitiveName="%mc_i_XMLList" />
-  <PRIMITIVE gatewayId="68" primitiveId="42" primitiveName="%l_i_XMLList" />
-  <PRIMITIVE gatewayId="68" primitiveId="43" primitiveName="%hm_i_XMLList" />
-  <PRIMITIVE gatewayId="68" primitiveId="44" primitiveName="%ptr_i_XMLList" />
-  <PRIMITIVE gatewayId="68" primitiveId="45" primitiveName="%ce_i_XMLList" />
-  <PRIMITIVE gatewayId="68" primitiveId="46" primitiveName="%st_i_XMLList" />
-  <PRIMITIVE gatewayId="68" primitiveId="47" primitiveName="%r_i_XMLList" />
-  <PRIMITIVE gatewayId="68" primitiveId="48" primitiveName="%lss_i_XMLList" />
-  <PRIMITIVE gatewayId="68" primitiveId="49" primitiveName="%ip_i_XMLList" />
-  <PRIMITIVE gatewayId="68" primitiveId="50" primitiveName="%XMLList_i_XMLList" />
-  <PRIMITIVE gatewayId="68" primitiveId="51" primitiveName="xmlReadStr" />
-  <PRIMITIVE gatewayId="68" primitiveId="52" primitiveName="xmlFormat" />
-  <PRIMITIVE gatewayId="68" primitiveId="53" primitiveName="xmlElement" />
-  <PRIMITIVE gatewayId="68" primitiveId="54" primitiveName="xmlDocument" />
-  <PRIMITIVE gatewayId="68" primitiveId="55" primitiveName="xmlNs" />
-  <PRIMITIVE gatewayId="68" primitiveId="56" primitiveName="xmlAddNs" />
-  <PRIMITIVE gatewayId="68" primitiveId="57" primitiveName="xmlGetNsByHref" />
-  <PRIMITIVE gatewayId="68" primitiveId="58" primitiveName="xmlGetNsByPrefix" />
-  <PRIMITIVE gatewayId="68" primitiveId="59" primitiveName="%XMLElem_6" />
-  <PRIMITIVE gatewayId="68" primitiveId="60" primitiveName="%XMLDoc_6" />
-  <PRIMITIVE gatewayId="68" primitiveId="61" primitiveName="%XMLNs_6" />
-  <PRIMITIVE gatewayId="68" primitiveId="62" primitiveName="%XMLAttr_6" />
-  <PRIMITIVE gatewayId="68" primitiveId="63" primitiveName="%XMLList_6" />
-  <PRIMITIVE gatewayId="68" primitiveId="64" primitiveName="%XMLSet_6" />
-  <PRIMITIVE gatewayId="68" primitiveId="65" primitiveName="xmlWrite" />
-  <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" />
-  <PRIMITIVE gatewayId="68" primitiveId="74" primitiveName="xmlIsValidObject" />
-  <PRIMITIVE gatewayId="68" primitiveId="75" primitiveName="xmlAsNumber" />
-  <PRIMITIVE gatewayId="68" primitiveId="76" primitiveName="xmlAsText" />
-  <PRIMITIVE gatewayId="68" primitiveId="77" primitiveName="xmlRemove" />
-  <PRIMITIVE gatewayId="68" primitiveId="78" primitiveName="xmlSetAttributes" />
+    <PRIMITIVE gatewayId="68" primitiveId="1" primitiveName="xmlRead" />
+    <PRIMITIVE gatewayId="68" primitiveId="2" primitiveName="xmlDelete" />
+    <PRIMITIVE gatewayId="68" primitiveId="3" primitiveName="xmlDump" />
+    <PRIMITIVE gatewayId="68" primitiveId="4" primitiveName="xmlGetOpenDocs" />
+    <PRIMITIVE gatewayId="68" primitiveId="5" primitiveName="xmlXPath" />
+    <PRIMITIVE gatewayId="68" primitiveId="6" primitiveName="%XMLDoc_e" />
+    <PRIMITIVE gatewayId="68" primitiveId="7" primitiveName="%XMLElem_e" />
+    <PRIMITIVE gatewayId="68" primitiveId="8" primitiveName="%XMLNs_e" />
+    <PRIMITIVE gatewayId="68" primitiveId="9" primitiveName="%XMLAttr_e" />
+    <PRIMITIVE gatewayId="68" primitiveId="10" primitiveName="%XMLList_e" />
+    <PRIMITIVE gatewayId="68" primitiveId="11" primitiveName="%XMLSet_e" />
+    <PRIMITIVE gatewayId="68" primitiveId="12" primitiveName="%XMLDoc_p" />
+    <PRIMITIVE gatewayId="68" primitiveId="13" primitiveName="%XMLElem_p" />
+    <PRIMITIVE gatewayId="68" primitiveId="14" primitiveName="%XMLNs_p" />
+    <PRIMITIVE gatewayId="68" primitiveId="15" primitiveName="%XMLList_p" />
+    <PRIMITIVE gatewayId="68" primitiveId="16" primitiveName="%XMLAttr_p" />
+    <PRIMITIVE gatewayId="68" primitiveId="17" primitiveName="%XMLSet_p" />
+    <PRIMITIVE gatewayId="68" primitiveId="18" primitiveName="%XMLList_size" />
+    <PRIMITIVE gatewayId="68" primitiveId="19" primitiveName="%XMLSet_size" />
+    <PRIMITIVE gatewayId="68" primitiveId="20" primitiveName="%XMLAttr_size" />
+    <PRIMITIVE gatewayId="68" primitiveId="21" primitiveName="%c_i_XMLDoc" />
+    <PRIMITIVE gatewayId="68" primitiveId="22" primitiveName="%XMLElem_i_XMLDoc" />
+    <PRIMITIVE gatewayId="68" primitiveId="23" primitiveName="%c_i_XMLElem" />
+    <PRIMITIVE gatewayId="68" primitiveId="24" primitiveName="%XMLElem_i_XMLElem" />
+    <PRIMITIVE gatewayId="68" primitiveId="25" primitiveName="%XMLAttr_i_XMLElem" />
+    <PRIMITIVE gatewayId="68" primitiveId="26" primitiveName="%XMLList_i_XMLElem" />
+    <PRIMITIVE gatewayId="68" primitiveId="27" primitiveName="%XMLNs_i_XMLElem" />
+    <PRIMITIVE gatewayId="68" primitiveId="28" primitiveName="%c_i_XMLAttr" />
+    <PRIMITIVE gatewayId="68" primitiveId="29" primitiveName="%XMLElem_i_XMLList" />
+    <PRIMITIVE gatewayId="68" primitiveId="30" primitiveName="%XMLDoc_i_XMLList" />
+    <PRIMITIVE gatewayId="68" primitiveId="31" primitiveName="%c_i_XMLList" />
+    <PRIMITIVE gatewayId="68" primitiveId="32" primitiveName="%s_i_XMLList" />
+    <PRIMITIVE gatewayId="68" primitiveId="33" primitiveName="%p_i_XMLList" />
+    <PRIMITIVE gatewayId="68" primitiveId="34" primitiveName="%b_i_XMLList" />
+    <PRIMITIVE gatewayId="68" primitiveId="35" primitiveName="%sp_i_XMLList" />
+    <PRIMITIVE gatewayId="68" primitiveId="36" primitiveName="%spb_i_XMLList" />
+    <PRIMITIVE gatewayId="68" primitiveId="37" primitiveName="%msp_i_XMLList" />
+    <PRIMITIVE gatewayId="68" primitiveId="38" primitiveName="%i_i_XMLList" />
+    <PRIMITIVE gatewayId="68" primitiveId="39" primitiveName="%h_i_XMLList" />
+    <PRIMITIVE gatewayId="68" primitiveId="40" primitiveName="%fptr_i_XMLList" />
+    <PRIMITIVE gatewayId="68" primitiveId="41" primitiveName="%mc_i_XMLList" />
+    <PRIMITIVE gatewayId="68" primitiveId="42" primitiveName="%l_i_XMLList" />
+    <PRIMITIVE gatewayId="68" primitiveId="43" primitiveName="%hm_i_XMLList" />
+    <PRIMITIVE gatewayId="68" primitiveId="44" primitiveName="%ptr_i_XMLList" />
+    <PRIMITIVE gatewayId="68" primitiveId="45" primitiveName="%ce_i_XMLList" />
+    <PRIMITIVE gatewayId="68" primitiveId="46" primitiveName="%st_i_XMLList" />
+    <PRIMITIVE gatewayId="68" primitiveId="47" primitiveName="%r_i_XMLList" />
+    <PRIMITIVE gatewayId="68" primitiveId="48" primitiveName="%lss_i_XMLList" />
+    <PRIMITIVE gatewayId="68" primitiveId="49" primitiveName="%ip_i_XMLList" />
+    <PRIMITIVE gatewayId="68" primitiveId="50" primitiveName="%XMLList_i_XMLList" />
+    <PRIMITIVE gatewayId="68" primitiveId="51" primitiveName="xmlReadStr" />
+    <PRIMITIVE gatewayId="68" primitiveId="52" primitiveName="xmlFormat" />
+    <PRIMITIVE gatewayId="68" primitiveId="53" primitiveName="xmlElement" />
+    <PRIMITIVE gatewayId="68" primitiveId="54" primitiveName="xmlDocument" />
+    <PRIMITIVE gatewayId="68" primitiveId="55" primitiveName="xmlNs" />
+    <PRIMITIVE gatewayId="68" primitiveId="56" primitiveName="xmlAddNs" />
+    <PRIMITIVE gatewayId="68" primitiveId="57" primitiveName="xmlGetNsByHref" />
+    <PRIMITIVE gatewayId="68" primitiveId="58" primitiveName="xmlGetNsByPrefix" />
+    <PRIMITIVE gatewayId="68" primitiveId="59" primitiveName="%XMLElem_6" />
+    <PRIMITIVE gatewayId="68" primitiveId="60" primitiveName="%XMLDoc_6" />
+    <PRIMITIVE gatewayId="68" primitiveId="61" primitiveName="%XMLNs_6" />
+    <PRIMITIVE gatewayId="68" primitiveId="62" primitiveName="%XMLAttr_6" />
+    <PRIMITIVE gatewayId="68" primitiveId="63" primitiveName="%XMLList_6" />
+    <PRIMITIVE gatewayId="68" primitiveId="64" primitiveName="%XMLSet_6" />
+    <PRIMITIVE gatewayId="68" primitiveId="65" primitiveName="xmlWrite" />
+    <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" />
+    <PRIMITIVE gatewayId="68" primitiveId="74" primitiveName="xmlIsValidObject" />
+    <PRIMITIVE gatewayId="68" primitiveId="75" primitiveName="xmlAsNumber" />
+    <PRIMITIVE gatewayId="68" primitiveId="76" primitiveName="xmlAsText" />
+    <PRIMITIVE gatewayId="68" primitiveId="77" primitiveName="xmlRemove" />
+    <PRIMITIVE gatewayId="68" primitiveId="78" primitiveName="xmlSetAttributes" />
+    <PRIMITIVE gatewayId="68" primitiveId="79" primitiveName="xmlName" />
 </GATEWAY>
index d56f9e7..85ca461 100644 (file)
@@ -38,30 +38,38 @@ int createXMLObjectAtPos(int type, int pos, int id, void *pvApiCtx)
 
     switch (type)
     {
-    case XMLDOCUMENT:;
-        fields = _XMLDoc;
-        break;
-    case XMLELEMENT:;
-        fields = _XMLElem;
-        break;
-    case XMLATTRIBUTE:;
-        fields = _XMLAttr;
-        break;
-    case XMLNAMESPACE:;
-        fields = _XMLNs;
-        break;
-    case XMLLIST:;
-        fields = _XMLList;
-        break;
-    case XMLNOTHANDLED:;
-        fields = _XMLNotHandled;
-        break;
-    case XMLSET:;
-        fields = _XMLSet;
-        break;
-    case XMLVALID:;
-        fields = _XMLValid;
-        break;
+        case XMLDOCUMENT:
+            ;
+            fields = _XMLDoc;
+            break;
+        case XMLELEMENT:
+            ;
+            fields = _XMLElem;
+            break;
+        case XMLATTRIBUTE:
+            ;
+            fields = _XMLAttr;
+            break;
+        case XMLNAMESPACE:
+            ;
+            fields = _XMLNs;
+            break;
+        case XMLLIST:
+            ;
+            fields = _XMLList;
+            break;
+        case XMLNOTHANDLED:
+            ;
+            fields = _XMLNotHandled;
+            break;
+        case XMLSET:
+            ;
+            fields = _XMLSet;
+            break;
+        case XMLVALID:
+            ;
+            fields = _XMLValid;
+            break;
     }
 
     err = createMList(pvApiCtx, pos, 2, &mlistaddr);
@@ -104,30 +112,38 @@ int createXMLObjectAtPosInList(int *list, int stackPos, int type, int pos, int i
 
     switch (type)
     {
-    case XMLDOCUMENT:;
-        fields = _XMLDoc;
-        break;
-    case XMLELEMENT:;
-        fields = _XMLElem;
-        break;
-    case XMLATTRIBUTE:;
-        fields = _XMLAttr;
-        break;
-    case XMLNAMESPACE:;
-        fields = _XMLNs;
-        break;
-    case XMLLIST:;
-        fields = _XMLList;
-        break;
-    case XMLNOTHANDLED:;
-        fields = _XMLNotHandled;
-        break;
-    case XMLSET:;
-        fields = _XMLSet;
-        break;
-    case XMLVALID:;
-        fields = _XMLValid;
-        break;
+        case XMLDOCUMENT:
+            ;
+            fields = _XMLDoc;
+            break;
+        case XMLELEMENT:
+            ;
+            fields = _XMLElem;
+            break;
+        case XMLATTRIBUTE:
+            ;
+            fields = _XMLAttr;
+            break;
+        case XMLNAMESPACE:
+            ;
+            fields = _XMLNs;
+            break;
+        case XMLLIST:
+            ;
+            fields = _XMLList;
+            break;
+        case XMLNOTHANDLED:
+            ;
+            fields = _XMLNotHandled;
+            break;
+        case XMLSET:
+            ;
+            fields = _XMLSet;
+            break;
+        case XMLVALID:
+            ;
+            fields = _XMLValid;
+            break;
     }
 
     err = createMatrixOfStringInList(pvApiCtx, stackPos, mlistaddr, 1, 1, 2, fields);
@@ -193,14 +209,21 @@ int isXMLSet(int *mlist, void *pvApiCtx)
 int isXMLValid(int *mlist, void *pvApiCtx)
 {
     return compareStrToMlistType(XMLObjects + 7, 1, mlist, pvApiCtx);
-}/*--------------------------------------------------------------------------*/
+}
 
+/*--------------------------------------------------------------------------*/
 int isXMLObject(int *mlist, void *pvApiCtx)
 {
     return compareStrToMlistType(XMLObjects, NB_XMLOBJECTS, mlist, pvApiCtx);
 }
 
 /*--------------------------------------------------------------------------*/
+int isXMLObjects(const char ** types, int nb, int *mlist, void *pvApiCtx)
+{
+    return compareStrToMlistType(types, nb, mlist, pvApiCtx);
+}
+
+/*--------------------------------------------------------------------------*/
 int getXMLObjectId(int *mlist, void *pvApiCtx)
 {
     int *id = NULL;
diff --git a/scilab/modules/xml/tests/unit_tests/xmlName.dia.ref b/scilab/modules/xml/tests/unit_tests/xmlName.dia.ref
new file mode 100644 (file)
index 0000000..a85a94f
--- /dev/null
@@ -0,0 +1,16 @@
+// ===========================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
+//
+//  This file is distributed under the same license as the Scilab package.
+// ===========================================================================
+doc = xmlReadStr("<root><foo a=""123"" b=""456"" c=""789""/></root>")
+ doc  =
+XML Document
+URL: Undefined
+assert_checkequal(xmlName(doc.root.children(1)),"foo");
+assert_checkequal(xmlName(doc.root.children(1).attributes),["a" "b" "c"]);
+assert_checkequal(xmlName(xmlXPath(doc,"//foo/@*")),["a" "b" "c"]);
+assert_checkequal(xmlName(xmlXPath(doc,"//foo")),"foo");
+xmlDelete(doc);
diff --git a/scilab/modules/xml/tests/unit_tests/xmlName.tst b/scilab/modules/xml/tests/unit_tests/xmlName.tst
new file mode 100644 (file)
index 0000000..023bf0e
--- /dev/null
@@ -0,0 +1,16 @@
+// ===========================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
+//
+//  This file is distributed under the same license as the Scilab package.
+// ===========================================================================
+
+
+doc = xmlReadStr("<root><foo a=""123"" b=""456"" c=""789""/></root>")
+
+assert_checkequal(xmlName(doc.root.children(1)),"foo");
+assert_checkequal(xmlName(doc.root.children(1).attributes),["a" "b" "c"]);
+assert_checkequal(xmlName(xmlXPath(doc,"//foo/@*")),["a" "b" "c"]);
+assert_checkequal(xmlName(xmlXPath(doc,"//foo")),"foo");
+
+xmlDelete(doc);
\ No newline at end of file
index 477b21f..aef8c94 100644 (file)
     <ClCompile Include="sci_gateway\cpp\sci_xmlGetNsByPrefix.cpp" />
     <ClCompile Include="sci_gateway\cpp\sci_xmlGetOpenDocs.cpp" />
     <ClCompile Include="sci_gateway\cpp\sci_xmlIsValidObject.cpp" />
+    <ClCompile Include="sci_gateway\cpp\sci_xmlName.cpp" />
     <ClCompile Include="sci_gateway\cpp\sci_xmlNs.cpp" />
     <ClCompile Include="sci_gateway\cpp\sci_xmlRead.cpp" />
     <ClCompile Include="sci_gateway\cpp\sci_xmlReadStr.cpp" />
index 0193bf9..9523a2d 100644 (file)
     <ClCompile Include="sci_gateway\cpp\sci_xmlSetAttributes.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="sci_gateway\cpp\sci_xmlName.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>
\ No newline at end of file