Starter Code:
var xDocument = XDocument.Parse(rawXmlString);
Imagine that I've loaded the XML below in an XDocument and I'd like to use Linq-to-XML:
<ParameterValues>
<ParameterValue>
<Name>Head Coach</Name>
<Value>Bill Belichick</Value>
</ParameterValue>
<ParameterValue>
<Name>Quarterback</Name>
<Value>Mac Jones</Value>
</ParameterValue>
</ParameterValues>
With C#, keying off of the Name values Head Coach and Quarterback respectively, how can I replace:
Bill BelichickwithMike Vrabel?Mac JoneswithKirk Cousins?
- Also, if it helps, this XML document will exist in memory only. It will not be persisted to a file.
ParameterValueswill indeed be the root node.- The
ParameterValuenodes may be out of order and someday there may be more than two subnodes.
What I've tried:
var xDocument = XDocument.Parse(rawXmlString);
I've experimented with various Linq-to-XML query methods but without much luck so far.
Here it is via LINQ to XML.
c#
Output