I have lots of visual studio c++ project files I would like to be able to Switch Address Sanitizer on and off for and its really slow doing it all by hand. I’m trying to write a go program that loops through all the xml elements in the vcxproj until its find the below section and then inserts like below. <EnableASAN>true</EnableASAN>
This is the code I have so far to find the right PropertyGroup but now I have no idea how to insert an xml element here. Can anyone point me in the right right direction how to do this if its possible.
@YamilBrecho The issue I have is the EnableASAN element doesn’t exist in the xml when switched off so cant just text replace it. My plan for removing the element to switch this off was basically what you have done though so thanks for that.
To insert an XML element in a specific location, you can use the following steps:
Parse the XML document into an object model, such as an XmlDocument or an XmlElement in .NET, or an ElementTree in Python.
Navigate to the parent node of the desired location using the object model’s navigation methods, such as SelectSingleNode , GetElementsByTagName , or find in Python.
Create a new element using the object model’s element creation method, such as CreateElement , Element , or SubElement in Python.
Set the attributes and text content of the new element as needed.
Insert the new element into the parent node using the object model’s insertion method, such as AppendChild , append , or insert in Python.
Save the XML document to a file or string if necessary.