0

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 3

1

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.
Sign up to request clarification or add additional context in comments.

Comments

0

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

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).
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.
0

Got it working by converting the xml into an xml string and using the below regex.

xmlString = xmlString.replace(/\d+>/g, '>');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.