Solved

Using regular expression to extract XML from an email message

Posted on 2010-08-19
5
628 Views
Last Modified: 2013-11-11
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?
0
Comment
Question by:GodsHand
5 Comments
 
LVL 9

Expert Comment

by:jeremycrussell
Comment Utility
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.
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
It should be as simple as:
<FieldTypes>.+?</FieldTypes>

Open in new window

0
 
LVL 13

Expert Comment

by:Superdave
Comment Utility
You will of course need to use the s flag, or preface the expression with (?s), for the above solution, so the . matches linefeeds.
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
>>  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 :)
0
 
LVL 4

Accepted Solution

by:
SyfAldeen earned 500 total points
Comment Utility
This should do the trick!
It's better not to rely on the XML contents like "<FieldTypes>"

<\?xml[^>]+?\?>.*

Open in new window

RegEx.png
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now