Author Topic: Missing documentation for XML module  (Read 27376 times)

votan

  • Guest
Missing documentation for XML module
« on: January 30, 2010, 05:10:26 AM »
I'm trying to do some XML parsing right now, but the chm help file does not contain any information for most of the xml commands.
Maybe someone here know this module and can give simple examples for every command?

Thanx in advance...

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
Re: Missing documentation for XML module
« Reply #1 on: January 30, 2010, 09:21:12 AM »
Code: [Select]
module xml

REM """
The module xml.bas is based on the Gnome libxml2 library.
"""
' FUNCTION DECLARATIONS
declare sub     ::ParseFile    alias "sbxmlParseFile"     lib "xml"
declare sub     ::NewDoc       alias "sbxmlNewDoc"        lib "xml"
declare sub     ::FreeDoc      alias "sbxmlFreeDoc"       lib "xml"
declare sub     ::GetChildren  alias "getchildren"        lib "xml"
declare sub     ::SetChildren  alias "setchildren"        lib "xml"
declare sub     ::GetNext      alias "getnext"            lib "xml"
declare sub     ::SetNext      alias "setnext"            lib "xml"
declare sub     ::GetPrev      alias "getprev"            lib "xml"
declare sub     ::SetPrev      alias "setprev"            lib "xml"
declare sub     ::GetParent    alias "getparent"          lib "xml"
declare sub     ::SetParent    alias "setparent"          lib "xml"
declare sub     ::SetProp      alias "sbxmlSetProp"       lib "xml"
declare sub     ::GetProp      alias "sbxmlGetProp"       lib "xml"
declare sub     ::NewNs        alias "sbxmlNewNs"         lib "xml"
declare sub     ::FreeNs       alias "sbxmlFreeNs"        lib "xml"
declare sub     ::NewChild     alias "sbxmlNewChild"      lib "xml"
declare sub     ::NewTextChild alias "sbxmlNewTextChild"  lib "xml"
declare sub     ::NewDocNode   alias "sbxmlNewDocNode"    lib "xml"
declare sub     ::Doc2XML      alias "sbxmlDocDumpMemory" lib "xml"

end module

The XML extension module was released in 2.0 but only with a minimal function interface and documentation.

http://xmlsoft.org/

If you find some time to expand the XML extension module to cover more of the libxml2 API, please share.


votan

  • Guest
Re: Missing documentation for XML module
« Reply #2 on: January 30, 2010, 10:27:35 AM »
Yes, already took a look at the source... but am not so good in C....
Problem is that I can'T find out the exact syntax to get an XML node by it's name...
For example... my xml file looks like:
<stufflist>
<stuff_test>This is a test!</stuff_test>
<stuff_test2>And this is another test!</stuff_test2>
</stufflist>

Now I need to get the right command with the right syntax to fetch the text content of <stuff_test2>

Maybe you know the syntax?

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
Re: Missing documentation for XML module
« Reply #3 on: January 30, 2010, 07:53:55 PM »
As mentioned before, XML support is a first cut effort and seeing there is no working example programs I know of, looks like your pretty much on your own. Maybe someone else on the forum has used this extension module and can help you out.

Use the libxml2 link I posted and find the corresponding functions indicated by the alias function name in their docs. This should give your the required arguments and types. The interface.c file for the XML extension module should be easy enough to understand to get the functions in place working under scriba/sbhttpd.

Good luck and if you get something working please share.

If I find some time, I'll try and document what is there and create an example to get started with.

If I remember correctly, Armando wrote a quick SB XML program to test the module for the 2.1 release. Maybe he still has it floating around.
« Last Edit: January 30, 2010, 08:54:25 PM by support »

votan

  • Guest
Re: Missing documentation for XML module
« Reply #4 on: February 02, 2010, 08:38:44 AM »
Just talked to Armando, but he said he also asked you for an XML example a longer time ago, but never heared back from you.
So seem that you are the only one who can help with the XML module...
BTW... using print xml::GetProp("text","name","node") kills the server service under windows ....
For you it's propably just a short look at the source of the module to see how the commands need to be used!?
Would be cool if you could look at it...

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
Re: Missing documentation for XML module
« Reply #5 on: February 02, 2010, 06:15:06 PM »
I'll add it to the wish list.  8)


Try GetProp(NodeHandle, PropName) as the argument structure being passed.

