Home » Javascript » Regular expression to replace XML tags with HTML tags using Angular 2

Regular expression to replace XML tags with HTML tags using Angular 2

Posted by: admin July 18, 2018 Leave a comment

Questions:

My XML string:

<command>ADD</command><requestType>VNM_ADD_SUBSCRIPTION</requestType>

Expected XML String:

<span class="key">&lt;command&gt;</span><span class="string">ADD</span><span class="key">&lt;&#47command&gt;</span><span class="key">&lt;requestType&gt;</span><span class="string">VNM_ADD_SUBSCRIPTION</span><span class="key">&lt;&#47requestType&gt;</span>

enter image description here

I am doing this to display the XML in the browser with style like below image. I have written the CSS class key, string for coloring the text.

enter image description here

To achieve this I need a regular expression to replace the XML tags without mentioning the node name in a generic way.

Can someone help me to achieve this? please…

Thanks in advance.

Answers: