Friday, 6 February 2015

add nodes to XML from second document, based on matching attribute



I have one xml document which contains lots of great data, but the powers that be have asked me to now include summaries and actors. so the question is how to take data that looks like this:



<mediaList>
<movie id="1125898" dateCreated="2014-04-12" lastModified="2014-05-23">
<title>127 Hours</title>
<director sort="7">Danny Boyle</director>
<genreWrap>
<genre>Drama</genre>
<subGenre>Dramas Based on Real Life</subGenre>
</genreWrap>
<genreWrap>
<genre>Thrillers</genre>
<subGenre>Suspense</subGenre>
</genreWrap>
<LCSpecialTopics>Adventure films</LCSpecialTopics>
<writer sort="7">Simon Beaufoy</writer>
<writer sort="7">Danny Boyle</writer>
<screenplay href="http://ift.tt/1IlVmF5">PN1997.2 .O54 2010</screenplay>
<language>English</language>
<year>2010</year>
<callNumber href="http://ift.tt/1IlVmF8">[DVD] PN1995.9 .A3 B69 2011</callNumber>
<coverArt href="Pics/127Hours.jpg"/>
</movie>
<movie id="1155300" dateCreated="2014-04-12" lastModified="2014-05-23">
<title>Lord Jim</title>
<director sort="9">Richard Brooks</director>
<genreWrap>
<genre>Action and Adventure</genre>
<subGenre>Action Classics</subGenre>
<subGenre>Adventures</subGenre>
</genreWrap>
<genreWrap>
<genre>Classics</genre>
<subGenre>Action Classics</subGenre>
</genreWrap>
<LCSpecialTopics>Adventure films</LCSpecialTopics>
<writer sort="9">Richard Brooks</writer>
<language>English</language>
<year>1965</year>
<callNumber href="http://ift.tt/1IlVmFb">[DVD] PN1995.9 .A3 B76 2004</callNumber>
<coverArt href="Pics/LordJim.jpg"/>
</movie>
<tvShow id="1686708" dateCreated="2014-12-05">
<title differentiator="Series 7">Prime Suspect</title>
<creator sort="10">Lynda La Plante</creator>
<genreWrap>
<genre>Television</genre>
<subGenre>TV Mysteries</subGenre>
<subGenre>TV Dramas</subGenre>
<subGenre>Foreign TV</subGenre>
<subSubGenre>Foreign TV Dramas</subSubGenre>
</genreWrap>
<LCSpecialTopics>Individual programs</LCSpecialTopics>
<language>English</language>
<year>2006</year>
<callNumber href="http://ift.tt/1ySeWPv">[DVD] PN1992.77 .P699 M37 2007</callNumber>
<coverArt href="Pics/PrimeSuspect7.jpg"/>
</tvShow>
<tvShow id="1689302" dateCreated="2014-12-05">
<title differentiator="The Complete Series">Profit</title>
<creator sort="7">David Greenwalt</creator>
<creator sort="6">John McNamara</creator>
<genreWrap>
<genre>Television</genre>
<subGenre>TV Dramas</subGenre>
<subSubGenre>TV Dramedy</subSubGenre>
</genreWrap>
<LCSpecialTopics>Individual programs</LCSpecialTopics>
<language>English</language>
<year>1996</year>
<callNumber href="http://ift.tt/1IlVk0b">[DVD] PN1992.77 .P76 2005</callNumber>
<coverArt href="Pics/Profit.jpg"/>
</tvShow>
</mediaList>


and then using the source material -- seen here,



