XML Generator/Merger

Discussion in 'Ruby' started by fuglyducky, May 26, 2010.

  1. fuglyducky

    fuglyducky Guest

    Before I get into this, I need to say that I am not a programmer and
    have very limited programming experience in any language, let alone
    Ruby. With that said, Ruby is the language I know the best (which
    really isn't saying much). Regardless...

    I have been working on a script that will take multiple predefined XML
    template files and merge them as needed. I was able to do this by:

    1. Convert file1 XML into an array where each line is an element in
    the array
    2. Convert entire file2 into a string and insert it into the second to
    last element in file1 array
    (this is to insert a subsection of XML inside the </close> tag of the
    file1 XML

    Example:

    file1:
    <header>
    <somevalue/>
    </header>

    file2:
    <other>
    <anothervalue/>
    </other>

    Merged:
    <header>
    <somevalue/>
    <other>
    <anothervalue/>
    </other>
    </header>


    This works perfectly. My problem is that I need to randomize the
    number of individual pieces like this...

    -single Header
    -multiple subElem1 (1+)
    -each subElem1 can contain multiple subElem2 (1+)
    -each subElem2 may contain multiple subElem3 and subElem4 (1+)

    Keep in mind that each section has a closing tag so I need a way to
    merge or insert and simply append. My thought was to create a
    multidimensional array and merge from the bottom up but I was
    wondering if there is a faster and/or cleaner way of doing this? It
    doesn't have to be pretty or fast.

    Does anyone have any idea on how I should/could proceed?

    Thanks!!!
    fuglyducky, May 26, 2010
    #1
    1. Advertising

  2. fuglyducky

    fuglyducky Guest

    On May 26, 9:42 am, fuglyducky <> wrote:
    > Before I get into this, I need to say that I am not a programmer and
    > have very limited programming experience in any language, let alone
    > Ruby. With that said, Ruby is the language I know the best (which
    > really isn't saying much). Regardless...
    >
    > I have been working on a script that will take multiple predefined XML
    > template files and merge them as needed. I was able to do this by:
    >
    > 1. Convert file1 XML into an array where each line is an element in
    > the array
    > 2. Convert entire file2 into a string and insert it into the second to
    > last element in file1 array
    > (this is to insert a subsection of XML inside the </close> tag of the
    > file1 XML
    >
    > Example:
    >
    > file1:
    > <header>
    >     <somevalue/>
    > </header>
    >
    > file2:
    > <other>
    >     <anothervalue/>
    > </other>
    >
    > Merged:
    > <header>
    >     <somevalue/>
    >     <other>
    >         <anothervalue/>
    >     </other>
    > </header>
    >
    > This works perfectly. My problem is that I need to randomize the
    > number of individual pieces like this...
    >
    > -single Header
    > -multiple subElem1 (1+)
    > -each subElem1 can contain multiple subElem2 (1+)
    > -each subElem2 may contain multiple subElem3 and subElem4 (1+)
    >
    > Keep in mind that each section has a closing tag so I need a way to
    > merge or insert and simply append. My thought was to create a
    > multidimensional array and merge from the bottom up but I was
    > wondering if there is a faster and/or cleaner way of doing this? It
    > doesn't have to be pretty or fast.
    >
    > Does anyone have any idea on how I should/could proceed?
    >
    > Thanks!!!


    Sorry...I was typing too fast...

    Keep in mind that each section has a closing tag so I need a way to
    merge or insert and NOT simply append.
    fuglyducky, May 26, 2010
    #2
    1. Advertising

  3. fuglyducky

    fuglyducky Guest

    On May 26, 9:47 am, fuglyducky <> wrote:
    > On May 26, 9:42 am, fuglyducky <> wrote:
    >
    >
    >
    > > Before I get into this, I need to say that I am not a programmer and
    > > have very limited programming experience in any language, let alone
    > > Ruby. With that said, Ruby is the language I know the best (which
    > > really isn't saying much). Regardless...

    >
    > > I have been working on a script that will take multiple predefined XML
    > > template files and merge them as needed. I was able to do this by:

    >
    > > 1. Convert file1 XML into an array where each line is an element in
    > > the array
    > > 2. Convert entire file2 into a string and insert it into the second to
    > > last element in file1 array
    > > (this is to insert a subsection of XML inside the </close> tag of the
    > > file1 XML

    >
    > > Example:

    >
    > > file1:
    > > <header>
    > >     <somevalue/>
    > > </header>

    >
    > > file2:
    > > <other>
    > >     <anothervalue/>
    > > </other>

    >
    > > Merged:
    > > <header>
    > >     <somevalue/>
    > >     <other>
    > >         <anothervalue/>
    > >     </other>
    > > </header>

    >
    > > This works perfectly. My problem is that I need to randomize the
    > > number of individual pieces like this...

    >
    > > -single Header
    > > -multiple subElem1 (1+)
    > > -each subElem1 can contain multiple subElem2 (1+)
    > > -each subElem2 may contain multiple subElem3 and subElem4 (1+)

    >
    > > Keep in mind that each section has a closing tag so I need a way to
    > > merge or insert and simply append. My thought was to create a
    > > multidimensional array and merge from the bottom up but I was
    > > wondering if there is a faster and/or cleaner way of doing this? It
    > > doesn't have to be pretty or fast.

    >
    > > Does anyone have any idea on how I should/could proceed?

    >
    > > Thanks!!!

    >
    > Sorry...I was typing too fast...
    >
    > Keep in mind that each section has a closing tag so I need a way to
    > merge or insert and NOT simply append.


    Forget it...I got it. Nested for loops do the trick.
    fuglyducky, May 26, 2010
    #3
    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. Jordan

    PDF Creater / Merger

    Jordan, Aug 7, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    634
    Mark Fitzpatrick
    Aug 7, 2005
  2. =?Utf-8?B?SklNLkgu?=

    q; merger two dataset

    =?Utf-8?B?SklNLkgu?=, May 22, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    433
    =?Utf-8?B?SklNLkgu?=
    May 22, 2006
  3. =?Utf-8?B?SklNLkgu?=

    Question: merger dataset with three tables

    =?Utf-8?B?SklNLkgu?=, Jun 7, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    368
    Ken Cox [Microsoft MVP]
    Jun 8, 2006
  4. mistersulu

    free, python XML merger?

    mistersulu, Dec 11, 2006, in forum: Python
    Replies:
    2
    Views:
    558
    mistersulu
    Dec 13, 2006
Loading...

Share This Page