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

  • Home
  • SEARCH
  • 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 6625667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:48:05+00:00 2026-05-25T21:48:05+00:00

For example, from the following string <?xml version=1.0?><root><point><message>hello world 1</message></point><point><data><message>hello world 2</message></data></point></root> if I

  • 0

For example, from the following string

<?xml version="1.0"?><root><point><message>hello world 1</message></point><point><data><message>hello world 2</message></data></point></root>

if I want to extract message, the result should be

hello world 1
hello world 2

Is there an easy way to do this?

All I can think of is to first find out the position of and and then generate substrings in a loop. Is there a better way?

  • 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-05-25T21:48:06+00:00Added an answer on May 25, 2026 at 9:48 pm

    Your data is not XML, so I guess you’ll have to use a regular expression for that:

    perl -n -E'say $1 while m{<message>(.*?)</message>}g' your_file_here.xml 
    

    If your file was proper XML, then XML::Twig would work nicely. You could even use the xml_grep tool that comes with it to do just what you want.

    update: with valid XML you can then do

    xml_grep --text_only message mes.xml 
    

    or

    xml_grep2 --text_only '//message' mes.xml # xml_grep2 is in App::xml_grep2
    

    or

    perl -MXML::Twig -E'XML::Twig->new( twig_handlers => 
                                          { message => sub { say $_->text; }, })
                                 ->parsefile( "mes.xml")'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using simplexml_load_string() how do I get ForgotPassword from the following XML? <?xml version=1.0 encoding=utf-8?>
I have a query that strips data from a XML string, inserts it into
I am reading data from another system that returns XML that provides the following
Can someone please derive a concrete example from the following: http://www.urdalen.com/blog/?p=210 ..that shows how
I'm following the racetrack example from Jason Rudolph's book at InfoQ , using grails-1.2.1.
I'm getting the following from a third party library (one example): @%SystemRoot%\SomePath\SomeFile.Dll,-203 I know
I'm trying to compile the following simple DL library example code from Program-Library-HOWTO with
Can anybody help me with retrieving some elements from the following example text: sdfaasdflj
I need a regex that will give me the following results from each example
I have the following example of reading from a buffered reader: while ((inputLine =

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.