Short version:
Could anyone suggest or provide a sample in LINQ to XML for VB, or in an XSLT of how to change one XML element into another (without hardcoding an element-by-element copy of all the unchanged elements)?
Background:
I have an XML file, that I think is properly formed, that contains a root entry that is <collection
> and multiple <dvd
> elements. Within a DVD, there are Genres and Tags, as shown below. (I cut out a lot of the other elements for simplicity).
What I want to do is turn any <Tag
> elements that might be present into an additional <Genre
>. For example, in the entry below, I need to add <Genre
>Kids</Genre
>. (I realize that it is actually the NAME attribute of the TAG element that I'm looking to turn into the GENRE element, but if I could even figure out how to create a new GENRE called "Tag" I'd be much further ahead and could probably puzzle out the rest.)
I've never done anything much with XML. My understanding is that I could use an XSLT transform file and a XSLCompiledTransform or I could use LINQ to XML (I have Visual Basic 9, and would prefer to do it all inside of VB). [I'm sure there are a number of other approaches, too.]
Trouble is, I can't find any examples of XSLT or LINQ syntax that tell me how to turn one element into another. I could write out enough LINQ to copy all of the elements one by one, but there has got to be an easier way than hardcoding a copy of all the elements that don't change! (There has got to be!)
So, if someone who knows could point me to an example or give me a hand with a bit of starter code in LINQ or XSLT, I would be forever grateful (OK, maybe not forever, but at least for a long time!).
Thanks.
Sample XML:
<Collection>
<DVD>
<ID>0000502461</ID>
<Title>Cirque du Soleil: Alegría</Title>
<Released>2002-05-31</Released>
<RunningTime>90</RunningTime>
<Genres>
<Genre>Family</Genre>
<Genre>Music</Genre>
</Genres>
<Overview>What if anything were possible? What if ...
</Overview>
<Notes/>
<Tags>
<Tag Name="Kids" FullName="Kids"/>
</Tags>
</DVD>
</Collection>