Link to home
Start Free TrialLog in
Avatar of GodsHand
GodsHandFlag for Canada

asked on

Using regular expression to extract XML from an email message

I'm sending a plain-text email to a Sharepoint list that contains XML in the body. I'm fairly new with regular expressions, so I can't figure out how to do this:

When Sharepoint gets the email, it outputs it with the email headers included. So it's kinda like:

from: <blah@blah.com>
subject: Testing
x-date-msg: blah blah
some-other-random-stuff: blah blahb lbah

<?xml version="1.0" encoding="utf-8" ?>
<FieldTypes>
	<FieldType>
		<Field Name="ID">New</Field>
		<Field Name="Date">9/12/2010</Field>
		<Field Name="PubAndRun">ROP</Field>
	</FieldType>
</FieldTypes>

Open in new window


Could someone point me in the right direction of how I'd use a regular expression to extract just the body portion from this text?
Avatar of jeremycrussell
jeremycrussell
Flag of United States of America image

What OS/Tools would you be using to parse this?  essentially, you might use regex to catch the header data and rip it out, instead of trying to rip out the body.  The tools you plan to use will make a difference.
Avatar of kaufmed
It should be as simple as:
<FieldTypes>.+?</FieldTypes>

Open in new window

You will of course need to use the s flag, or preface the expression with (?s), for the above solution, so the . matches linefeeds.
>>  You will of course need to use the s flag, or preface the expression with (?s), ....

Unless of course the data is received with no newlines (i.e. one-line string); otherwise I agree :)
ASKER CERTIFIED SOLUTION
Avatar of SyfAldeen
SyfAldeen
Flag of Egypt image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial