XML In Moodle 2.0

XML In Moodle 2.0

by Penny Leach -
Number of replies: 5
We just briefly touched on this in the Dev Jabber chat, but I thought it would be a good thing to discuss here so everyone can weigh in.

I'm soon going to be adding LEAP2A portfolio standard support to the portfolio API for Moodle 2.0, which raises the question of a consistent way to read/write XML (I only care about writing at the moment, but it's a good time to talk about both).

I would strongly advocate using the php5 builtin DOM functions, but that's not going to work, for example, for Backup/Restore because it's just too much to store in memory.

I kind of think it would be nice to have a consistent way of doing things, rather than a mix of Dom/XMLWriter/Simplewhatever/Smarty/Stringconcatenation, that we seem to have now.

Discuss!
Average of ratings: -
In reply to Penny Leach

Re: XML In Moodle 2.0

by Martín Langhoff -
Well, I think it is clear we need both

* A DOMinatrix processor, for easy programming of XML things that we know are small (ie: environment.xml)
* A stream processor (with parser/callback for reading, and a "stream writing" mode that optionally validates); for unknown-size data...


I really wanted to be in today's meeting but could not- grr mixed
In reply to Penny Leach

Re: XML In Moodle 2.0

by Dan Poltawski -

I think that SimpleXML has become the defacto standard for reading (disclosure: I may be responsible for a few commits pushing that it that way wink ).

danp@dev:~/git/moodle$ git grep -i SimpleXML | wc -l
59 

Eloys research in Development:Backup_2.0_-_Improve_XML_parsing which suggested the performance benefits of SimpleXML seems to suggest its a winner. Its also now in the php required extensions. (But its not really a huge deal to change it if there are some arguments against SimpleXML).

For writing I have no opinion as I know nothing about the benefits of the options. I do know i've seen bugs caused by the current inconsistent approach so agree that we shold standardise. (Reminder about a bug I created for this a while ago: MDL-13157 )

In reply to Dan Poltawski

Re: XML In Moodle 2.0

by Penny Leach -
Actually when I talked to Eloy about it, he was talking about using XMLReader/XMLWriter rather than SimpleXML.

http://ch2.php.net/manual/en/book.xmlreader.php
http://ch2.php.net/manual/en/book.xmlwriter.php

One limitation of SimpleXML is that it can't read comments, I believe. Nigel found this recently in Mahara, and had to load into DomDocument the SimpleXML object to get at the comment nodes.
In reply to Penny Leach

Re: XML In Moodle 2.0

by Frank Ralf -
When exporting questions Moodle inserts the question number as a comment (e.g. <!-- question: 583  -->). If this feature is important for re-importing questions the API must be comment-aware (see http://www.qedoc.org/en/index.php?title=Moodle_XML_format#Question_numbers ).

Cheers,
Frank

In reply to Frank Ralf

Re: XML In Moodle 2.0

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
If the information is really important, it should not be in a comment.

I expect the comment is only added to question exports for the benefit of humans reading the file.