I want to replace a value of an element and attribute of any XML. I have a list of replaceable elements and attributes. What is the most efficient and fastest way to do this? Using regex, .*
is very expensive in performance and memory usage. Is there any way to minimize the usage of this in this requirement? So far, I have this.
For example, I have XMLs that contains the following (this sample is for explanation purposes only)
(1)
<Book>
<author>Uncommon Passion</author>
<title>Anne Calhoun</title>
</Book>
(2)
<Book author="Anne Calhoun">Uncommon Passion</Book>
(3)
<Article author="James Clear">Habit</Article>
Then I want to replace the value of the author element from xml 1 and at the same time the value of author attribute of xml 2 and 3. The incoming XMLs might have totally different tree-structure.