XML Generator/Merger

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.

···

On May 26, 9:42 am, fuglyducky <fuglydu...@gmail.com> 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!!!

Forget it...I got it. Nested for loops do the trick.

···

On May 26, 9:47 am, fuglyducky <fuglydu...@gmail.com> wrote:

On May 26, 9:42 am, fuglyducky <fuglydu...@gmail.com> 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.