sabre-io / xml

sabre/xml is an XML library that you may not hate.
http://sabre.io/xml/
BSD 3-Clause "New" or "Revised" License
516 stars 77 forks source link

Merge elements from different branches #157

Closed danswiser closed 5 years ago

danswiser commented 5 years ago

Please excuse any of my XML terminology, I don't typically use XML.

I have multiple branches where the same element exists. Each branch is holding different information about elements. I'd like to merge them together in the simplest way possible.

Here's a snippet of my XML:

<MultipleFilters>
  <AConfigs ts="Wed Dec 19 16:14:29 2018 UTC" tzo="18000" al="true" loginid="9999">
    <A id="100" fn="John" ln="Smith" desc="Technical_Support" un="jsmith" sk="US_Technical_Support(10)">
      <G id="10" n="US_Nightshift"/>
    </A>
  </AConfigs>
  <ACalls ts="Wed Dec 19 18:17:11 2018 UTC" tzo="18000" al="false">
    <A id="100" aics="5,1;" gid="10" dir="1" cct="3" cq="US_Support" inatt="374" outatt="0" a2aatt="0" tatt="272"/>
  </ACalls>
</MultipleFilters>

What I'm trying to do is combine both elements into a single element (matched by the "id" attribute"). Is there anything within this project that would help me or should I just focus on merging the data before/after this package?

evert commented 5 years ago

@danswiser the best way to look at this library, is similar to using functional programming.

The best way to go about this problem is to look at this similar to writing a reduce() function.

sabre/xml doesn't do any mutations in the DOM, you basically can simultaneously read the entire document and also write the new version of your document in 1 pass.

danswiser commented 5 years ago

That's good enough for me.

Thanks.