]> Git trees. - libqmvoc.git/commitdiff
a couple of fixes to the parser... I found some bugs but have not yet found out why...
authorCarsten Niehaus <cniehaus@gmx.de>
Sun, 3 Sep 2006 11:25:45 +0000 (11:25 +0000)
committerCarsten Niehaus <cniehaus@gmx.de>
Sun, 3 Sep 2006 11:25:45 +0000 (11:25 +0000)
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=580368

libscience/elementparser.cpp
libscience/xmlreadingtest.cpp

index 632ec166bf5ae2cd326a508b1f37b1f701f95e22..b9230a4984e236d31993746e2cef74a455b5455b 100644 (file)
@@ -109,8 +109,6 @@ bool ElementSaxParser::startElement(const QString&, const QString &localName, co
     {
         for (int i = 0; i < attrs.length(); ++i) 
         {
-            //kDebug() << "attrs.value(i) is: " << attrs.value(i) << " (localname: " << localName << ")" << endl;
-            
             if ( attrs.localName( i ) == "unit" )
             {
                 d->currentUnit = ChemicalDataObject::unit( attrs.value( i ) );
@@ -170,11 +168,10 @@ bool ElementSaxParser::startElement(const QString&, const QString &localName, co
     {
         for (int i = 0; i < attrs.length(); ++i) 
         {
-            // FIXME
             if ( attrs.localName( i ) != "dictRef" )
                 continue;
 
-            if (attrs.value(i) == "bo:symbol")
+            if (attrs.value(i) == "bo:symbol"){
                 for (int i = 0; i < attrs.length(); ++i) 
                 {
                     if (attrs.localName(i) == "value") {
@@ -182,7 +179,8 @@ bool ElementSaxParser::startElement(const QString&, const QString &localName, co
                         d->currentDataObject->setType( ChemicalDataObject::symbol );
                     }
                 }
-            else if ( attrs.value(i) == "bo:name" || attrs.value(i) == "bo::symbol" ) {
+            }
+            else if ( attrs.value(i) == "bo:name" ){
                 for (int i = 0; i < attrs.length(); ++i) 
                 {
                     if (attrs.localName(i) == "value") {
@@ -201,13 +199,23 @@ bool ElementSaxParser::endElement( const QString &, const QString& localName, co
     if ( localName == "atom" )
     {
         if ( d->currentElement->dataAsString( ChemicalDataObject::symbol ) != "Xx" )
+        {
             d->elements.append(d->currentElement);
+            
+            QList<ChemicalDataObject*> list = d->currentElement->data();
+            foreach( ChemicalDataObject*o, list )
+            {
+                if ( o ) { 
+                    kDebug() << "Name: " << o->dictRef() << " " << o->valueAsString() << endl;
+                }
+            }
+        }
 
         d->currentElement = 0;
         d->currentDataObject = 0;
         d->inElement = false;
     }
-    else if ( localName == "scalar" || localName == "label" )
+    else if ( localName == "scalar" || localName == "label" || localName == "array" )
     {
         if ( d->currentUnit != ChemicalDataObject::noUnit )
             d->currentDataObject->setUnit( d->currentUnit );
@@ -357,10 +365,5 @@ bool ElementSaxParser::characters(const QString &ch)
 
 QList<Element*> ElementSaxParser::getElements()
 {
-    kDebug() << "ElementSaxParser::getElements()" << endl;
-
-    foreach (Element* e, d->elements) {
-        kDebug() << e->dataAsString( ChemicalDataObject::name) << " symbol: " <<  e->dataAsString( ChemicalDataObject::symbol) << endl;
-    }
     return d->elements;
 }
index 97dd0fc5ca703d7ad1f0fefbfed89ba6f4c099fc..e7ae096a19eece9dac17e3e040be635a6ed1e162 100644 (file)
@@ -27,26 +27,25 @@ int main(int argc, char *argv[])
     reader.parse(source);
 
     QList<Element*> v = parser->getElements();
-    kDebug() << "Count: " << v.count() << endl;
-
-    foreach( Element* e, v ){
-        if ( e )
-        {
-            QList<ChemicalDataObject*> list = e->data();
-
-            //Test: give me all data available
-            foreach( ChemicalDataObject*o, list ){
-                if ( o )
-                {
-                    QString unit = o->unitAsString();
-                    if ( unit == "bo:noUnit" )
-                        unit = "";
-                    kDebug() << "Name: " << o->dictRef() << " " << o->valueAsString()  <<" "  << unit << endl;
-                }
-            }
-        }
 
-    }
+//X     foreach( Element* e, v ){
+//X         if ( e )
+//X         {
+//X             QList<ChemicalDataObject*> list = e->data();
+//X 
+//X             //Test: give me all data available
+//X             foreach( ChemicalDataObject*o, list ){
+//X                 if ( o )
+//X                 {
+//X                     QString unit = o->unitAsString();
+//X                     if ( unit == "bo:noUnit" )
+//X                         unit = "";
+//X                     kDebug() << "Name: " << o->dictRef() << " " << o->valueAsString()  <<" "  << unit << endl;
+//X                 }
+//X             }
+//X         }
+//X 
+//X     }
 
     return 0;
 }