XmlMassUpdate Multiple Values (MSBuild Community Tasks)
Say you have a config file with the following settings:
<someNode>
<node>value A</node>
<node>value B</node>
<node>value C</node>
</someNode>
For the life of me, I can't figure out how to get XmlMassUpdate to inject the following:
<someNode>
<node>value 1</node>
<node>value 2</node>
<node>value 3</node>
</someNode>
The result looks like this:
<someNode>
<node>value 1</node>
<node>value B</node>
<node>value C</node>
</someNode>
What I'm shooting for is:
<someNode>
<node>value A</node>
<node>value B</node>
<node>value C</node>
<node>value 1</node>
<node>value 2</node>
<node>value 3</node>
</someNode>
EDIT: I found a temporary solution (see below)... still interested in something better, though.
<someNode>
<node xmu:key="id" id="1">value A</node>
<node xmu:k开发者_StackOverflowey="id" id="2">value B</node>
<node xmu:key="id" id="3">value C</node>
</someNode>
The answer is to apply a unique attribute to the element and use that as the xmu:key (see EDIT above).
Get community tasks code. Replace:
if (keyAttribute == null)
{
xpath = nodeToFind.Name;
}
With:
if (keyAttribute == null)
{
xpath = nodeToFind.Name;
if (nodeToFind.ChildNodes.Count == 1 && nodeToFind.FirstChild.NodeType == XmlNodeType.Text)
{
xpath = string.Format("{0}[{1}='{2}']/{1}", parentNode.LocalName, nodeToFind.LocalName,
nodeToFind.InnerText, nodeToFind.LocalName);
parentNode = parentNode.ParentNode;
}
}
In method :
private XmlNode locateTargetNode(XmlNode parentNode, XmlNode nodeToFind, XmlAttribute keyAttribute)
Rebuild. You're done :)
精彩评论