Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8785109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:16:10+00:00 2026-06-13T21:16:10+00:00

I have a string, it looks like an XML file but actually it is

  • 0

I have a string, it looks like an XML file but actually it is just a normal string saved in a variable.

The string is like this:

<m:properties>
             <d:user_id m:type="Edm.Int64">37</d:user_id>
             <d:organization_id m:type="Edm.Int64">1</d:organization_id>
             <d:name>Test</d:name>
             <d:password>81dc9bdb52d04dc20036dbd8313ed055</d:password>
             <d:email_id>test1@cs.com</d:email_id>
             <d:user_type_id m:type="Edm.Int32">3</d:user_type_id>
             <d:is_valid m:type="Edm.Boolean">true</d:is_valid>
             <d:registration_date m:type="Edm.DateTime">2012-10-25T11:20:08</d:registration_date>
           </m:properties>

I need to extract text within :

  1. <d:password> </d:password>
  2. <d:email_id></d:email_id>

The content of <d:password> </d:password> and <d:email_id></d:email_id> is dynamic.

How to use javascript String handling functions to extract the required texts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:16:11+00:00Added an answer on June 13, 2026 at 9:16 pm

    IF this string is regular (i.e. it’s structure never changes), then you could use a regex but, it’s awfully close to HTML/XML which are irregular and regex and irregular don’t go together. They don’t go together so much that if I even suggest a regex, I’ll lose all my rep in the downvote storm which would follow. So…

    IF this string is regular, then this is a possible solution for quick and clean:

    String name = text.split(">")[6].split("<")[0];
    String password = text.split(">")[8].split("<")[0];
    

    Here, the magic numbers 6 and 8 are the indices of the tags in your input string. With a little further work, you could lose the magic numbers altogether but if the structure is fixed, constants might work OK for them.

    Or, losing the magic numbers, and perhaps cleaner (although using magic numbers for the length of ‘name>’ and ‘password>’).

    String name = text.substring(text.indexof("name>")+5).split("<")[0];
    String password = text.substring(text.indexof("password>")+9).split("<")[0];
    

    Both of these will work for any length of user name and password.

    PS. Of course, the first rule of programming is that there is no such thing as a structure that comes from outside your code which will never change 😉

    PPS. When I say ‘any length’, that is of course subject to the limits of Java and the Dalvik VM 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic xml file that looks like this. <root> <item> <title><p>some title</p></title>
I have a xml file that looks like this <a> <bb> <c date=20110706 time=1:20
I have an xml file that looks like this: <args> <sometag value=abc /> <anothertag
Ok, so I have an XML file that pretty much looks like this: <Templates>
I have a String that looks like this String = Förpackning Flaska (375 ml)
I have a string that looks like this: <name>-<gender>-<age>.jpg I want to be very
I have a string that looks like this: 9/1/2009. I want to convert it
i have a string that looks like this: sodjfoisdfsdf sdofij sodiosifosf fsdi a123 sdfoi
I have a string which looks like this a 3e,6s,1d,3g,22r,7c 3g,5r,9c 19.3 , how
Problem: I have a string that looks like this: [1=>2,3,4][5=>6,7,8][9=>10,11,12][13=>14,15][16=>17,18] Question: How can you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.