Commit edd5b572 authored by Ivan Donchevskiy's avatar Ivan Donchevskiy

/include /src/Various /Utilities/UniXmlTest Function for UniXML to find nodes…

/include /src/Various /Utilities/UniXmlTest Function for UniXML to find nodes with parameters width and depth of search. Test for it.
parent a9ecd155
############################################################################
# This file is part of the UniSet library #
############################################################################
bin_PROGRAMS = xmltest
xmltest_SOURCES = XmlTest.cc
xmltest_LDADD = $(top_builddir)/lib/libUniSet.la
xmltest_CPPFLAGS = -I$(top_builddir)/include
include $(top_builddir)/conf/setting.mk
/* This file is part of the UniSet project
* Copyright (c) 2009 Free Software Foundation, Inc.
* Copyright (c) 2009 Ivan Donchevskiy
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// --------------------------------------------------------------------------
/*! \file
* \author Ivan Donchevskiy
* \date $Date: 2009/07/15 15:55:00 $
* \version $Id: Jrn.h,v 1.0 2009/07/28 16:55:00 vpashka Exp $
*/
// --------------------------------------------------------------------------
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "UniXML.h"
int main()
{
UniXML* f = new UniXML();
f->newDoc("journal");
xmlNode *cur,*beg;
beg=cur=f->createChild(f->cur,"0","");
char* ch = new char[10];
for(int j=1;j<30;j++)
{
sprintf(ch,"%d",j);
cur=f->createNext(cur,ch,"");
f->setProp(cur,"name",ch);
}
for(int j=0;j<10;j++)
{
sprintf(ch,"%d",j);
cur=f->createChild(cur,ch,"");
f->setProp(cur,"name",ch);
for(int i=0;i<10;i++)
{
sprintf(ch,"%d",i*j);
cur=f->createNext(cur,ch,"");
f->setProp(cur,"name",ch);
}
}
bool testPassed=true;
if(f->extFindNode(beg,9,30,"72","72")!=0)
printf("correct, \"72\" has width 30 and depth 9\n");
else testPassed=false;
if(f->extFindNode(beg,9,29,"72","72")==0)
printf("correct, \"72\" has width more than 29\n");
else testPassed=false;
if(f->extFindNode(beg,8,30,"72","72")==0)
printf("correct, \"72\" has depth more than 8\n");
else testPassed=false;
printf("If test passed it is 1: %d\n", testPassed);
return 0;
}
\ No newline at end of file
...@@ -175,6 +175,7 @@ AC_CONFIG_FILES([Makefile ...@@ -175,6 +175,7 @@ AC_CONFIG_FILES([Makefile
Utilities/MBTester/Makefile Utilities/MBTester/Makefile
Utilities/DBServer-MySQL/Makefile Utilities/DBServer-MySQL/Makefile
Utilities/JrnTests/Makefile Utilities/JrnTests/Makefile
Utilities/UniXmlTest/Makefile
Utilities/codegen/Makefile Utilities/codegen/Makefile
Utilities/codegen/uniset-codegen Utilities/codegen/uniset-codegen
Utilities/codegen/tests/Makefile Utilities/codegen/tests/Makefile
......
...@@ -107,6 +107,8 @@ public: ...@@ -107,6 +107,8 @@ public:
// ->parent // ->parent
xmlNode* findNode(xmlNode* node, const std::string searchnode, const std::string name = ""); xmlNode* findNode(xmlNode* node, const std::string searchnode, const std::string name = "");
xmlNode* extFindNode(xmlNode* node, int depth, int width, const std::string searchnode, const std::string name = "", bool top=true );
protected: protected:
static int recur; static int recur;
......
...@@ -313,6 +313,35 @@ xmlNode* UniXML::findNode(xmlNode* node, const string searchnode, const string n ...@@ -313,6 +313,35 @@ xmlNode* UniXML::findNode(xmlNode* node, const string searchnode, const string n
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
//width means number of nodes of the same level as node in 1-st parameter (width number includes first node)
//depth means number of times we can go to the children, if 0 we can't go only to elements of the same level
xmlNode* UniXML::extFindNode(xmlNode* node, int depth, int width, const string searchnode, const string name, bool top )
{
xmlNode* nodeFound;
int i=0;
while (node != NULL)
{
if(top&&(i>=width)) return 0;
if (searchnode == xml2local(node->name))
{
if( name == getProp(node,"name") )
return node;
if( name.empty() )
return node;
}
if(depth>0)
{
if ( (nodeFound=extFindNode(node->children, depth-1,width, searchnode, name,false)) != 0 )
return nodeFound;
}
i++;
node = node->next;
}
return 0;
}
bool UniXML_iterator::goNext() bool UniXML_iterator::goNext()
{ {
if( !curNode ) // || !curNode->next ) if( !curNode ) // || !curNode->next )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment