# Xml-map

**URL:** <https://www.ruby-forum.com/t/xml-map/109319>\
**Category:** Ruby\
**Created:** [July 13, 2007, 12:05pm UTC](https://www.ruby-forum.com/t/xml-map/109319 "2007-07-13T12:05:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcin\_r](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e5b9ba/32.png) [@marcin\_r](https://www.ruby-forum.com/u/marcin_r)\
**Post date:** [July 13, 2007, 12:05pm UTC](https://www.ruby-forum.com/t/xml-map/109319/1 "2007-07-13T12:05:02Z")

</div>

Hello.

Thanks to my bas from softwarelab.eu (little advert)  
I’m starting to release code that i wrote so far 🙂  
for now there’s little - or no- documentation but i’ll be working on it

back to the topic:

xml-map is easy to use XML to ruby object library with rails-like  
models,  
validators and more ^^, it uses vary fast libxml instead of slow and old  
REXML, you need version 0.4 of libxml to work properly

you can grab it from svn from [xml-map.rubyforge.org](http://xml-map.rubyforge.org)

What is done:

- Import valid XML
- autogenerate models
- some validators

what i’m working on:

- all validators from XmlSchema
- autogenerating models with validators from xsd

require ‘rubygems’  
require ‘xml/libxml’

require ‘…/lib/xml\_models’

require ‘pp’

============================================

> cat sample/sample.rb

tfile = ARGV.shift || “test.xml”

# auogenerate required models

xm=XmlMapper.new({:generate=\>true, :file=\> $stdout})

#load xml file  
doc = XML::Document.file(tfile)  
root\_node = doc.root

# parase xml and create model instances

rn = xm.parse\_xml(root\_node)

pp rn

rn.content[0].content\<\<“dwa”

rn.save(out.xml)

============================================

> cat sample/test.xml

\<?xml version="1.0"?\> raz dwa trzy ============================================ ruby sample.rb class RootNode \< XmlNode end

class SimpleNode \< XmlNode  
end

class ComplicatedNode \< XmlNode  
end

#===== class generation ends here, you can copy above classes add  
attr\_accessors for desired attributes

#\<RootNode:0xb7810364  
@content=  
[#\<SimpleNode:0xb780fc20 @content=[“raz”], @node\_name=“simple”\>,  
#\<ComplicatedNode:0xb780f39c  
@content=  
[#\<SimpleNode:0xb780eac8 @content=[“dwa”], @node\_name=“simple”\>,  
#\<SimpleNode:0xb780e640 @content=[“trzy”], @node\_name=“simple”\>],  
@node\_name=“Complicated”,  
@param1=“string”,  
@param2=“2”,  
@param3=“3”\>],  
@node\_name=“root”\>

======================================

soon i’m going to provide more documentation and more compleate support  
for  
xsd and validators, if anyone is interested in helping in this easy but  
time  
consuming work, please let me know ^^

## =================================== Marcin R.

Friends teach what you should know  
Enemies Teach what you have to know

---

<div class="post-metadata">

**Author:** ![marcin\_r](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e5b9ba/32.png) [@marcin\_r](https://www.ruby-forum.com/u/marcin_r)\
**Post date:** [July 13, 2007, 12:26pm UTC](https://www.ruby-forum.com/t/xml-map/109319/2 "2007-07-13T12:26:05Z")

</div>

two more things:

- this module was tested on nearly 20mb XML file and worked fine, it  
made  
syncing between database and xml piece of cake (i’m going to relase code  
that  
made comparing between AR models and XmlModels so easy)

- it was NOT tested on strange xmls - so PLEASE send me everything you  
got,  
strange xml’s with CDATA, strange characters encodings etc if it’s not  
parased properly by this library

---

<div class="post-metadata">

**Author:** ![marcin\_r](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e5b9ba/32.png) [@marcin\_r](https://www.ruby-forum.com/u/marcin_r)\
**Post date:** [July 13, 2007, 12:55pm UTC](https://www.ruby-forum.com/t/xml-map/109319/3 "2007-07-13T12:55:07Z")

</div>

Hi Marcin,

Marcin R. wrote:

> it made syncing between database and xml piece of cake (i’m going to relase code that  
> made comparing between AR models and XmlModels so easy)

I am looking forward to this. I had just been looking at doing a project  
which could use AR \<-\> xml.

Thanks for releasing!

Cheers,  
Mark

---

<div class="post-metadata">

**Author:** ![marcin\_r](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e5b9ba/32.png) [@marcin\_r](https://www.ruby-forum.com/u/marcin_r)\
**Post date:** [August 13, 2007, 7:52pm UTC](https://www.ruby-forum.com/t/xml-map/109319/4 "2007-08-13T19:52:43Z")

</div>

Hi,

Where can one get xml-map from?

Thanks

Ed

On 7/13/07, Marcin R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> REXML, you need version 0.4 of libxml to work properly
> 
> - autogenerating models with validators from xsd

–  
Ed Howland

> **[Green Programming](http://greenprogrammer.blogspot.com)**
>
> Environmentally safe code

“The information transmitted is intended only for the person or entity  
to which it is addressed and may contain proprietary, confidential  
and/or legally privileged material. Any review, retransmission,  
dissemination or other use of, or taking of any action in reliance  
upon, this information by persons or entities other than the intended  
recipient is prohibited. If you received this in error, please contact  
the sender and delete the material from all computers.”

---

<div class="post-metadata">

**Author:** ![marcin\_r](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e5b9ba/32.png) [@marcin\_r](https://www.ruby-forum.com/u/marcin_r)\
**Post date:** [August 13, 2007, 8:11pm UTC](https://www.ruby-forum.com/t/xml-map/109319/5 "2007-08-13T20:11:45Z")

</div>

On 8/13/07, Ed Howland [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> Where can one get xml-map from?

You quoted it in your reply.
