Login | Register
My pages Projects Community openCollabNet

Discussions > dev > Propel objects to XML

propel
Discussion topic

Back to topic list

Propel objects to XML

Reply

Author Ron Rademaker <r dot rademaker at virtualbuilding dot nl>
Full name Ron Rademaker <r dot rademaker at virtualbuilding dot nl>
Date 2006-12-14 07:28:48 PST
Message Hello,

In my own propel branch (currently based on 1.3) I've added a function
toXML to the generated om objects. It allows one to create a XML
representation of the object in a DomDocument. Most of my propel changes
depend heavily on my php framework (non open source) so contributing
that to Propel is not useful. The toXML however, depends only a little
bit on the framework and if people are interested, I'll make some
changes to get rid of the dependencies all together and commit it in the
1.3 branch. So, who's interested?

Function works as follows:

public function toXML(DomDocument $dom, DomNode $node = null, $recurse = 0);

$dom - The DomDocument where XML will be generated in
$node - The DomNode where the XML will be appended to (if null a root
DomNode will be added to $dom)
$recurse - How deep the function recurses into foreign tables (both FK
as FKRef)

The function returns a DomNode.

Example, db:

Table Foo, columns: id, foo, bar_id (FK to Bar)
Tabe Bar, columns: id, bar
Table Foobar, columns: id, foobar, foo_id (FK to Foo)

contents of the db:

Foo
1,"foo",1

Bar
1,"bar"

Foobar
1,"foobar1",1
2."foobar2",2

And some code:

$foo = FooPeer::retrieveByPk(1);
$dom = new DomDocument("1.0");
$rootNode = $dom->appendChil​d($dom->createEl​ement("root") );
$fooNode = $foo->toXML($dom, $rootNode, 1);
print $dom->saveXML();

Will give you:
<?xml version='1.0'?>
<root>
    <foo>
       <id>1</id>
       <foo>foo</foo>
       <bar_id>1</bar_id>
       <bar>
          <id>1</id>
          <bar>bar</bar>
       </bar>
       <foobar>
          <id>1</id>
          <foobar>foobar​1</foobar>
          <foo_id>1</foo_id>
       </foobar>
       <foobar>
          <id>2</id>
          <foobar>foobar​2</foobar>
          <foo_id>1</foo_id>
       </foobar>
    </foo>
</root>

Ron

« Previous message in topic | 1 of 13 | Next message in topic »

Messages

Show all messages in topic

Propel objects to XML Ron Rademaker <r dot rademaker at virtualbuilding dot nl> Ron Rademaker <r dot rademaker at virtualbuilding dot nl> 2006-12-14 07:28:48 PST
     Re: [propel-dev] Propel objects to XML hlellelid Hans Lellelid 2006-12-14 07:36:55 PST
         Re: [propel-dev] Propel objects to XML =?ISO-8859-1?Q?David_Z=FClke?= <dz at bitxtender dot com> =?ISO-8859-1?Q?David_Z=FClke?= <dz at bitxtender dot com> 2006-12-14 07:41:18 PST
             Re: [propel-dev] Propel objects to XML hlellelid Hans Lellelid 2006-12-14 07:45:56 PST
         Re: [propel-dev] Propel objects to XML Ron Rademaker <r dot rademaker at virtualbuilding dot nl> Ron Rademaker <r dot rademaker at virtualbuilding dot nl> 2006-12-14 07:53:48 PST
         Re: [propel-dev] Propel objects to XML Thomas Rabaix <thomas at rabaix dot net> Thomas Rabaix <thomas at rabaix dot net> 2006-12-14 08:07:03 PST
     Re: [propel-dev] Propel objects to XML =?ISO-8859-1?Q?David_Z=FClke?= <dz at bitxtender dot com> =?ISO-8859-1?Q?David_Z=FClke?= <dz at bitxtender dot com> 2006-12-14 07:38:47 PST
         Re: [propel-dev] Propel objects to XML Ron Rademaker <r dot rademaker at virtualbuilding dot nl> Ron Rademaker <r dot rademaker at virtualbuilding dot nl> 2006-12-14 07:57:54 PST
         Re: [propel-dev] Propel objects to XML Alan Pinstein <apinstein at mac dot com> Alan Pinstein <apinstein at mac dot com> 2006-12-14 08:21:55 PST
             Re: [propel-dev] Propel objects to XML Ants Aasma <ants dot aasma at mig dot ee> Ants Aasma <ants dot aasma at mig dot ee> 2006-12-14 08:40:08 PST
                 Re: [propel-dev] Propel objects to XML Alan Pinstein <apinstein at mac dot com> Alan Pinstein <apinstein at mac dot com> 2006-12-14 08:43:51 PST
                     Re: [propel-dev] Propel objects to XML Ants Aasma <ants dot aasma at mig dot ee> Ants Aasma <ants dot aasma at mig dot ee> 2006-12-14 08:53:04 PST
                         Re: [propel-dev] Propel objects to XML Alan Pinstein <apinstein at mac dot com> Alan Pinstein <apinstein at mac dot com> 2006-12-14 09:11:14 PST
Messages per page: