From 95032b5b060a530a3a84b72921cab0a23afdbeb6 Mon Sep 17 00:00:00 2001
From: graetz23
Date: Sat, 5 Feb 2022 14:04:46 +0100
Subject: [PATCH 1/2] cleaning branch for acting as library
---
main.cpp | 196 -----------------------------------------
run/xmlcc.html | 16 ----
run/xmlcc.xml | 43 ---------
run/xmlccFeed.rss | 29 ------
run/xmlccMalformed.xml | 106 ----------------------
5 files changed, 390 deletions(-)
delete mode 100644 main.cpp
delete mode 100644 run/xmlcc.html
delete mode 100644 run/xmlcc.xml
delete mode 100644 run/xmlccFeed.rss
delete mode 100644 run/xmlccMalformed.xml
diff --git a/main.cpp b/main.cpp
deleted file mode 100644
index 0dcc8bc..0000000
--- a/main.cpp
+++ /dev/null
@@ -1,196 +0,0 @@
-/**
- * @file main.cpp
- * @author Christian
- *
- * XMLCC is distributed under the MIT License (MIT); this file is part of.
- *
- * Copyright (c) 2008-2022 Christian (graetz23@gmail.com)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef __cplusplus
-#error use a C++ compiler for XMLCC::
-#endif
-
-/******************************************************************************/
-
-#include "./xmlcc/xmlcc.h" // include of XMLCC::
-
-/******************************************************************************/
-
-// XMLCC:: is still keeping DOM::, SAX::, CFG::, SYS::, and TEST::
-using namespace XMLCC;
-
-/******************************************************************************/
-
-int // main
-main( int argc, char** argv ) {
-
- /****************************************************************************/
-
- try { // try everything ~8>
-
- /**************************************************************************/
-
- if( true ) { // print version and built date at start up
-
- std::cout << "XMLCC:: version " << _XMLCC_VERSION_ << " package "
- << _XMLCC_PACKAGE_ << std::endl << std::flush;
- std::cout << "XMLCC:: built " << _XMLCC_BUILD_DATE_ << " "
- << _XMLCC_BUILD_TIME_ << std::endl << std::flush;
- std::cout << std::endl << std::flush;
-
- } // if
-
- /**************************************************************************/
-
- if( true ) { // generating the actual config file for XMLCC
-
- std::cout << "checking config file .. " << std::flush;
- CFG::Config config;
- if( config.exists( ) ) {
- std::cout << "exists!" << std::endl << std::endl << std::flush;
- } else {
- std::cout << "not existing; going to generating one .. " << std::flush;
- config.write( config.generate( ) );
- std::cout << "done!" << std::endl << std::endl << std::flush;
- } // if
-
- } // if
-
- /**************************************************************************/
-
-#ifdef _XMLCC_USE_TEST_ // see xmlccTest.h & xmlccTest.cpp
- XMLCC::TEST::run( ); // run unit tests of XMLCC as set in config file
-#endif // _XMLCC_USE_TEST_
-
- /**************************************************************************/
-
- if( true ) { // generating a simple web page by using DOM objects directly
-
- // example how to generate, view, and write content in XML (HTML)
- std::cout << "generating DOM tree .. " << std::flush;
- DOM::Root* xml = 0;
- xml = new DOM::Root( "xmlcc.html", new DOM::Doctype( ),
- new DOM::Comment( "XMLCC 1.01 20200307 Amara Faith" ),
- new DOM::Element( "html",
- new DOM::Element( "head",
- new DOM::Element( "title",
- new DOM::Value( "HTML generated by XMLCC" ) ) ),
- new DOM::Element( "body" ),
- new DOM::Element( "center",
- new DOM::Comment( "HTML was generated by XMLCC" ),
- new DOM::Value( "Hello" ),
- new DOM::Element( "b", new DOM::Value( "WWW" ) ),
- new DOM::Value( "from XMLCC" ), new DOM::Element( "br" ),
- new DOM::Element( "a",
- new DOM::Attribute( "href",
- "https://github.com/graetz23/xmlcc/" ),
- new DOM::Value( "visit project page" ) ) ) ) );
- std::cout << "done!" << std::endl << std::flush;
-
-// std::cout << std::endl << std::flush;
-// std::cout << "showing DOM tree to file .. " << std::endl << std::flush;
-// std::cout << xml << std::endl << std::flush; // DOM:: 2 std::cout
-// std::cout << "done!" << std::endl << std::flush;
-
- std::cout << "writing DOM tree to file .. " << std::flush;
- std::fstream file; // open file
- file.open( ( (char*)( xml->getStr( ).c_str( ) ) ), std::ios::out );
- file << xml; // DOM tree 2 std::ostream
- file.close( );
- delete xml; // deletes complete DOM tree
- std::cout << "done!" << std::endl << std::endl << std::flush;
-
- } // if
-
- /**************************************************************************/
-
- if( true ) { // generating a simple web page by using DOM objects directly
-
- // TODO implement web page example using DOM::Controller
-
- } // if
-
- /**************************************************************************/
-
- XMLCC::Str fileName = ""; // file name by console or use xmlccMalformed.xml
- if( argc >= 2 )
- fileName.append( argv[ 1 ] );
- else
- fileName = "xmlccMalformed.xml";
-
- /**************************************************************************/
-
- if( true ) { // parsing to document object model (DOM)
-
- std::cout << "parsing to document object model (DOM): " << fileName
- << std::endl << std::flush;
- XMLCC::DOM::Core core; // methods for parsing 2 DOM tree
- XMLCC::DOM::Root* root = core.parseFile2DomTree( fileName ); // DOM tree
- if( root != 0 ) {
- std::cout << root << std::flush << std::endl; // DOM tree 2 std::ostream
- delete root; // deletes complete DOM tree
- } // if root
-
- } // if
-
- /**************************************************************************/
-
- if( true ) { // parsing using simple API for XML (SAX)
-
- std::cout << "parsing by simple API for XML (SAX): " << fileName
- << std::endl << std::flush;
- // SAX parser; parsing, cleaning, and calling SAX handler methods
- XMLCC::SAX::Parser* parser = new XMLCC::SAX::Parser(
- new XMLCC::SAX::HandlerExample( ) );
- parser->parseFile( fileName ); // HandlerExample is streaming to std::cout
- delete parser;
-
- } // if
-
- /**************************************************************************/
-
- // std::cout << "done!" << std::endl << std::flush;
- /**************************************************************************/
-
- } catch( XMLCC::SYS::Failure& f ) { // own exception class
- std::cout << "SYS::Failure caught:" << std::endl << std::flush;
- std::cout << f;
- } catch( XMLCC::SYS::Error& e ) { // own exception class
- std::cout << "SYS::Error caught:" << std::endl << std::flush;
- std::cout << e;
- } catch( XMLCC::SYS::Exception& e ) { // own exception class
- std::cout << "SYS::Exception caught:" << std::endl << std::flush;
- std::cout << e;
- } catch( std::exception& e ) { // standard exception class
- std::cout << "std::exception caught:" << std::endl << std::flush;
- std::cout << e.what( ) << std::endl << std::flush;
- } catch( ... ) { // any other exception thrown
- std::cout << "Strange exception caught:" << std::endl << std::flush;
- XMLCC::SYS::Exception e;
- e.nuke( ); // nuke screen
- } // try
-
- return 0;
-
-} // main
-
-/******************************************************************************/
diff --git a/run/xmlcc.html b/run/xmlcc.html
deleted file mode 100644
index 9fe945c..0000000
--- a/run/xmlcc.html
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
- HTML generated by XMLCC
-
-
-
-
- Hello
- WWW
- from XMLCC
-
- visit project page
-
-
diff --git a/run/xmlcc.xml b/run/xmlcc.xml
deleted file mode 100644
index e4920cf..0000000
--- a/run/xmlcc.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/run/xmlccFeed.rss b/run/xmlccFeed.rss
deleted file mode 100644
index e6bb6dc..0000000
--- a/run/xmlccFeed.rss
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
-
- Titel des Feeds
- URL der Webpraesenz
- Kurze Beschreibung des Feeds
- Sprache des Feeds (z. B. "de-de")
- Autor des Feeds
- Erstellungsdatum("Tue, 8 Jul 2008 2:43:19")
-
- URL einer einzubindenden Grafik
- Bildtitel
- URL, mit der das Bild verknuepft ist
-
- -
- Titel des Eintrags
- Kurze Zusammenfassung des Eintrags
- Link zum vollstaendigen Eintrag
- Autor des Artikels, E-Mail-Adresse
- Eindeutige Identifikation des Eintrages
- Datum des Items
-
- -
- ..
-
-
-
diff --git a/run/xmlccMalformed.xml b/run/xmlccMalformed.xml
deleted file mode 100644
index 6d9d48c..0000000
--- a/run/xmlccMalformed.xml
+++ /dev/null
@@ -1,106 +0,0 @@
- xml version = " 1.0" encoding="UTF-8" standalone="no " ?>
-
-
-
-< people >
- < person gender = " female
- "
- scars = "
-
- none
-
- "
- >
-
-
-
-
-
- Gable < / familyname >
-
- this tag is a
- tag in some text < /
- mixed >
- to overcome html for eXaMpLe
-
-
-
-Ginger
-Sandy
-Memphis
-
- < / forename
- >
-
-
- < age > 27 < / age >
-
- person
-
-
- ><
- person gender="male">
- Hudden
-
- Paul
- Big Bull
- James
-
- unknown
-
- Main Street
- 5643
- 70569
- Stuttgart
-
-
- < info drink = " coke " / >
-
- <
- info clothes =
- "cotton" hat = " red "
-
-shoes
-
-
-=
-
-"
-black
-
-grey
-
-red
-
-"
-
-
-/
-
-
->
-
-
-
-
-
-
-
-
-
-
-
From 1a29f2bed8de4a6e68c8040f9a5c8313174b4e07 Mon Sep 17 00:00:00 2001
From: graetz23
Date: Sat, 5 Feb 2022 15:34:03 +0100
Subject: [PATCH 2/2] added crawling method to find some node in xml or html
tree ..
---
xmlcc/xmlccDomController.cpp | 26 ++++++++++++++++++++++++++
xmlcc/xmlccDomController.h | 2 ++
2 files changed, 28 insertions(+)
diff --git a/xmlcc/xmlccDomController.cpp b/xmlcc/xmlccDomController.cpp
index a938fca..d047b7b 100644
--- a/xmlcc/xmlccDomController.cpp
+++ b/xmlcc/xmlccDomController.cpp
@@ -85,6 +85,32 @@ Controller::getAttribute( Node* node, Str strAttribute ) {
return (Node*)( attribute ); // if DOM::Attribute not found return null ptr
} // Controller::getAttribute
+Node* // return DOM::Element stored at Node* by name or a null pointer
+Controller::crawlElement( Node* node, Str strElement ) {
+ Node* element = 0;
+ NodeList* elementList = genListOfElements( node );
+ int noOfElements = elementList->size( );
+ int n = 0;
+ bool isSearching = true;
+ while( isSearching && ( n < noOfElements ) ) {
+ Element* elementNode = (Element*)( elementList->get( n ) );
+ Str nameElementNode = elementNode->getStr( );
+ if( nameElementNode.compare( strElement ) == 0 ) {
+ isSearching = false;
+ element = elementNode;
+ } else { // go recursive on that
+ Node* child = crawlElement( elementNode, strElement );
+ if( child != 0 ) {
+ element = child;
+ isSearching = false; // hands back FIRST found node
+ } // if
+ } // if found
+ n++;
+ } // while isSearching
+ delete elementList;
+ return (Node*)( element ); // if DOM::Element not found return null pointer
+} // Controller::crawlElement
+
/**************************************************************************/
Root* /// create a XMLCC root
diff --git a/xmlcc/xmlccDomController.h b/xmlcc/xmlccDomController.h
index a3a9fb5..6b3ee8d 100644
--- a/xmlcc/xmlccDomController.h
+++ b/xmlcc/xmlccDomController.h
@@ -67,6 +67,8 @@ Controller {
Node* getElement( Node* node, Str strElement ); /// return DOM::Element stored at Node* by name or a null pointer
Node* getAttribute( Node* node, Str strAttribute ); /// return DOM::Attribute stored at Node* by name or a null pointer
+ Node* crawlElement( Node* node, Str strElement ); /// crawl down the child of given node and return the FIRST node for given string or a null pointer
+
/**************************************************************************/
Root* createRoot( void ); /// XMLCC root, representing the file