From: Carsten Niehaus Date: Sun, 3 Sep 2006 11:25:45 +0000 (+0000) Subject: a couple of fixes to the parser... I found some bugs but have not yet found out why... X-Git-Tag: v3.80.2~42 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=fec616a24ccc26423dd781ce11766b53c00dda4d;p=libqmvoc.git a couple of fixes to the parser... I found some bugs but have not yet found out why the name and the symbol is not stored... svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=580368 --- diff --git a/libscience/elementparser.cpp b/libscience/elementparser.cpp index 632ec16..b9230a4 100644 --- a/libscience/elementparser.cpp +++ b/libscience/elementparser.cpp @@ -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 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 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; } diff --git a/libscience/xmlreadingtest.cpp b/libscience/xmlreadingtest.cpp index 97dd0fc..e7ae096 100644 --- a/libscience/xmlreadingtest.cpp +++ b/libscience/xmlreadingtest.cpp @@ -27,26 +27,25 @@ int main(int argc, char *argv[]) reader.parse(source); QList v = parser->getElements(); - kDebug() << "Count: " << v.count() << endl; - - foreach( Element* e, v ){ - if ( e ) - { - QList 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 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; }