Merging two XML tree: xslt or dom ?

Discussion in 'XML' started by Yannick Patois, Jul 20, 2004.

  1. 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

    --
    _/ Yannick Patois \___________________________________________________
    | web: http://feelingsurfer.net/garp/ | Garp sur irc undernet |
    | email: | |
    | ATTAC dans le Pays de Gex: http://attacgex.ouvaton.org |
     
    Yannick Patois, Jul 20, 2004
    #1
    1. Advertising

  2. Yannick Patois

    Uche Ogbuji Guest

    Yannick Patois <> wrote in message news:<cdiokd$jil$>...
    > 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/
     
    Uche Ogbuji, Jul 23, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ray
    Replies:
    2
    Views:
    416
  2. Prashanth  Ellina

    XSLT modifying an xml dom tree?

    Prashanth Ellina, Aug 1, 2005, in forum: XML
    Replies:
    6
    Views:
    491
    Prashanth Ellina
    Aug 2, 2005
  3. Joris Gillis
    Replies:
    2
    Views:
    1,568
    Joris Gillis
    Jun 16, 2006
  4. Stub

    B tree, B+ tree and B* tree

    Stub, Nov 12, 2003, in forum: C Programming
    Replies:
    3
    Views:
    10,247
  5. JMan
    Replies:
    7
    Views:
    487
    Martin Honnen
    Oct 15, 2008
Loading...

Share This Page