<root>
<row>
<Heading0>PN 19959 A 3 B 69 2011</Heading0>
<Heading1>[DVD] PN1995.9.A3 B69 2011</Heading1>
<Heading2>127 hours [videorecording] / Fox Searchlight Pictures and Pathâe present, in association with Everest Entertainment ; a Cloud Eight, Decibel Films, Darlow Smithson production ; a Danny Boyle film ; produced by Christian Colson, Danny Boyle, John Smithso</Heading2>
<Heading3>127 hours</Heading3>
<Heading4>127 hours (Motion picture)</Heading4>
<Heading5></Heading5>
<Heading6>Twentieth Century Fox Home Entertainment,</Heading6>
<Heading7>2011</Heading7>
<Heading8></Heading8>
<Heading9>2011</Heading9>
<Heading10>[2011]</Heading10>
<Heading11>eng</Heading11>
<Heading12>Closed-captioned.
English (5.1 Dolby Digital), dubbed French (Dolby surround) or dubbed Spanish (Dolby surround) dialogue, optional French or Spanish subtitles; English subtitles for the deaf and hard of hearing (SDH)</Heading12>
<Heading13>Based on the book "Between a rock and a hard place" by Aron Ralston.
Videodisc release of the 2010 motion picture.
DVD release date: Mar. 1, 2011.
Special features include commentary and deleted scenes.</Heading13>
<Heading14>James Franco, Amber Tamblyn, Kate Mara, Clâemence Poâesy, Kate Burton, Lizzy Caplan, Treat Williams.</Heading14>
<Heading15>"... the powerfully uplifting true story of one man's struggle to survive against mountainous odds. Aron Ralston (James Franco) has a passion for all things outdoors. But when a falling boulder traps him in a remote Utah canyon, a thrill-seeker's adventure becomes the challenge of a lifetime. Over the next five days, Ralston embarks on a remarkable personal journey in which he relies on the memories of family and friends--as well as his own courage and ingenuity--to turn adversity into triumph!"--Container.</Heading15>
<Heading16>1125898</Heading16>
<Heading17>1413868</Heading17>
<Heading18>1351628</Heading18>
<Heading19>0113503003890</Heading19>
</row>
<row>
<Heading0>PN 19959 A 3 B 76 2004</Heading0>
<Heading1>[DVD] PN1995.9.A3 B76 2004</Heading1>
<Heading2>Lord Jim [videorecording] / a film by Richard Brooks ; written for the screen and directed by Richard Brooks.</Heading2>
<Heading3>Lord Jim</Heading3>
<Heading4></Heading4>
<Heading5></Heading5>
<Heading6>Columbia Pictures ; Columbia TriStar Home Entertainment,</Heading6>
<Heading7>2004</Heading7>
<Heading8>1965</Heading8>
<Heading9>2004-1965</Heading9>
<Heading10>[2004]</Heading10>
<Heading11>eng</Heading11>
<Heading12>English or French dialogue, English, French, Japanese, Spanish subtitles; closed-captioned.</Heading12>
<Heading13>Title from container.
Originally released as a motion picture in 1965.
Based on the novel by Joseph Conrad.</Heading13>
<Heading14>Peter O'Toole, James Mason, Eli Wallach, Curt Jurgens, Paul Lukas.</Heading14>
<Heading15>A disgraced 19th-century British sailor lives nobly among natives. From the Joseph Conrad novel.</Heading15>
<Heading16>1155300</Heading16>
<Heading17>1443177</Heading17>
<Heading18>1360820</Heading18>
<Heading19>0113503022411</Heading19>
</row>
<row>
<Heading0>PN 199277 P 699 M 37 2007</Heading0>
<Heading1>[DVD] PN1992.77.P699 M37 2007</Heading1>
<Heading2>Prime suspect. The final act [videorecording] / a co-production of Granada and WGBH Boston ; producers, Andy Harries and Rebecca Eaton ; produced by Andrew Benson ; written by Frank Deasy ; directed by Philip Martin.</Heading2>
<Heading3>Prime suspect.</Heading3>
<Heading4></Heading4>
<Heading5></Heading5>
<Heading6>Acorn Media,</Heading6>
<Heading7>2007</Heading7>
<Heading8></Heading8>
<Heading9>2007</Heading9>
<Heading10>[2007]</Heading10>
<Heading11>eng</Heading11>
<Heading12>Closed-captioned.</Heading12>
<Heading13>Originally broadcast on British television in 2006.
Special features: Fifty-minute behind-the-scenes featurette; photo gallery; cast filmographies.</Heading13>
<Heading14>Helen Mirren, Frank Finlay, Tom Bell, Laura Greenwood.</Heading14>
<Heading15>Detective Superintendent Jane Tennison finds herself searching for Sallie Sturdy, a fourteen-year-old girl presumed murdered. Facing the hospitalization of her father, descending deeper into alcoholism, and resisting pressure to retire quietly, Tennison vows to bring Sallie's killer to justice before ending her career. She forges a surprising friendship with Penny Philips, Sallie's best friend.</Heading15>
<Heading16>1686708</Heading16>
<Heading17>2104396</Heading17>
<Heading18>1500951</Heading18>
<Heading19>0113503133952</Heading19>
</row>
<row>
<Heading0>PN 199277 P 76 2005</Heading0>
<Heading1>[DVD] PN1992.77 .P76 2005</Heading1>
<Heading2>Profit. The complete series [videorecording] / Greenwalt McNamara Productions ; a Stephen J. Cannell Production ; created by David Greenwalt and John McNamara ; executive producers, David Greenwalt and John McNamara ; produced by John B. Moranville.</Heading2>
<Heading3>Profit.</Heading3>
<Heading4></Heading4>
<Heading5></Heading5>
<Heading6>Anchor Bay Entertainment,</Heading6>
<Heading7>2005</Heading7>
<Heading8>1996</Heading8>
<Heading9>2005-1996</Heading9>
<Heading10>c2005.</Heading10>
<Heading11>eng</Heading11>
<Heading12>Closed-captioned.</Heading12>
<Heading13>Title from container.
Originally aired on television in 1996.
Special features include interviews and commentaries.</Heading13>
<Heading14>Adrian Pasdar, Sherman Augustus, Lisa Zane, Lisa Blount, Lisa Darr, Jack Gwaltney, Allison Hossack, Keith Szarabajka.</Heading14>
<Heading15>A charismatic sociopath turns a childhood secret into a ruthless climb up the corporate ladder.</Heading15>
<Heading16>1689302</Heading16>
<Heading17>2106987</Heading17>
<Heading18>1501141</Heading18>
<Heading19>0113503134315</Heading19>
</row>
</root>


