Results 1 to 2 of 2

Thread: How to merge nodes with same value by preserving structure in XML

  1. #1

    Thread Starter
    Fanatic Member Flashbond's Avatar
    Join Date
    Jan 2013
    Location
    Istanbul
    Posts
    646

    How to merge nodes with same value by preserving structure in XML

    Hi Guys! I want to parse it with VB but if there is an easier way, I am open to suggestions.

    I have:
    Code:
       <search value="5/12/2014">
          <departure value="US">
             <resort value="Barbados">
                <date value="10/25/2014">
                   <price value="1200" />
                   <seat value="9" />
                </date>
             </resort>
          </departure>
       </search>
       <search value="5/12/2014">
          <departure value="US">
             <resort value="Barbados">
                <date value="11/1/2014">
                   <price value="1000" />
                   <seat value="9" />
                </date>
             </resort>
          </departure>
       </search>
       <search value="5/12/2014">
          <departure value="Brazil">
             <resort value="Barbados">
                <date value="10/25/2014">
                   <price value="1100" />
                   <seat value="9" />
                </date>
             </resort>
          </departure>
       </search>
       <search value="5/12/2014">
          <departure value="Brazil">
             <resort value="Barbados">
                <date value="11/1/2014">
                   <price value="1000" />
                   <seat value="9" />
                </date>
             </resort>
          </departure>
       </search>
       <search value="5/13/2014">
          <departure value="US">
             <resort value="Barbados">
                <date value="10/4/2014">
                   <price value="1100" />
                   <seat value="9" />
                </date>
             </resort>
          </departure>
       </search>
       <search value="5/13/2014">
          <departure value="US">
             <resort value="Barbados">
                <date value="10/11/2014">
                   <price value="1100" />
                   <seat value="6" />
                </date>
             </resort>
          </departure>
       </search>
    I want to merge all nodes if have the same value until it has a different child value like this:
    Code:
       <search value="5/12/2014">
          <departure value="US">
             <resort value="Barbados">
                <date value="10/25/2014">
                   <price value="1200" />
                   <seat value="9" />
                </date>
                <date value="11/1/2014">
                   <price value="1000" />
                   <seat value="9" />
                </date>
             </resort>
          </departure>
          <departure value="Brazil">
             <resort value="Barbados">
                <date value="10/25/2014">
                   <price value="1100" />
                   <seat value="9" />
                </date>
                <date value="11/1/2014">
                   <price value="1000" />
                   <seat value="9" />
                </date>
             </resort>
          </departure>
       </search>
       <search value="5/13/2014">
          <departure value="US">
             <resort value="Barbados">
                <date value="11/1/2014">
                   <price value="1000" />
                   <seat value="9" />
                </date>
                <date value="10/11/2014">
                   <price value="1100" />
                   <seat value="6" />
                </date>
             </resort>
          </departure>
       </search>
    Thanks a lot!
    God, are you punishing me because my hair is better than yours? -Jack Donaghy

  2. #2
    Lively Member
    Join Date
    Sep 2013
    Posts
    117

    Re: How to merge nodes with same value by preserving structure in XML

    A different structure would be a lot better. It needs an outer enclosing node to be valid xml

Posting Permissions

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



Click Here to Expand Forum to Full Width