XML Generator/Merger

F

fuglyducky

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!!!
 
F

fuglyducky

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

fuglyducky

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.
 

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,776
Messages
2,569,603
Members
45,196
Latest member
ScottChare

Latest Threads

Top