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 8149539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:52:24+00:00 2026-06-06T14:52:24+00:00

I have code to retrieve stomp messages, which works. I then want to grab

  • 0

I have code to retrieve stomp messages, which works. I then want to grab the xml out of the stomp message to do stuff with, which I have code for and it works.

The challenge is to strip out the cruft from the message and get only the xml.

Here is a sample of the stomp message (yes the data is the same, but that’s not relevant here):

MESSAGE
_HQ_ORIG_ADDRESS:jms.queue.edu
timestamp:1339716293764
redelivered:false
_HQ_ORIG_MESSAGE_ID:xxxxxxxx
expires:0
subscription:subscription/jms.queue.edu
priority:4
message-id:xxxxxxxxxx
destination:jms.queue.edu

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><create><sourceMessageId>4454</sourceMessageId><messageId>3038</messageId><course> <batchUid>ASIA.355.921.2012S1.6733</batchUid><title>ASIA355-921-Chinese Cinema</title><startDate>2012-06-18-07:00</startDate><endDate>2012-09- 21-07:00</endDate><mappedNodeBatchUid>9c0bc373-23a0-4e60-b201- efbbc9bb022e</mappedNodeBatchUid><available>false</available></course></create>
MESSAGE
_HQ_ORIG_ADDRESS:jms.queue.edu
timestamp:1339716293764
redelivered:false
_HQ_ORIG_MESSAGE_ID:xxxxxxxx
expires:0
subscription:subscription/jms.queue.edu
priority:4
message-id:xxxxxxxxxx
destination:jms.queue.edu

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><create><sourceMessageId>4454</sourceMessageId><messageId>3038</messageId><course> <batchUid>ASIA.355.921.2012S1.6733</batchUid><title>ASIA355-921-Chinese Cinema</title><startDate>2012-06-18-07:00</startDate><endDate>2012-09- 21-07:00</endDate><mappedNodeBatchUid>9c0bc373-23a0-4e60-b201- efbbc9bb022e</mappedNodeBatchUid><available>false</available></course></create>

What I want to do is remove all the lines in the message starting from “MESSAGE” up to and including the line break before each line that starts with the xml. This will give me the results required to parse using an xml parser:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?><create><sourceMessageId>4454</sourceMessageId><messageId>3038</messageId><course> <batchUid>ASIA.355.921.2012S1.6733</batchUid><title>ASIA355-921-Chinese Cinema</title><startDate>2012-06-18-07:00</startDate><endDate>2012-09- 21-07:00</endDate><mappedNodeBatchUid>9c0bc373-23a0-4e60-b201- efbbc9bb022e</mappedNodeBatchUid><available>false</available></course></create>
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?><create><sourceMessageId>4454</sourceMessageId><messageId>3038</messageId><course> <batchUid>ASIA.355.921.2012S1.6733</batchUid><title>ASIA355-921-Chinese Cinema</title><startDate>2012-06-18-07:00</startDate><endDate>2012-09- 21-07:00</endDate><mappedNodeBatchUid>9c0bc373-23a0-4e60-b201- efbbc9bb022e</mappedNodeBatchUid><available>false</available></course></create>

I tried:

$xmlstr = preg_replace("/MESSAGE(.*)jms.queue.edu$/ims",'',$msg);
$xmlstr = trim($xmlstr);

But that removes everything between the first occurrence of “MESSAGE” on the first line, and the last occurrence of the xml. In other words, all lines between the first “MESSAGE” and the last “xml” are removed.

Any ideas? I’ve tried using a variety of tricks including; regex, implode/explode, writing/reading to a file, etc. But I feel the above preg_replace code works, it just needs to be able to recognize ALL occurrences. I know it will involve either a “while” or “foreach” loop, but I’m looking forward to a nice, clean solution. Any help is most appreciated.

  • 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-06T14:52:25+00:00Added an answer on June 6, 2026 at 2:52 pm

    Use ? after the *.

    Alternatively, try this:

    list(,$body) = explode("\r\n\r\n",$msg); // adjust line ending as needed
    list($xmlstr) = explode("\r\n",$body);
    

    This will get the line that contains all the XML.

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

Sidebar

Related Questions

i have this code, which helps me to retrieve all table fields and associate
I have the following code through which i am able to retrieve phone numbers.
I have the following code, which will retrieve a filename from a table and
I have this code to retrieve Flickr images. However, I just want to retrieve
I have some code to retrieve XML data: import cStringIO import pycurl from xml.etree
I have this code to retrieve data from file then make some treatment, and
I have c# application which include code to retrieve registry values and check it's
I have a grid view and I add columns to it by code: //Retrieve
I have code that generates a List<string[]> variable but can't quite figure out how
I have code which has a drop down list. And when a certain option

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.