I have an XML and it contains a tag which has a value I want to replace in nodeJS. The XML contains comments and attributes to the tags. Most parsers convert the XML to JSON and do the replace in the process of which, the comments get lost in the final file. So I thought of doing a XML to string conversion and replace and then back to XML. I am unable to convert the string back to XML as many existing libraries in node either are converting to JSON, are unable to to parse attributes with ':' in it. So any Solution for the same is appreciated.
N.B - the XML needs to be exactly the same as earlier in exception to only the one tag value I replace. The order of the tags and the comments are important as there is a checksum calculation involved.
Sample Input :
<?xml version="1.0" encoding="UTF-8"?>
<session abc:def ="dines/dwivedi.../nodeJS/developer" name="Dinesh_Dwivedi"
samp1:display="sample/text1"
samp2:display="sample/text2"
samp3:display="sample/text3">
<view name="viewer/name1" type="good.sample.data1">
<feature ="text1" value="1:1"/>
<!--This is a sample comment-->
</view>
<view name="viewer/name2" type="good.sample.data2">
<feature ="text2" value="1:2"/>
<!--This is a sample comment too-->
</view>
<!--again another Sample comment-->
</session>
Text to change - Dinesh_Dwivedi
Replace Text - Dines_Dwivedi
Final Output -
<?xml version="1.0" encoding="UTF-8"?>
<session abc:def ="dines/dwivedi.../nodeJS/developer" name="Dines_Dwivedi"
samp1:display="sample/text1"
samp2:display="sample/text2"
samp3:display="sample/text3">
<view name="viewer/name1" type="good.sample.data1">
<feature ="text1" value="1:1"/>
<!--This is a sample comment-->
</view>
<view name="viewer/name2" type="good.sample.data2">
<feature ="text2" value="1:2"/>
<!--This is a sample comment too-->
</view>
<!--again another Sample comment-->
</session>