FYI: Save yourself a lot of time and grief by first testing your code (especially when using extension modules) with the command line interpreter (scriba) before using the app server. If it works under scriba, it will work on the app server variation.



« Last Edit: February 02, 2010, 07:44:22 PM by support »

Airr

  • Guest
Re: Missing documentation for XML module
« Reply #6 on: July 01, 2010, 10:39:42 PM »
I know this is an old post, but anyway....

GetProp doesn't seem to be "exported":

Code: [Select]
SLFST XML_SLFST[] ={
{ "versmodu" , versmodu },
{ "bootmodu" , bootmodu },
{ "finimodu" , finimodu },
{ "emsgmodu" , emsgmodu },
{ "sbxmlParseFile"     , sbxmlParseFile     },
{ "sbxmlNewDoc"        , sbxmlNewDoc        },
{ "sbxmlFreeDoc"       , sbxmlFreeDoc       },
{ "sbxmlNewNs"         , sbxmlNewNs         },
{ "sbxmlFreeNs"        , sbxmlFreeNs        },
{ "getchildren"        , getchildren        },
{ "setchildren"        , setchildren        },
{ "getnext"            , getnext            },
{ "setnext"            , setnext            },
{ "getprev"            , getprev            },
{ "setprev"            , setprev            },
{ "sbxmlSetProp"       , sbxmlSetProp       },
{ "sbxmlNewChild"      , sbxmlNewChild      },
{ "sbxmlNewTextChild"  , sbxmlNewTextChild  },
{ "sbxmlNewDocNode"    , sbxmlNewDocNode    },
{ "sbxmlDocDumpMemory" , sbxmlDocDumpMemory },
{ NULL , NULL }
  };

I'm playing around with mini-xml as a replacement for libxml.  The static library of libxml is about 3megs now.  mini-xml's static lib is about 250k, with debugging turned on (should be about 40-90k without).

Additionally, libxml has additional external dependencies, whereas the only dependency that mini-xml has is pthreads, which any decent C compiler already provides.

Quick example in C, using votan's example xml file:

Code: C
  1. #include <mxml.h>
  2. #include <stdio.h>
  3.  
  4. #define filename "stuff.xml"
  5.  
  6. int main()
  7. {
  8.         // declare variables
  9.         mxml_node_t *rootNode, *childNode;
  10.  
  11.  
  12.         // try opening the file
  13.         FILE *fp = fopen(filename, "r"); // open the xml file
  14.  
  15.        // check if file exists
  16.        if(fp == NULL) {
  17.            perror("\""filename"\"");
  18.            return -1;
  19.        }
  20.  
  21.         // load the file into an xml ROOT node
  22.         rootNode = mxmlLoadFile(NULL, fp, MXML_OPAQUE_CALLBACK);
  23.        
  24.         // file's loaded, close the handle
  25.         if (fp) fclose(fp);
  26.  
  27.         // get the first value and print
  28.         childNode = mxmlFindElement(rootNode,rootNode,"stuff_test",NULL,NULL,MXML_DESCEND);
  29.         if (childNode) printf("Test1: %s\n", childNode->child->value.opaque);
  30.        
  31.         // get the second value and print
  32.         childNode = mxmlFindElement(rootNode,rootNode,"stuff_test2",NULL,NULL,MXML_DESCEND);
  33.         if (childNode) printf("Test2: %s\n", childNode->child->value.opaque);
  34.  
  35.         // Free the xml doc
  36.         if (rootNode) mxmlDelete(rootNode);
  37.        
  38.         return 0;
  39. }
  40.  

Output:

C:\tmp>xmltest2
Test1: This is a test!
Test2: And this is another test!


The xml file:
Code: [Select]
<?xml version="1.0" encoding="UTF-8" ?>

<stufflist>
<stuff_test>This is a test!</stuff_test>
<stuff_test2>And this is another test!</stuff_test2>
</stufflist>

A.
« Last Edit: July 01, 2010, 10:44:13 PM by Airr »

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
Re: Missing documentation for XML module
« Reply #7 on: July 02, 2010, 04:57:13 AM »
Quote
I'm playing around with  mini-xml as a replacement for libxml.  The static library of libxml is about 3megs now.  mini-xml's static lib is about 250k, with debugging turned on (should be about 40-90k without).

That's great news Armando. I will be happy to test your new XML extension module when your ready.