Merging two XML tree: xslt or dom ?

Y

Yannick Patois

Hi,

I would like to merge two XML document, or more exacly enrich a document
by inheritiong from another.

I read a bit about XSLT and I know a bit of python/sax/dom, and I dont
know where I should go. I tried xslt, without success yet (but I dont
know much about it) so I failed back on python+dom wher I know a bit more.

I'm asking you if it's a good choice, or if I should use XSLT for this.

Small example of what I want:

File1:
<toto>
<tata>bla</tata>
<titi>bli</titi>
<toto>

File2:
<toto>
<tata>bla bla</tata>
<tutu>blu</tutu>
<toto>

Result:
<toto>
<tata>bla bla</tata>
<titi>bli</titi>
<tutu>blu</tutu>
<toto>

Note that <tata> value has been supereseded by file2 value, and <titi>
added as not present in file2. To me, it must look like OO "inheritance"
property, even if I dont know if this has any meaning for XML.

More concrelty, it's about compilation commands to issue for a given
file, right now I represent them like this (prototype):

<package name="default">
<spi_configure>
<command name="./configure" argument="$SPI_PREFIX"/>
</spi_configure>
<spi_make>
<command name="make" />
</spi_make>
<spi_makeinstall>
<command name="make" argument="install" />
</spi_makeinstall>
<spi_check>
<command name="make" argument="check" />
</spi_check>
</package>


<package name="foo" version="1.0.0">
<spi_make>
<command name="make" argument="all" />
<command name="make" argument="dylibs" />
</spi_make>
</package>


The package "foo" build exactly like the default procedure, except that
the make step is a bit different. That's what I need to express by
creating a new xml file containing all the informations. Then I know how
to convert this to bash or whatever using xslt.

Thanks for any help.

Yannick
 
U

Uche Ogbuji

Yannick Patois said:
Hi,

I would like to merge two XML document, or more exacly enrich a document
by inheritiong from another.

I read a bit about XSLT and I know a bit of python/sax/dom, and I dont
know where I should go. I tried xslt, without success yet (but I dont
know much about it) so I failed back on python+dom wher I know a bit more.

I'm asking you if it's a good choice, or if I should use XSLT for this.

Small example of what I want:

File1:
<toto>
<tata>bla</tata>
<titi>bli</titi>
<toto>

File2:
<toto>
<tata>bla bla</tata>
<tutu>blu</tutu>
<toto>

Result:
<toto>
<tata>bla bla</tata>
<titi>bli</titi>
<tutu>blu</tutu>
<toto>

Note that <tata> value has been supereseded by file2 value, and <titi>
added as not present in file2. To me, it must look like OO "inheritance"
property, even if I dont know if this has any meaning for XML.

You can use DOM or XSLT for this. For an example of the latter, see:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/135131

With XSLT, you're going to need the document() function, then you'll
need to set up templates for each level of the doc that could be
merged, using various tricks to keep the contexts of both source
documents in sync.

I'd think it easier in DOM.

Good luck.

--
Uche Ogbuji Fourthought, Inc.
http://uche.ogbuji.net http://4Suite.org http://fourthought.com
Perspective on XML: Steady steps spell success with Google -
http://www.adtmag.com/article.asp?id=9663
Use XML namespaces with care -
http://www-106.ibm.com/developerworks/xml/library/x-namcar.html
Managing XML libraries - http://www.adtmag.com/article.asp?id=9160
Commentary on "Objects. Encapsulation. XML?" -
http://www.adtmag.com/article.asp?id=9090
A survey of XML standards -
http://www-106.ibm.com/developerworks/xml/library/x-stand4/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,828
Latest member
LauraCastr

Latest Threads

Top