 




<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Irregular Expressions &#187; parse xml perl</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/Irregular-Expressions/tag/parse-xml-perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/Irregular-Expressions</link>
	<description>Insight into current security related events and exploits, including virtualization security and tips.</description>
	<lastBuildDate>Sun, 28 Apr 2013 08:00:32 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Parsing XML with regular expressions &#8211; Part 1</title>
		<link>http://itknowledgeexchange.techtarget.com/Irregular-Expressions/parsing-xml-with-regular-expressions-part-1/</link>
		<comments>http://itknowledgeexchange.techtarget.com/Irregular-Expressions/parsing-xml-with-regular-expressions-part-1/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 01:37:42 +0000</pubDate>
		<dc:creator>Dan O'Connor</dc:creator>
				<category><![CDATA[parse xml perl]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[perl xml]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/Irregular-Expressions/?p=168</guid>
		<description><![CDATA[Many applications now have the ability to produce XML reports, while perl does have modules available to parse this information I find regular expressions are faster on extremely large data sets. A small example. &#60;date&#62; &#60;start&#62;Thu Mar 4 23:27:03 2010&#60;/start&#62; &#60;end&#62;Thu Mar 4 23:58:37 2010&#60;/end&#62; &#60;/date&#62; Get the XML you need to parse into an [...]]]></description>
				<content:encoded><![CDATA[<p>Many applications now have the ability to produce XML reports, while perl does have modules available to parse this information I find regular expressions are faster on extremely large data sets.</p>
<p>A small example.</p>
<pre>&lt;date&gt;
	&lt;start&gt;Thu Mar  4 23:27:03 2010&lt;/start&gt;
	&lt;end&gt;Thu Mar  4 23:58:37 2010&lt;/end&gt;
&lt;/date&gt;</pre>
<p>Get the XML you need to parse into an array, you can use perl&#8217;s open or a shell command to do so.</p>
<pre>$target = "/path/to/what/you/want.xml";
open(FH, $target) || die("Could not open file!");
@file=&lt;FH&gt;;</pre>
<p>OR</p>
<pre>@file = `cat /path/to/what/you/want.xml`;</pre>
<p>Now you just need to step through the array, you can use a foreach loop for this.</p>
<pre>foreach(@file) {</pre>
<pre>}</pre>
<p>Now going through the file you can use the &#8216;&#8230;&#8217; regex to match between two markers and then get down to what you are looking for.</p>
<pre>foreach(@file) {

	if(/&lt;date&gt;/ ... /&lt;\/date&gt;/) {
		if(/&lt;start&gt;(.+)&lt;\/start&gt;/) {
			$report_start = $1;
		}
		if(/&lt;end&gt;(.+)&lt;\/end&gt;/) {
			$report_end = $1;
		}
	}
}</pre>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/Irregular-Expressions/parsing-xml-with-regular-expressions-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