the output will look like:



<mediaList>
<movie id="1125898" dateCreated="2014-04-12" lastModified="2014-05-23">
<title>127 Hours</title>
<director sort="7">Danny Boyle</director>
<genreWrap>
<genre>Drama</genre>
<subGenre>Dramas Based on Real Life</subGenre>
</genreWrap>
<genreWrap>
<genre>Thrillers</genre>
<subGenre>Suspense</subGenre>
</genreWrap>
<summary>"... the powerfully uplifting true story of one man's struggle to survive against mountainous odds. Aron Ralston (James Franco) has a passion for all things outdoors. But when a falling boulder traps him in a remote Utah canyon, a thrill-seeker's adventure becomes the challenge of a lifetime. Over the next five days, Ralston embarks on a remarkable personal journey in which he relies on the memories of family and friends--as well as his own courage and ingenuity--to turn adversity into triumph!"</summary>
<LCSpecialTopics>Adventure films</LCSpecialTopics>
<writer sort="7">Simon Beaufoy</writer>
<writer sort="7">Danny Boyle</writer>
<screenplay href="http://ift.tt/1IlVmF5">PN1997.2 .O54 2010</screenplay>
<language>English</language>
<year>2010</year>
<callNumber href="http://ift.tt/1IlVmF8">[DVD] PN1995.9 .A3 B69 2011</callNumber>
<coverArt href="Pics/127Hours.jpg"/>
</movie>
<movie id="1155300" dateCreated="2014-04-12" lastModified="2014-05-23">
<title>Lord Jim</title>
<director sort="9">Richard Brooks</director>
<genreWrap>
<genre>Action and Adventure</genre>
<subGenre>Action Classics</subGenre>
<subGenre>Adventures</subGenre>
</genreWrap>
<genreWrap>
<genre>Classics</genre>
<subGenre>Action Classics</subGenre>
</genreWrap>
<summary>A disgraced 19th-century British sailor lives nobly among natives. From the Joseph Conrad novel.</summary>
<LCSpecialTopics>Adventure films</LCSpecialTopics>
<writer sort="9">Richard Brooks</writer>
<language>English</language>
<year>1965</year>
<callNumber href="http://ift.tt/1IlVmFb">[DVD] PN1995.9 .A3 B76 2004</callNumber>
<coverArt href="Pics/LordJim.jpg"/>
</movie>
<tvShow id="1686708" dateCreated="2014-12-05">
<title differentiator="Series 7">Prime Suspect</title>
<creator sort="10">Lynda La Plante</creator>
<genreWrap>
<genre>Television</genre>
<subGenre>TV Mysteries</subGenre>
<subGenre>TV Dramas</subGenre>
<subGenre>Foreign TV</subGenre>
<subSubGenre>Foreign TV Dramas</subSubGenre>
</genreWrap>
<summary>Detective Superintendent Jane Tennison finds herself searching for Sallie Sturdy, a fourteen-year-old girl presumed murdered. Facing the hospitalization of her father, descending deeper into alcoholism, and resisting pressure to retire quietly, Tennison vows to bring Sallie's killer to justice before ending her career. She forges a surprising friendship with Penny Philips, Sallie's best friend.</summary>
<LCSpecialTopics>Individual programs</LCSpecialTopics>
<language>English</language>
<year>2006</year>
<callNumber href="http://ift.tt/1ySeWPv">[DVD] PN1992.77 .P699 M37 2007</callNumber>
<coverArt href="Pics/PrimeSuspect7.jpg"/>
</tvShow>
<tvShow id="1689302" dateCreated="2014-12-05">
<title differentiator="The Complete Series">Profit</title>
<creator sort="7">David Greenwalt</creator>
<creator sort="6">John McNamara</creator>
<genreWrap>
<genre>Television</genre>
<subGenre>TV Dramas</subGenre>
<subSubGenre>TV Dramedy</subSubGenre>
</genreWrap>
<summary>A charismatic sociopath turns a childhood secret into a ruthless climb up the corporate ladder.</summary>
<LCSpecialTopics>Individual programs</LCSpecialTopics>
<language>English</language>
<year>1996</year>
<callNumber href="http://ift.tt/1IlVk0b">[DVD] PN1992.77 .P76 2005</callNumber>
<coverArt href="Pics/Profit.jpg"/>
</tvShow>
</mediaList>


Every movie or tvshow (in the first document) has an @id attribute which will match a Heading16 element in the second document, when the match is found, Heading15 should be inserted into the movie or tvShow element after the final genreWrap element in a Summary element. Any help would be much obliged. There are movie or tvShow elements which have the same @id attributes because they're a box-set, in case that matters.


No comments:

Post a Comment