Hi have the following xml:
<?xml version="1.0" encoding="UTF-8"?>
<library>
<item>
<books>
<?xml version="1.0" encoding="UTF-8"?>
<Fiction>
<tt:Author>A</tt:Author>
<tt:BookName>45</tt:BookName>
</Fiction>
</books>
</item>
</library>
I want to basically replace the second occurence of the entire xml tag with blank space. So basically replace <?xml version="1.0" encoding="UTF-8"?>
string which appears after the <books>
opening tag with a space.
Any suggestions? I tried other links but could not get a working solution. The problem is there are ", ? and >
in between the xml tag and the string replace function is considering that as an escape sequence character.
This is what I tried:
var stringToReplace = '<?xml version="1.0" encoding="UTF-8"?>';
var string = data.string;
//console.log(string);
var t=0;
var text = string.replace(/stringToReplace/g, function (match) {
t++;
return (t === 2) ? "Not found" : match;
});
console.log(text);
The above still prints both the xml tags