I am looking for a way, how to replace attribute value in XML node, where the issue with an attribute is, that its name is generated dynamically.
As an example, I can have two different XML files containing something like this
fileA.xaml
<root xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
xmlns:p="clr-namespace:FullAssemblyIdentifier.Wrong_Namespace;assembly=AssemblyName">
</root>
fileB.xaml
<root xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
xmlns:p2="clr-namespace:FullAssemblyIdentifier.Wrong_Namespace;assembly=AssemblyName">
</root>
As you can see, there is actually a difference in name. xmlns:p
vs xmlns:p2
. The thing is, that it can be called anyhow. It can even be xmlns:ABC
. What I am trying to do is to create some kind of ReferenceChanger class, that will fix the reference in all XAML files at once. So far I was thinking about something like this:
ReferenceChanger.cs
public void ChangeReference(XmlNode xmlDoc)
{
const string newReference = "FullAssemblyIdentifier.CorrectReference";
// this does not select the element
var element = (XmlElement)xmlDoc.SelectSingleNode("//root[contains(.,'FullAssemblyIdentifier.Wrong_Namespace')]");
// How do i get the name of the attribute ???
string dynamicallyGeneratedAttributeName = element.GetDynamicallyGeneratedAttributeIdentifier();
if (element != null)
{
// this I can not use, because I do not know the attribute name
element.SetAttribute(dynamicallyGeneratedAttributeName, newReference);
}
}
One thing, that is certain is, that this wrong value is (and always will be) only in root element and not in any other element.