Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Merging two xml files into a third one

    Now, I'm sure that a variation of this question has been asked a thousand times in different forums including this one. But, my situation is kind of unique, and would really appreciate some help on this.

    This is my situation. Say this is file one:

    Code:
    <rootu>
    <MainID>5555</MainID>
    <fileversion>1.003</fileversion>
    <mainu Important="True">
    <ID>1234</ID>
    <Content1>Content</Content1>
    <Link>Link.htm</Link>
    <Content2>Content</Content2>
    </mainu>
    <mainu Important="True">
    <ID>2432</ID>
    <Content1>Content</Content1>
    <Link>Link.htm</Link>
    <Content2>Content</Content2>
    </mainu>
    <mainu Important="False">
    <ID>4444</ID
    <Content1>Content</Content1>
    <Link>Link.htm</Link>
    <Content2>Content</Content2>
    </mainu>
    </rootu>
    A little note, the Important True/False values are something that I would like to have as an important distinguisher, but, if nobody can come up with a way to help me based on using such a distinguishing mechanism, than at the least, I still would loved to be helped based on the same idea, but with no Important value as a distinguisher (as if I never even included that). I will further explain important value in a second, but first...

    This is file 2:

    Code:
    <rootu>
    <fileversion>1.22</fileversion>
    <mainu>
    <Date>2009-07-03T15:25:36Z</Date>
    <ID>1234</ID>
    <Content1>Content</Content1>
    <Link>Link.htm</Link>
    <newContent1>More Content</newContent1>
    <newLinkText>Text</newLinkText>
    <newLink>Link2.htm</newLink>
    <moreContent>Information</moreContent>
    </mainu>
    <mainu>
    <Date>2009-07-03T15:25:36Z</Date>
    <ID>6783</ID>
    <Content1>Content</Content1>
    <Link>Link.htm</Link>
    <newContent1>More Content</newContent1>
    <newLinkText>Text</newLinkText>
    <newLink>Link2.htm</newLink>
    <moreContent>Information</moreContent>
    </mainu>
    <mainu>
    <Date>2009-07-03T15:25:36Z</Date>
    <ID>1112</ID>
    <Content1>Content</Content1>
    <Link>Link.htm</Link>
    <newContent1>More Content</newContent1>
    <newLinkText>Text</newLinkText>
    <newLink>Link2.htm</newLink>
    <moreContent>Information</moreContent>
    </mainu>
    <mainu>
    <Date>2009-07-03T15:25:36Z</Date>
    <ID>2432</ID>
    <Content1>Content</Content1>
    <Link>Link.htm</Link>
    <newContent1>More Content</newContent1>
    <newLinkText>Text</newLinkText>
    <newLink>Link2.htm</newLink>
    <moreContent>Information</moreContent>
    </mainu>
    <mainu>
    <Date>2009-07-03T15:25:36Z</Date>
    <ID>4444</ID>
    <Content1>Content</Content1>
    <Link>Link.htm</Link>
    <newContent1>More Content</newContent1>
    <newLinkText>Text</newLinkText>
    <newLink>Link2.htm</newLink>
    <moreContent>Information</moreContent>
    </mainu>
    <mainu>
    <Date>2009-07-03T15:25:36Z</Date>
    <ID>1234</ID>
    <Content1>Content</Content1>
    <Link>Link.htm</Link>
    <newContent1>More Content</newContent1>
    <newLinkText>Text</newLinkText>
    <newLink>Link2.htm</newLink>
    <moreContent>Information</moreContent>
    </mainu>
    </rootu>
    Now, it might already be obvious what I want to do, but, I'll show it, this is what I want the resulting newly merged xml file to look like:

    Code:
    <rootu>
    <MainID>5555</MainID>
    <fileversion>Whatever ends up here doesn't matter...</fileversion>
    <mainu Important="True">
    <Date>2009-07-03T15:25:36Z</Date>
    <ID>1234</ID>
    <Content1>Content</Content1>
    <Link>Link.htm</Link>
    <newContent1>More Content</newContent1>
    <newLinkText>Text</newLinkText>
    <newLink>Link2.htm</newLink>
    <moreContent>Information</moreContent>
    <Content2>Content</Content2>
    </mainu>
    <mainu Important="True">
    <Date>2009-07-03T15:25:36Z</Date>
    <ID>4444</ID>
    <Content1>Content</Content1>
    <Link>Link.htm</Link>
    <newContent1>More Content</newContent1>
    <newLinkText>Text</newLinkText>
    <newLink>Link2.htm</newLink>
    <moreContent>Information</moreContent>
    <Content2>Content</Content2>
    </mainu>
    <mainu Important="True">
    <Date>2009-07-03T15:25:36Z</Date>
    <ID>1234</ID>
    <Content1>Content</Content1>
    <Link>Link.htm</Link>
    <newContent1>More Content</newContent1>
    <newLinkText>Text</newLinkText>
    <newLink>Link2.htm</newLink>
    <moreContent>Information</moreContent>
    <Content2>Content</Content2>
    </mainu>
    </rootu>
    So put into words, what I need to do is merge two xml files into a third one based on matchings in the ID value inside the mainu attribute and also having as many new mainu's based matching ID values as there are in file2, no matter how many times a matching ID occurance happens with the same value (in this case "1234"). That's what I'd really like to accomplish.

    Also, if anyone can even further help me, and explain how I can ONLY merge the mainu's if both the ID matches and the Important value is set to true. I know that is even more tricky, and if I can't make use of the concept, I know a way around it, so it's not as important. But, I really especially need help on what I mentioned above.

    Thanks allot for any help.
    Last edited by PhilN; 07-04-2009 at 09:33 AM.

  • #2
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    .....
    Last edited by PhilN; 07-04-2009 at 09:34 AM.

  • #3
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by PhilN View Post
    Now, I'm sure that a variation of this question has been asked a thousand times in different forums including this one. But, my situation is kind of unique, and would really appreciate some help on this.

    This is my situation. Say this is file one:

    Code:
    <rootus>
    <MainID>5555</MainID>
    <fileversion>1.003</fileversion>
    <mainu Important="True">
    <ID>1234</ID>
    <Content1>Content</Content1>
    <Link>Link.htm</Link>
    <Content2>Content</Content2>
    </mainu>
    <mainu Important="True">
    <ID>2432</ID>
    <Content1>Content</Content1>
    <Link>Link.htm</Link>
    <Content2>Content</Content2>
    </mainu>
    <mainu Important="False">
    <ID>4444</ID
    <Content1>Content</Content1>
    <Link>Link.htm</Link>
    <Content2>Content</Content2>
    </mainu>
    </rootu>
    A little note, the Important True/False values are something that I would like to have as an important distinguisher, but, if nobody can come up with a way to help me based on using such a distinguishing mechanism, than at the least, I still would loved to be helped based on the same idea, but with no Important value as a distinguisher (as if I never even included that). I will further explain important value in a second, but first...

    This is file 2:
    Code:
    <rootu>
    <fileversion>1.22</fileversion>
    <mainu>
    <Date>2009-07-03T15:25:36Z</Date>
    <ID>1234</ID>
    <Content1>Content</Content1>
    <Link>Link.htm</Link>
    <newContent1>More Content</newContent1>
    <newLinkText>Text</newLinkText>
    <newLink>Link2.htm</newLink>
    <moreContent>Information</moreContent>
    </mainu>
    <mainu>
    <Date>2009-07-03T15:25:36Z</Date>
    <ID>6783</ID>
    <Content1>Content</Content1>
    <Link>Link.htm</Link>
    <newContent1>More Content</newContent1>
    <newLinkText>Text</newLinkText>
    <newLink>Link2.htm</newLink>
    <moreContent>Information</moreContent>
    </mainu>
    <mainu>
    <Date>2009-07-03T15:25:36Z</Date>
    <ID>1112</ID>
    <Content1>Content</Content1>
    <Link>Link.htm</Link>
    <newContent1>More Content</newContent1>
    <newLinkText>Text</newLinkText>
    <newLink>Link2.htm</newLink>
    <moreContent>Information</moreContent>
    </mainu>
    <mainu>
    <Date>2009-07-03T15:25:36Z</Date>
    <ID>2432</ID>
    <Content1>Content</Content1>
    <Link>Link.htm</Link>
    <newContent1>More Content</newContent1>
    <newLinkText>Text</newLinkText>
    <newLink>Link2.htm</newLink>
    <moreContent>Information</moreContent>
    </mainu>
    <mainu>
    <Date>2009-07-03T15:25:36Z</Date>
    <ID>4444</ID>
    <Content1>Content</Content1>
    <Link>Link.htm</Link>
    <newContent1>More Content</newContent1>
    <newLinkText>Text</newLinkText>
    <newLink>Link2.htm</newLink>
    <moreContent>Information</moreContent>
    </mainu>
    <mainu>
    <Date>2009-07-03T15:25:36Z</Date>
    <ID>1234</ID>
    <Content1>Content</Content1>
    <Link>Link.htm</Link>
    <newContent1>More Content</newContent1>
    <newLinkText>Text</newLinkText>
    <newLink>Link2.htm</newLink>
    <moreContent>Information</moreContent>
    </mainu>
    </rootu>
    Now, it might already be obvious what I want to do, but, I'll show it, this is what I want the resulting newly merged xml file to look like:
    Code:
    <rootus>
    <MainID>5555</MainID>
    <fileversion>Whatever ends up here doesn't matter...</fileversion>
    <mainu Important="True">
    <Date>2009-07-03T15:25:36Z</Date>
    <ID>1234</ID>
    <Content1>Content</Content1>
    <Link>Link.htm</Link>
    <newContent1>More Content</newContent1>
    <newLinkText>Text</newLinkText>
    <newLink>Link2.htm</newLink>
    <moreContent>Information</moreContent>
    <Content2>Content</Content2>
    </mainu>
    <mainu Important="True">
    <Date>2009-07-03T15:25:36Z</Date>
    <ID>4444</ID>
    <Content1>Content</Content1>
    <Link>Link.htm</Link>
    <newContent1>More Content</newContent1>
    <newLinkText>Text</newLinkText>
    <newLink>Link2.htm</newLink>
    <moreContent>Information</moreContent>
    <Content2>Content</Content2>
    </mainu>
    <mainu Important="True">
    <Date>2009-07-03T15:25:36Z</Date>
    <ID>1234</ID>
    <Content1>Content</Content1>
    <Link>Link.htm</Link>
    <newContent1>More Content</newContent1>
    <newLinkText>Text</newLinkText>
    <newLink>Link2.htm</newLink>
    <moreContent>Information</moreContent>
    <Content2>Content</Content2>
    </mainu>
    </rootu>
    So put into words, what I need to do is merge two xml files into a third one based on matchings in the ID value inside the mainu attribute and also having as many new mainu's based matching ID values as there are in file2, no matter how many times a matching ID occurance happens with the same value (in this case "1234"). That's what I'd really like to accomplish.

    Also, if anyone can even further help me, and explain how I can ONLY merge the mainu's if both the ID matches and the Important value is set to true. I know that is even more tricky, and if I can't make use of the concept, I know a way around it, so it's not as important. But, I really especially need help on what I mentioned above.

    Thanks allot for any help.
    put your code between [ code] and [ /code] tags, without spaces, please. You can edit your first post to do that. Thank you.
    - at first look the xml from first and last snipet is invalid, tags rootu, rootus must be closed with same tag name.
    - is ambigous to mix two files without some external logic, where you take the decisions how you want to mix different parts of the files
    - once you know how you want to mix them you can use xslt to do that.

    http://www.jenitennison.com/xslt/merging-docs.xml

    best regards

    best regards

  • #4
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I knew somebody was going to say that, but, I already pointed out my mistake. I did not know I could edit my post, so I put it in my reply to my post.

    I know I need to merge it using xslt, or java, but, what do you (or anybody) think is a good way of doing this?

    Also, in what you said "once (I) know how I want mix them..." I already showed how I want to mix them with how I showed the output on file 3.

    Sorry for not putting the code in [Code] tags. It's friday night and I'm going out, so I guess I'll update that tomarrow. But, I hope somebody could help me on this.

    I have found some other interesting stuff on the interent that I'll try to experiment with.

    I might sound like somewhat of a noob. But I'm not. Every single time I ran into problems, I always figured a way to do it, after much experimentation. Any help would be very great, though, and thanks in advance.
    Last edited by PhilN; 07-04-2009 at 03:50 AM.

  • #5
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by PhilN View Post
    I knew somebody was going to say that, but, I already pointed out my mistake. I did not know I could edit my post, so I put it in my reply to my post.

    Sorry for not putting the code in [Code] tags. It's friday night and I'm going out, so I guess I'll update that tomarrow. But, I hope somebody could help me on this.
    the code stuff is to help us to read the post, it's not really a 'crime' to not use them,

    I know I need to merge it using xslt, or java, but, what do you (or anybody) think is a good way of doing this?

    Also, in what you said "once (I) know how I want mix them..." I already showed how I want to mix them with how I showed the output on file 3.

    I have found some other interesting stuff on the interent that I'll try to experiment with.

    I might sound like somewhat of a noob. But I'm not. Every single time I ran into problems, I always figured a way to do it, after much experimentation. Any help would be very great, though, and thanks in advance.
    now I'm confused, you have any specific problem? I want to help you but I don't think I want to write the xslt for you.

    best regards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •