Solved

Using regular expression to extract XML from an email message

Posted on 2010-08-19
5
637 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 9

Expert Comment

by:jeremycrussell
ID: 33480711
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 75

Expert Comment

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

Open in new window

0
 
LVL 13

Expert Comment

by:Superdave
ID: 33482112
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 75

Expert Comment

by:käµfm³d 👽
ID: 33482143
>>  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
ID: 33483220
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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
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…

630 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