[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-edu-devel
Subject:    Re: [kde-edu-devel] XML and me.....
From:       Scott Wheeler <wheeler () kde ! org>
Date:       2002-05-29 11:33:23
[Download RAW message or body]

On Wednesday 29 May 2002 12:35 pm, Anne-Marie Mahfouf wrote:
> Hi,

> The latin and english words were stored in a text file, I will use FlashKard 
> xml. But I have some difficulties extracting the content from that xml 
> file.... I had a look at flashKard but there are 3 classes involved 
> (xmlparser, datawidget and card) and I cannot figure out how to make all 
that 
> work in KLatin... 

First I should point out that this is "kvtml", i.e. KVocTrainML, which I 
borrowed from Ewald (since FlashKard is newer than KVocTrain and I was 
already planning on using XML of some type).

DataWidget is just the widget that contains the KListView where I put the data 
once its parsed.  You shouldn't need to wory about that.

So the two remaining classes are XMLParser and Card.  XMLParser is a subclass 
of QXmlDefaultHandler and it's implementation came more or less out of the 
the Qt documentation for the XML module.  

Card and CardList (from card.h) are pretty easy.  Card is a simple class that 
contains a "front" and "back" QString, plus a couple of accessor and modifier 
methods.  It also makes it possible to reverse the card, as is useful in 
FlashKard.  

CardList is just a QValueList<Card>.

> I don't know where the data is after being extracted (in a QValueList?) nor 
> don't I understand why the XMLParser parses a list and not a file. I am new 
> in all that so maybe I am really naive on that one.... 
> Should I wait for the lib to be done or should I carry on? In that case, any 
> hint would be welcome.

Well, specifically in a CardList, which is indeed a subclass of QValueList.

Here's where the nastiness of the XML module comes in.  XMLParser doesn't 
handle input or output, it just provides some overloaded functions that are 
called while the XML module is parsing things.  Hmm.  I'll try to be a bit 
more clear.  

Here's a bit of the source now with extra verbose comments:

        XMLParser handler(list);

Ok, we've created an instance of my parser.  I'll explain what it does a bit 
more in a moment.  We're not actually parsing the CardList "list", that's 
just an argument to the constructor to tell it where to put the data that it 
parses.

        QFile input(*it);

This is all happening inside of an iterator based loop.  In this case *it is 
just a QString with the file name.

        QXmlInputSource source(input);

Here we tell the XML module what to use as it's input.  This is the QFile that 
we created in the line above.

        QXmlSimpleReader reader;

Defining the reader for our "source" that we defined in the line above.

        reader.setContentHandler(&handler);

Now we get to the goodies.  We tell the reader to use *my* parser specifically 
when it is parsing the file.  Every parser or "handler" has to implement 
functions like startElement() and endElement().  (They are virual in the 
baseclass.)  Our "reader" expects to find these functions and will complain 
if they're not there.  I just filled in the gaps and told the XML module what 
it should do when it comes across something like a startElement().

        reader.parse(source);

And this is just the function to actually start doing all of the work.

Of course hopefully our library will hide most of this ugliness at some point, 
but that may be a little bit in the future.  I don't know when you're hoping 
to have your rewrite done.

I would hope that the library would do something like this:

QValueList<KVocabularyItems> items = KEduData::parse("foo.kvtml");

And then have things like:

QString original = items[0].originalText();
QString translated = items[0].translatedText();

But that may be oversimplification.  We'll see.  

> A wish: could FlashKard accept a filename as a parameter so it could open 
> directly with a file loaded? 

Yep.  That's been on my todo list for a while and I'm acutally (today) 
implementing that in another one of my KDE applications, so after I've 
finished that, I'll probably borrow most of the source and drop it into 
FlashKard.

> Wishes for the edulib:
> - a class for the user to enter kvtml data (if it's only vocabulary data, 
> could it be with the <e><o></o><t></t></e> tags only? This is easy to 
> understand and to hack manually)

Yes, that should be all there is to it, plus the:

<?xml version="1.0"?>
<!DOCTYPE kvtml SYSTEM "kvoctrain.dtd">
<kvtml> ...

At some point we'll have to decide whether the new format will be an extension 
to kvtml or something designed for a bit more general use.  Since Ewald 
designed kvtml, he probably knows better how it will respond to being 
extended.

> - the flashKard quizz would be nice as well (where you enter the word in a 
> lineEdit)

Yeah, there have been a couple of mentions of this.  I really don't know 
KParts at all (other than as a user), but I'm guessing that's the way to go.  
Alternatively, as I recall, I think I wrote QuizWidget and its subclass 
GuessWidget (and FlashcardsWidget) to be fairly portable, but I must admit 
that wasn't a primary goal at creation.  I know that they rely on the Card 
class, but I don't think there's anything else from FlashKard that they 
require.
 
> So in KLatin I would have 2 test modes: the actual one (1 word, 3 different 
> meanings, choose the correct one) and the FlashKard-like quizz. 
> Maybe a Memory game as well for fun (words pair: latin+your language)
> 
> Thanks for any help/hint/flame/encouragement on that matter. Please tell me 
> if KLatin as I see it is better in GUI than the actual one. Ask me for the 
> code if you want it, I'll commit only when xml works and if people are happy 
> with the new interface. If not, it still improves my coding skills so 
there's 
> no bother ;)

Hope it helps!

Cheers!

-Scott
_______________________________________________
kde-edu-devel mailing list
kde-edu-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/kde-edu-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic