Using SPWebConfigModification, Part 4 - Why doesn't this work?
My code would step through this XML, and at each node generate a new SPWebConfigModification. The <location path="_some/path/here"> node, having children, would cause that code to make an EnsureSection type of modification, with a name like “location[@path=\”_some/path/here\”]” and SharePoint will complain about those aforementioned characters. It is a section, is it not (by a definition of having children)? And that section requires a unique XPath described by its attributes. Why, then, can we not add what I think is a properly constructed SPWebConfigModification for that section?
The Microsoft documentation states:
When the type of web.config modification is EnsureChildNode, the Name property refers to an XPath expression that uniquely identifies the node under the parent node, as identified by the Path property. For example, to ensure a child node as a safe control entry, which has two unique attributes (e.g., Assembly and TypeName), the name should match the following XPath expression:
SafeControl[@Assembly=\"Microsoft.Sharepoint\"][@TypeName=\"*\"]
So our Name property looks right to me, but that only works for an EnsureChildNode type.
Let's make some minor changes in Part 5 that should put this all to bed.