I have a scenario where I have to remove the numbers from the name of the xml tag. For example, if there is a tag <xxx1>1234</xxx1>, I need an output as <xxx>1234</xxx>. I surfed through the net and was not able to find a solution. Please help.
3 Answers
You could take a dom elements children and append to a new dom element in its place rather than changing the element details itself.
Pseudo code:
curElementContent = get element from dom and get its contents
newElement = create new dom element
append curElementContent to newElement
remove curElement from dom and insert newElement.
Comments
You could give this a try:
tags.replace(/<xxxx\d>/gi, '<xxxx>').replace(/<\/xxxx\d>/gi,'</xxxx>');
Where tags contains the string you need to update.
2 Comments
CARTIC
Hi..Thanks for the response. Could you please explain if tags in tags.replace is predefined. Also, can this be used for a complete xml. I will have to loop through the tag name (the xxx value).
CARTIC
Got it working by converting the xml into an xml string and using the below regex. xmlString = xmlString.replace(/\d+>/g, '>'); Thanks for your support.