Update of /cvsroot/eas-dev/clip-xml/example In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv4527 Added Files: Makefile XPath_tests.tar.gz c.xml component.dtd component.xml currency.xml test-koi8-r.xml test.prg test_xml.prg Log Message: Add files --- NEW FILE: Makefile --- # CLIP-XML library examples Makefile # Copyright (C) 2006, E/AS Software Foundation # Web: http://eas.lrn.ru # Copyright (C) 2006, ITK # Web: http://www.itk.ru ifndef CLIPROOT CLIPROOT=$(shell cd ../../../../; pwd)/cliproot endif include $(CLIPROOT)/include/Makefile.inc CLIPINCLUDE = -I$(CLIPROOT)/include CLIP = $(CLIPROOT)/bin/clip C_FLAGS=-g .SUFFIXES: .prg .o .po .PHONY: all clean # Widget tests LIBS=-lclip-xml PROGS=test_xml test EXTRALIBS= all: $(PROGS) clean: rm -f *.o core* *core $(PROGS) *.log *.nm *.ex *.exe $(OUTPUT) rm -f *.exe *.c *.o *.a *.so *.po *.log *.pa *.b *.BAK *.bak *~ core* *core rm -rf *.ex *.nm test_xml: test_xml.prg $(CLIP) -ewsln $(C_FLAGS) $(CLIPINCLUDE) test_xml.prg $(LIBS) $(EXTRALIBS) test: test.prg clip -esg test.prg $(LIBS) --- NEW FILE: XPath_tests.tar.gz --- (This appears to be a binary file; contents omitted.) --- NEW FILE: c.xml --- (This appears to be a binary file; contents omitted.) --- NEW FILE: component.dtd --- <!-- DTD for CLIP component format Version: 1.0rc Date: 06 Apr 2006 Author: Andrey Cherepanov <sib...@ma...> Last version: http://eas.lrn.ru/dtd/component.dtd For check component XML type: xmllint -noout -dtdvalid component.dtd <component.xml> (replace '-' by double '-') --> <!-- Root tag --> <!ELEMENT component ( name, version, category*, description?, license?, created?, modified?, author*, property*, requires?, commands?, files?, dictionary?, meta*, data*, install?, uninstall?, locale* )* > <!-- Component name. Required. --> <!ELEMENT name (#PCDATA)> <!-- Component category (path delimited by '/': Base/Directories/Finance). Optional. --> <!ELEMENT category (#PCDATA)> <!-- Component brief description. Optional. --> <!ELEMENT description (#PCDATA)> <!-- Component version. Required. --> <!ELEMENT version (#PCDATA)> <!-- Component license. Optional. --> <!ELEMENT license (#PCDATA)> <!-- Component creation date (yyyy-mm-dd). Optional. --> <!ELEMENT created (#PCDATA)> <!-- Component modification date (yyyy-mm-dd). Optional. --> <!ELEMENT modified (#PCDATA)> <!-- Component author. Optional. --> <!ELEMENT author (#PCDATA|name|email|copyright)*> <!ELEMENT email (#PCDATA)> <!ELEMENT copyright (#PCDATA)> <!-- Custom property. Optional. --> <!ELEMENT property (#PCDATA)> <!ATTLIST property name CDATA #REQUIRED > <!-- Component requirements. Optional. --> <!ELEMENT requires (dependence*)> <!ELEMENT dependence (#PCDATA)> <!ATTLIST dependence type CDATA #REQUIRED version CDATA #IMPLIED > <!ELEMENT function (#PCDATA)> <!-- Component requires. Optional. --> <!ELEMENT commands (plugin*)> <!ELEMENT plugin (code?, command+)> <!ATTLIST plugin name CDATA #IMPLIED > <!ELEMENT code (#PCDATA)> <!ELEMENT command (#PCDATA)> <!-- Component files. Optional. --> <!ELEMENT files (file*)> <!ELEMENT file (#PCDATA)> <!ATTLIST file name CDATA #REQUIRED form CDATA #IMPLIED type CDATA #IMPLIED > <!-- Dictionary --> <!ELEMENT dictionary ( id, name, type?, path, dbUser? )> <!ELEMENT id (#PCDATA)> <!ELEMENT type (#PCDATA)> <!ELEMENT path (#PCDATA)> <!ELEMENT dbUser (#PCDATA)> <!-- Database structure and data. Optional. --> <!ELEMENT meta ( depository| extent| attribute| index| class| counter| tcolumn| tview| report| plugin| user| group)*> <!ATTLIST meta dictionary CDATA #REQUIRED > <!-- Depository --> <!ELEMENT depository (#PCDATA)> <!ATTLIST depository id ID #IMPLIED name CDATA #REQUIRED number CDATA #IMPLIED memoSize CDATA #IMPLIED > <!-- Extent --> <!ELEMENT extent (#PCDATA)> <!ATTLIST extent id ID #IMPLIED name CDATA #REQUIRED > <!-- Attribute --> <!ELEMENT attribute (#PCDATA)> <!ATTLIST attribute id ID #IMPLIED name CDATA #REQUIRED type (string|number|date|logical|text|object|any|ref|classref|array|code) #REQUIRED len CDATA #IMPLIED dec CDATA #IMPLIED lenType (ignore|rtrim|alltrim|fill) #IMPLIED refTo CDATA #IMPLIED defValue CDATA #IMPLIED counter CDATA #IMPLIED notNull (yes|no|true|false) #IMPLIED notEmpty (yes|no|true|false) #IMPLIED mask CDATA #IMPLIED source CDATA #IMPLIED code CDATA #IMPLIED count CDATA #IMPLIED > <!-- Index --> <!ELEMENT index (#PCDATA)> <!ATTLIST index id ID #IMPLIED name CDATA #REQUIRED expression CDATA #REQUIRED > <!-- Class --> <!ELEMENT class (#PCDATA|object)*> <!ATTLIST class id ID #IMPLIED name CDATA #REQUIRED superClass CDATA #IMPLIED extent CDATA #IMPLIED essence CDATA #IMPLIED expression CDATA #IMPLIED uniqueKey CDATA #IMPLIED logNeed (yes|no|true|false) #IMPLIED hasCounters (yes|no|true|false) #IMPLIED attributes CDATA #IMPLIED indices CDATA #IMPLIED > <!-- Counter --> <!ELEMENT counter (#PCDATA)> <!ATTLIST counter id ID #IMPLIED name CDATA #REQUIRED value CDATA #REQUIRED type CDATA #IMPLIED depository CDATA #IMPLIED maxValue CDATA #IMPLIED lastValue CDATA #IMPLIED > <!-- TColumn --> <!ELEMENT tcolumn (#PCDATA)> <!ATTLIST tcolumn id ID #IMPLIED name CDATA #REQUIRED header CDATA #IMPLIED footer CDATA #IMPLIED width CDATA #IMPLIED expression CDATA #IMPLIED depend CDATA #IMPLIED ref CDATA #IMPLIED > <!-- TView --> <!ELEMENT tview (#PCDATA)> <!ATTLIST tview id ID #IMPLIED name CDATA #REQUIRED class CDATA #IMPLIED extent CDATA #IMPLIED group CDATA #IMPLIED user CDATA #IMPLIED header CDATA #IMPLIED footer CDATA #IMPLIED columns CDATA #IMPLIED > <!-- Report--> <!ELEMENT report (#PCDATA)> <!ATTLIST report id ID #IMPLIED name CDATA #REQUIRED type CDATA #IMPLIED file CDATA #IMPLIED class CDATA #IMPLIED extent CDATA #IMPLIED group CDATA #IMPLIED user CDATA #IMPLIED > <!-- Plugin --> <!ELEMENT plugin (#PCDATA)> <!ATTLIST plugin id ID #IMPLIED name CDATA #REQUIRED class CDATA #IMPLIED type CDATA #IMPLIED file CDATA #IMPLIED function CDATA #IMPLIED > <!-- User --> <!ELEMENT user (#PCDATA)> <!ATTLIST user id ID #IMPLIED name CDATA #REQUIRED group CDATA #IMPLIED access CDATA #IMPLIED > <!-- Group --> <!ELEMENT group (#PCDATA)> <!ATTLIST group id ID #IMPLIED name CDATA #REQUIRED > <!-- Default data --> <!ELEMENT data ( objects* )> <!ELEMENT objects (object+)> <!ATTLIST objects class CDATA #REQUIRED depository CDATA #REQUIRED > <!-- Object contents --> <!ELEMENT object (attr+)> <!ATTLIST object id ID #IMPLIED > <!ELEMENT attr (#PCDATA|value)*> <!ATTLIST attr name CDATA #REQUIRED refTo CDATA #IMPLIED > <!ELEMENT value (#PCDATA|value)*> <!ATTLIST value type (string|number|date|logical|text|object|any|ref|classref|array|code) #REQUIRED refTo CDATA #IMPLIED meta CDATA #IMPLIED > <!-- Install actions. Optional. --> <!ELEMENT install (#PCDATA)> <!-- Uninstall actions. Optional. --> <!ELEMENT uninstall (#PCDATA)> <!-- Component l10n. Optional. --> <!ELEMENT locale (name?, description?, message*)> <!ATTLIST locale lang CDATA #REQUIRED > <!ELEMENT message (#PCDATA)> <!ATTLIST message id CDATA #REQUIRED > --- NEW FILE: component.xml --- <?xml version="1.0" encoding="utf-8" standalone="no" ?> <component> <name>currency</name> <version>1.0</version> <category>Base/Directories/Finance</category> <description>Currency directory</description> <license>This component in released under the GNU/GPL License</license> <created>2005-12-21</created> <modified>2006-01-16</modified> <author> <name>Andrey Cherepanov</name> <email>su...@ea...</email> <copyright>2006</copyright> </author> <author>uri</author> <property name="policy">ru.Ru</property> <property name="info">http://eas.lrn.ru/components/currency.xml</property> <property name="download">http://eas.lrn.ru/components/currency.component</property> <property name="documentation"><![CDATA[ This is documentation on component currency ]]></property> <requires> <dependence type="component">forms</dependence> </requires> <commands> <plugin name="currency.po"> <command>getCourse</command> </plugin> </commands> <files> <file name="create.xpm">Icon for create action</file> <file name="edit.xpm">edit.xpm</file> <file name="delete.xpm">delete.xpm</file> <file form="list/currency" name="currency_list.xfl"></file> <file form="object/currency" name="currency.xfl"></file> <file name="currency.xpm">currency.xpm</file> </files> <meta dictionary="ETC01"> <!-- Depositories --> <depository name="ETC0101" /> <!-- Attributes --> <attribute name="name" type="string" len="30" notNull="yes" notEmpty="yes"> Currency name </attribute> <attribute name="ncode" type="string" len="3" /> <attribute name="code" type="string" len="3" /> <!-- Indeces --> <index name="ncode" expression="ncode" /> <index name="code" expression="code" /> <!-- Classes --> <class name="currency" attributes="ncode,code,name" indices="ncode,code"> Class for currencies </class> </meta> <!-- Default data --> <data> <objects class="currency" depository="ETC0101"> <object> <attr name="ncode">001</attr> <attr name="code">USD</attr> <attr name="name">ÐÐ¾Ð»Ð»Ð°Ñ Ð¡Ð¨Ð</attr> </object> </objects> </data> <install> <!-- custom install actions --> </install> <uninstall> <!-- custom uninstall actions --> </uninstall> <locale lang="ru"> <name>ÐалÑÑÑ</name> <description>СпÑавоÑник валÑÑ</description> <message id="Currency name">Ðазвание валÑÑÑ</message> <message id="Class for currencies">ÐалÑÑÑ</message> </locale> </component> --- NEW FILE: currency.xml --- <?xml version="1.0" encoding="koi8-r" ?> <package> <name>currency</name> <category>goscomstatinfo</category> <documentation> lalala1 lalala2 </documentation> <version>1.0</version> <license>GNU/GPL</license> <creationDate>2006-03-10</creationDate> <author> <authorName>ITK</authorName> <authorEmail>ur...@it...</authorEmail> </author> [...1147 lines suppressed...] <attr name="name">ìÁÒÉ</attr> <attr name="smallname">çÒÕÚÉÑ</attr> </object> <object> <attr name="code">985</attr> <attr name="unit">òLN</attr> <attr name="name">úÌÏÔÙÊ</attr> <attr name="smallname">ðÏÌØÛÁ</attr> </object> <object> <attr name="code">986</attr> <attr name="unit">BRL</attr> <attr name="name">âÒÁÚÉÌØÓËÉÊ ÒÅÁÌ</attr> <attr name="smallname">âÒÁÚÉÌÉÑ</attr> </object> </class> </data> </package> --- NEW FILE: test-koi8-r.xml --- (This appears to be a binary file; contents omitted.) --- NEW FILE: test.prg --- #include <clip-expat.ch> function main() local parser, aa if pcount() == 0 ? "Call test <filename.xml>" return endif filename = param(1) if empty(filename) filename = "component.xml" endif tm := seconds() parser = xml_ParserCreate() ? "parser:",parser aa = 0 xml_SetUserData(parser, @aa) xml_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_NEVER) xml_SetCharacterDataHandler(parser, @myfunc()) //xml_SetStartElementHandler(parser, @myStartElement()) //xml_SetEndElementHandler(parser, @myEndElement()) xml_SetElementHandler(parser, @myStartElement(), @myEndElement()) xml_SetCommentHandler(parser, @myComment()) xml_SetCdataSectionHandler(parser, @myStartCdata(), @myEndCdata()) file = fopen(filename) do while !fileeof(file) buf = filegetstr(file, 1024) //? "buf=", buf xml_Parse(parser, buf, len(buf), fileeof(file)) if xml_GetErrorCode(parser) <> 0 ? "Error in XML (" + alltrim(str(xml_GetErrorCode(parser))) + "): " + xml_ErrorString(parser) ?? " at line "+alltrim(str(xml_GetCurrentLineNumber(parser))) ?? ", column "+alltrim(str(xml_GetCurrentColumnNumber(parser))) endif enddo //? "end parse line",xml_GetCurrentLineNumber(parser) fclose(file) xml_ParserFree(parser) ? "" ? "free" ? "Processed time:", seconds()-tm, "sec" ? return function myfunc(aa, str, len) ? replicate("&\t", aa), '"'+str+'"' return function myStartElement(aa, name, arrAttr) ? replicate("&\t", aa),"<"+name+">" for i=1 to len(arrAttr) ? replicate("&\t", aa+1), arrAttr[i] next aa++ return function myEndElement(aa, name) aa-- ? replicate("&\t", aa),"</"+ name+">" return function myComment(aa, data) ? replicate("&\t", aa),"/* "+ data+ "*/" return function myStartCdata(aa) ? replicate("&\t", aa),"<![CDATA[" aa++ return function myEndCdata(aa) aa-- ? replicate("&\t", aa),"]]>" return --- NEW FILE: test_xml.prg --- /** Test program for XMLTree */ #define SPACER ' ' #define VERBOSE .F. /* TODO: decorated output for XPath result */ function main( cmd, path ) local f, tm, c, t1, t2, t3, i, node, tstr, attr tm := seconds() // Create XMLTree object f := XMLTree() // "koi8-r" ) if cmd != 'dump' .and. cmd != 'create' if VERBOSE; ?? "XMLTree() created&\n"; endif endif if cmd != 'create' // Parse file if .not. f:parseFile( "component.xml" ) // Output error description and exit ?? "ERROR:", f:getError(), chr(10) return 1 endif else // Create root tag t1 := XMLTag( "languages" ) f:setRoot( t1 ) // Create two child tags and fill texts and attributes t2 := XMLTag( "lang" ) t2:setAttribute( "code", "en" ) t2:setText( "English" ) t3 := XMLTag( "lang" ) t3:setAttribute( "code", "ru" ) t3:setText( "òÕÓÓËÉÊ" ) // Add child tags t1:addChild( t2 ) t1:addChild( t3 ) endif if cmd != 'dump' .and. cmd != 'create' if VERBOSE; ?? "parseFile(&\"component.xml&\") done&\n"; endif endif switch cmd case 'count' c := map() c:tags := 0 c:text := 0 countTags( f:getRoot(), c ) ?? "Tags:", c:tags, chr(10) ?? "Text:", c:text, "characters", chr(10) case 'dump' ?? f:dump() case 'create' ?? f:dump() case 'path' c := f:XPath( path ) if .not. empty( xml_XPathError() ) ?? "ERROR:", xml_XPathError(),chr(10) return 1 endif if valtype(c) == 'A' for i:=1 to len(c) node := c[i] if valtype(node) == 'O' tstr := "<" + node:getName() for attr in node:getAttributes() tstr += " " + attr[1] + '="' + attr[2] + '"' next tstr += ">" + node:getText() + "</" + node:getName() + ">" ?? tstr + chr(10) else ?? c,chr(10) endif next else ?? c,chr(10) endif otherwise ?? "Available commands:&\n" ?? " count Count all tags and text characters&\n" ?? " create Manually create simple XML file &\n" ?? " dump Dump tree as XML file&\n" ?? " path <XPath> Show elements selected by XPath&\n" endswitch if cmd != 'dump' .and. cmd != 'create' if VERBOSE; ?? "Processed time:", alltrim(str(seconds()-tm)), "sec&\n"; endif endif return 0 function countTags( tag, counter ) local i counter:tags++ counter:text += len(tag:text) for i in tag:childs countTags( i, counter ) next return |