Parsing a string in java

I have a string of the form <user>id</user>text<user>id2</user>text1<user>id3</user>
I want to convert this String to <user>name</user>text<user>name2</user>text1<user>name3</user>
Basically each userId has a corresponding name which i need to fetch from DB and replace this id with the name.
How do i do it effeciently in java.

Rohit BajajAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
What about using XML and XSLT?
Pawan KumarDatabase ExpertCommented:
Please try with REGEX.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Your problem has nothing to do with "parsing a string". It's to do with filling a template. You need to replace placeholders (id,id2,id3 etc) with the actual values. Commonly, this is often done with templating software such as Velocity
The same could go for
Rohit BajajAuthor Commented:
There is one reason why templating probably could not apply here... correct me if i am wrong...
In the above string i need to extract the id and then search for a corresponding name in DB and replace it there
So i need to fetch the id , id2 etc. values which will require parsing it..
Oh sorry - i thought it was the other way around ;)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.