XML as data source

Hello,

This is my first post here. Sorry in advance if this topic has already been around, but I’ve used the search function and didn’t see any relevant results.

I am very happy that a simple yet powerful framework like Yii exists and wanted to use it in my uni project. It’s basically an application similar to the Hangman game in the Demo section of the Yii website. The main goal is to build a simple eLearning system for the Chinese language (or any other, more to be explained).

I have my data (words, phrases, parts of speech) in XML files. What I want to do, is to make models for every XML file and use them as data source for the lessons (some will just present the phrases, so they can be learned, while other will be small quizes needing user input).

So my first question would be:

How to access XML and make models out of it in the best manner? I can’t use Gii or any other code generators, as they all rely on databases… I have files.

Thanks in advance for your help,

With kind regards

Bill

I made a project that had the need to read xml.

SO I made classes with functions reading the xml and returning the things I wanted.

But that project did not use a framework.

So an idea is to use a model or something with simiral way?

Of course maybe a solution more Yii specific

I’m investigating this possibility since I’m working on a project where I’m trying to avoid the use of any DB.

Apart from berkdb, which would be a fine option but not widely available, I was thinking about the use of an XML, and I was slightly worried of course of a couple of things:

  • modelling data with classes (aka models) out of xml files (could that be done automatically?)

  • slightly related to the previous point, I’m worring about speed. Caching would be useful of course but I don’t know if splitting into thousands of files would help

any ideas if and how yii would behave in this situation?

Hi newbie to Yii, but not frameworks or PHP. I have been working on two new projects with Yii. One screen uses a db and xml.

Answer to your first question: No, none that I could find. So, I created a loadXML() method on the model file being used by the controller. I would prefer to have an individual XML model file, but this will work. I call the method on the active record for the page. I have seen no inherent criteria to navigate XML nodes and attributes in Yii either. So, I have to write additional methods to query the correct data for output. I wish there were a way to load XML data into a Zii Grid View, but the only thing Yii has that I see is XMLmenu, which isn’t what I need.

Second question: Why wouldn’t SQLite be a better solution? Not sure why you don’t want to run a db at all. I am assuming for the overall weight of the app, but if so, why would SQLite not be the preference?

I am at the point with Yii and XML to where I assume I will need to write a custom model to convert XML data into a SQLite db when the user uploads the data. I have another part that needs a heavy-duty RSS reader. I assume that an additional framework like Simple Pie will have to be integrated to traverse XML docs for output.

Hi all. Just FYI, got xml feeds to easily output with by building a custom action, which a flash widget calls to get its data. I have also used the same logic, except to load XML data into the database with Yii. In this case, I allow the user to upload an XML file, which is then converted by Yii with the global php method simple_load_xml. It parses the XML doc, then sets the values into a form, the user looks over the XML->form data, then submits the form to the db.

New to Yii, but I have to say I’m loving it. However, I’m about to need an RSS reader for Yii. I’m assuming I can import the simplepie framework, combine with Yii, and Viola.

It would be cool to be able to create models based off of XML, but that’s kinda what simplepie does already for RSS. But if Yii had the ability to traverse example XML docs and create models would be a big help.

This is really interesting topic! I’m going to use YII without any database. Data will be pulled and pushed back and forth between webserver and application/data server via xml. I don’t want to use AR, I hope, CFormModel will be enough for user input. Models will get/set data with some XML wrapper class. However, eventually, when I decide to use database (obviously it’s gonna be faster than xml exchange with current server) much work has to be done to migrate. Probably I should just switch my custom model for AR some day… or even better - application might work in two modes: xml or mysql data source. The question is how to do this with maximum code reusing? I guess, if I extend AR model and re-write all SQL specific functionality, it could be my custom Model. As I don’t need full AR functionality for XML data source, it shouldn’t be hard.

If I added some extra AR specific featured while app was working with MySQL, and I switched back to XML data source, I just need to rewrite additional functions.

If it sounds weird for someone, please advice something more reasonable.

cheers