# Use of xml

**URL:** <https://www.ruby-forum.com/t/use-of-xml/77561>\
**Category:** Rails\
**Created:** [November 28, 2006, 8:23pm UTC](https://www.ruby-forum.com/t/use-of-xml/77561 "2006-11-28T20:23:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pabloz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c37758/32.png) [@pabloz](https://www.ruby-forum.com/u/pabloz)\
**Post date:** [November 28, 2006, 8:23pm UTC](https://www.ruby-forum.com/t/use-of-xml/77561/1 "2006-11-28T20:23:48Z")

</div>

Hi

Is it a good idea to keep for example blog posts in xml file rather than  
mysql? Right now i am trying this kind of project and its going really  
really slow, i dont have a model, i learn REXML, but still cant add  
nothing to my xml from a form for example. Anyway…is this a good way?  
or You would suggest database?

---

<div class="post-metadata">

**Author:** ![pabloz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c37758/32.png) [@pabloz](https://www.ruby-forum.com/u/pabloz)\
**Post date:** [November 28, 2006, 8:36pm UTC](https://www.ruby-forum.com/t/use-of-xml/77561/2 "2006-11-28T20:36:23Z")

</div>

Pabloz wrote:

> Is it a good idea to keep for example blog posts in xml file rather than  
> mysql? Right now i am trying this kind of project and its going really  
> really slow, i dont have a model, i learn REXML, but still cant add  
> nothing to my xml from a form for example. Anyway…is this a good way?  
> or You would suggest database?

Which kind of store do you understand best?

And wouldn’t you prefer to have full ActiveRecord support?

SQLite3 fully supports arbitrary-length strings in all VARCHARs (whether  
you  
want them or not).

Now why can’t your form add anything to XML? Could you use  
Builder::XmlMarkup to write the XML and REXML to read it?

Can you create new elements and add them to REXML? is that where you are  
stuck?

Without more info your question is arbitrary. I would use YAML, but we  
will  
keep that our little secret…

–  
Phlip  
[Redirecting...](http://www.greencheese.us/ZeekLand) ← NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![pabloz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c37758/32.png) [@pabloz](https://www.ruby-forum.com/u/pabloz)\
**Post date:** [November 28, 2006, 8:48pm UTC](https://www.ruby-forum.com/t/use-of-xml/77561/3 "2006-11-28T20:48:26Z")

</div>

In my experience parsing xml files with REXML was much slower than  
reading from MySQL.

I had a storefront that read product data from XML that was dumped  
from a legacy POS system. Page loads were SLOW.  
I wound up writing an update script to sync the XML files with a MySQL  
table and it became much faster. Not to mention the ease of use for  
CRUD that comes with ActiveRecord.

That said, I could’ve probably just cached the XML (as you could too)  
but in my case I wasn’t writing to XML, just reading.  
Also creating a model that houses the logic for CRUD/returning  
attributes, would probably make you much happier, and your app more  
rails like. that way if you ever decide to switch to db later, it will  
be much easier.  
But if you’re building from scratch, I’d just go with MySQL (or other  
DB).

–

Chris M.  
Web D.  
Open Source & Web Standards Advocate

> **[Chriscodes.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=chriscodes.com)**
>
> Painless, quick delivery of your domain name. Fast and professional service.

---

<div class="post-metadata">

**Author:** ![pabloz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c37758/32.png) [@pabloz](https://www.ruby-forum.com/u/pabloz)\
**Post date:** [November 29, 2006, 2:13pm UTC](https://www.ruby-forum.com/t/use-of-xml/77561/4 "2006-11-29T14:13:00Z")

</div>

On 28-Nov-06, at 2:23 PM, Pabloz wrote:

> Hi
> 
> Is it a good idea to keep for example blog posts in xml file rather  
> than  
> mysql? Right now i am trying this kind of project and its going really  
> really slow, i dont have a model, i learn REXML, but still cant add  
> nothing to my xml from a form for example. Anyway…is this a good  
> way?  
> or You would suggest database?

I think there are very good reasons to keep your data in the file  
system, and I do this routinely. However, using the DOM as an in-  
memory data structure os something that I find painful even to  
contemplate. If you really want to do this, then you might look at  
libxml as an alternative (much faster with some nice utilities).

You’ve got some alternatives: ActiveRecord, which undeniably fits  
nicely into Rails, but then you’ve got a database to deal with. YAML  
which may well be what you are hoping for by using XML (but I’ve  
experienced some problems with it). There is also JSON and a more  
Ruby-like variant called Ron. With JSON/Ron and YAML you won’t have  
control over the appearance of the file on disk, control that you  
would have with XML, and that might be a problem – but you’ll have a  
much nicer programming model.

A final alternative for XML is to use something like xampl (I’m  
biased, see the links below). This gives you some reasonable control  
over the on-disk appearance and a _much_ easier API to manipulate the  
XML in your program (the API is just Ruby). I don’t know if I’d start  
something new with the current version of xampl, there’s a new  
version of xampl that I’ll be releasing soon (I hope) that is much  
improved and works pretty much transparently with Rails (unless you  
want to use Rail’s scaffolding). The documentation in the examples  
download is still almost entirely correct, I’ve just added stuff.

Good luck. I’d be interested in knowing what you chose to do and how  
it works out.

Cheers,  
Bob

* * *

Bob H. – blogs at \<[http://www.recursive.ca/](http://www.recursive.ca/)  
hutch/\>  
Recursive Design Inc. – [http://www.recursive.ca/](http://www.recursive.ca/)  
Raconteur – [http://www.raconteur.info/](http://www.raconteur.info/)  
xampl for Ruby – [http://rubyforge.org/projects/xampl/](http://rubyforge.org/projects/xampl/)

---

<div class="post-metadata">

**Author:** ![pabloz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c37758/32.png) [@pabloz](https://www.ruby-forum.com/u/pabloz)\
**Post date:** [November 30, 2006, 4:30am UTC](https://www.ruby-forum.com/t/use-of-xml/77561/5 "2006-11-30T04:30:26Z")

</div>

Pabloz wrote:

> Hi
> 
> Is it a good idea to keep for example blog posts in xml file rather than  
> mysql? Right now i am trying this kind of project and its going really  
> really slow, i dont have a model, i learn REXML, but still cant add  
> nothing to my xml from a form for example. Anyway…is this a good way?  
> or You would suggest database?
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

Without knowing the business problem, the question is meaningless.

XML is good for cross-platform data transfer and serialization of  
hierarchical data.

DOM can be considered an indexed tree structure, independent of its XML  
roots, for some purposes. I have used JDOM as the core of a  
high-performance ETL tool. In this case, the DOM is never rendered as  
XML except for debugging. I build DOM from COBOL copybooks, VSAM  
records, RDBMS rows, Excel spreadsheets, and (of course) XML documents.  
I max out the I/Ochannels on mainframe database server with this  
configuration.

RDBMS is good for data that can be organized as a set of related  
tables. It has proven itself to be a flexible model for meeting most  
problems efficiently.

Personally, I am not fond of MySQL. The business problems that I work  
on tend to be transactional, and MySql does not honor the ACID  
definition of a transaction. However, it does work well as a backing  
store for for mostly static data (Wikipedia) and data that is not  
audit sensitive (37signals). On the other hand, with their purchase of  
Netfrastructure, I believe that MySql is positioned to become a  
technology leader in the next generation of transactional RDBMS’ in the  
next two years.

I do like Firebird RDBMS, and the ruby support for Firebird is quite  
decent. You should probably also download and test the personal  
versions of DB2, MS-SQL, and Oracle if you plan to distribute your  
application.

Perhaps you could give us a better idea of the scope of the problem?

---

<div class="post-metadata">

**Author:** ![pabloz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c37758/32.png) [@pabloz](https://www.ruby-forum.com/u/pabloz)\
**Post date:** [November 28, 2006, 9:00pm UTC](https://www.ruby-forum.com/t/use-of-xml/77561/6 "2006-11-28T21:00:15Z")

</div>

Pabloz wrote:

> Hi
> 
> Is it a good idea to keep for example blog posts in xml file rather than  
> mysql? Right now i am trying this kind of project and its going really  
> really slow, i dont have a model, i learn REXML, but still cant add  
> nothing to my xml from a form for example. Anyway…is this a good way?  
> or You would suggest database?

You can think of a basic xml file as a database with far less features  
and flexibility.

Why not go with a database? Rails make it dead simple to do so.
