Example - xml creator

XML output retrieves today's national, regional and global weather from homepage of uk.weather.com. Output is refreshing each 15 minutes from cron.

 

 

Output:

<?xml version="1.0" encoding="UTF-8"?>
<wordpress>
  <data title="WordPress Themes">
    <theme>
      <name>Dara</name>
      <description>With bold featured images and bright, cheerful colors, Dara is ready to get to work for your business.</description>
      <demo_url>https://darademo.wordpress.com/</demo_url>
    </theme>
    <theme>
      <name>Spatial</name>
      <description>A theme for blogs and portfolios with a minimalist touch</description>
      <demo_url>https://spatialdemo.wordpress.com/</demo_url>
    </theme>
    <theme>
      <name>Aperitive</name>
      <description>A delicious, crispy, tender theme for a restaurant website, solo chef, or all-around food lover</description>
      <demo_url>https://aperitivedemo.wordpress.com/</demo_url>
    </theme>
    <theme>
      <name>Libre 2</name>
      <description>A stylish, classic look for your personal blog or long-form writing site. The main navigation bar stays fixed to the top while your visitors read, keeping your most important content at hand, while three footer widget areas give your secondary content a comfortable home.</description>
      <demo_url>https://libre2demo.wordpress.com/</demo_url>
    </theme>
    <theme>
      <name>Wanderer</name>
      <description>A blogging theme.</description>
      <demo_url>https://wandererdemo.wordpress.com/</demo_url>
    </theme>
    <theme>
      <name>Baskerville 2</name>
      <description>Baskerville 2 is a dynamic, grid-based theme for curators. It&amp;amp;#8217;s the perfect way to showcase your posts, videos, images and galleries, and share your favorite quotes and links.</description>
      <demo_url>https://baskerville2demo.wordpress.com/</demo_url>
    </theme>
    <theme>
      <name>Maxwell</name>
      <description>Maxwell is a modern blog theme with an ultra clean and elegant design. With its beautiful typography and thoughtful white space, Maxwell truly helps you to stand out with your content.</description>
      <demo_url>https://maxwelldemo.wordpress.com/</demo_url>
    </theme>
    <theme>
      <name>Ixion</name>
      <description>A theme for non-profits, organizations, and schools.</description>
      <demo_url>https://ixiondemo.wordpress.com/</demo_url>
    </theme>
    <theme>
      <name>Lenscap</name>
      <description>Lenscap makes it super easy to create a stunning WordPress-powered magazine and online store with slick content discovery features, gallery and video post styles, smart customization options and WooCommerce support.</description>
      <demo_url>https://lenscapdemo.wordpress.com/</demo_url>
    </theme>
    <theme>
      <name>Label</name>
      <description>Label is a stylistic theme created specially for art and fashion bloggers. With a distinctive masonry powered layout, a fullscreen post slider, and a classy vertical header &amp;amp;#8211; it&amp;amp;#8217;s sure to make your website stand out.</description>
      <demo_url>https://labeldemo.wordpress.com/</demo_url>
    </theme>
    <theme>
      <name>Twenty Sixteen</name>
      <description>Twenty Sixteen is a modernized take on an ever-popular WordPress layout — the horizontal masthead with an optional right sidebar that works perfectly for blogs and websites. It has custom color options with beautiful default color schemes, a harmonious fluid grid using a mobile-first approach, and impeccable polish in every detail. Twenty Sixteen will make your WordPress look beautiful everywhere.</description>
      <demo_url>https://twentysixteendemo.wordpress.com/</demo_url>
    </theme>
    <theme>
      <name>Eris</name>
      <description>Eris is a crisp and elegant portfolio theme. You can use showcase all your different projects as a unified and beautiful story.</description>
      <demo_url>https://erisdemo.wordpress.com/</demo_url>
    </theme>
    <theme>
      <name>Espresso</name>
      <description>A sophisticated, responsive portfolio theme designed by Justin Caroll, perfect for showcasing your work. With a convenient slide-out sidebar, bold featured images, and quick access to your favorite social networks, Espresso will make your portfolio stand out from the rest.</description>
      <demo_url>https://espressodemo.wordpress.com/</demo_url>
    </theme>
    <theme>
      <name>Karuna</name>
      <description>Karuna is a clean business theme designed with health and wellness-focused sites in mind. With bright, bold colors, prominent featured images, and support for customer testimonials, your business&amp;amp;#8217; brand will shine with Karuna.</description>
      <demo_url>https://karunademo.wordpress.com/</demo_url>
    </theme>
    <theme>
      <name>Pena</name>
      <description>This theme has been inspired by &amp;amp;#8220;Living on One Dollar&amp;amp;#8221; documentary we watched one night. We were deeply touched and wanted to somehow contribute to the whole project. As theme developers we decided to develop a WordPress theme to help spread the word about it. Pena is modern, responsive and mobile friendly theme.</description>
      <demo_url>https://penademo.wordpress.com/</demo_url>
    </theme>
    <theme>
      <name>Shoreditch</name>
      <description>Shoreditch is a functional and responsive theme perfect for your business’s online presence. Although its main purpose is business, Shoreditch looks great as a personal blog theme too.</description>
      <demo_url>https://shoreditchdemo.wordpress.com/</demo_url>
    </theme>
    <theme>
      <name>Affinity</name>
      <description>Affinity is a classic one-page theme designed with weddings and family announcements in mind.</description>
      <demo_url>https://affinitydemo.wordpress.com/</demo_url>
    </theme>
    <theme>
      <name>Carbon</name>
      <description>A WordPress theme with Versatile Layout</description>
      <demo_url>https://carbonthemedemo.wordpress.com/</demo_url>
    </theme>
    <theme>
      <name>Edin</name>
      <description>Edin is a modern responsive business and corporate theme that helps you to create a strong&amp;amp;#8211;yet beautiful&amp;amp;#8211;online presence for your business.</description>
      <demo_url>https://edindemo.wordpress.com/</demo_url>
    </theme>
    <theme>
      <name>Sapor</name>
      <description>Sapor is a two column blogging theme with a lot of possibilities</description>
      <demo_url>https://sapordemo.wordpress.com/</demo_url>
    </theme>
  </data>
</wordpress>

Source code of script:

# File: xmlcreator_main.w
# Name: XML Creator for data about Wordpress Themes
# Description: Script extracts basic information about the most popular Wordpress Themes and saves extracted data into XML file.
# Input: URL
# Output format: XML
# Output fields: Theme name, description, demo URL

#<Logger File>
#	Global
#	FileName xmlcreator_log.log
#	Level debug
#</Logger>

<Section>
	Name xmlcreator_main
			
	Define $output_file xmlcreator_output.xml

	
	
	#delete old output CSV file
	<Action Exec>
		cmd rm -f *.xml
	</Action>
	
	
	
    # load content    
    <Action ContentURL>
        URL https://wordpress.com/themes/
        RemoveNewLine
    </Action>
	
	# inicializing of XML structure
	<Action Php>
		Code $context->setVariable('$dom', createXML());
	</Action>

	<Pattern>
		RegExp <h2>{$title_tag}</h2>
		Compact
		Trim
	</Pattern>

	# add title to structure
	<Action Php>
		Code $context->setVariable('$dom', addTitleToXML($context->getVariable('$dom'),$context));
	</Action>

	<Section While>
		Optional
		# Finish extraction at the end of themes' list
		EndAt <nav id="nav-below"
		
		<Pattern>
			RegExp <header class="entry-header">
		</Pattern>
		
		# Restrict  processed content to current theme information, so we will not skip to another one
		<Section>
			EndAt </header>
			
			<Pattern>
				Optional
				RegExp <h1 class="entry-title"><a class="details" href="{:re([^"]*)}" title="{$description:re([^"]*)}">{$name}</a></h1>
				Compact
				Trim
			</Pattern>
			
			<Pattern>
				Optional
				RegExp <a class="preview" href="{$demo_url:re([^"]*)}" target="_blank">Demo</a>
				Compact
				Trim
			</Pattern>
			
			# add data from this section iteration to structure
			<Action Php>
				Code $context->setVariable('$dom', addThemeToXML($context->getVariable('$dom'),$context));
			</Action>
		</Section>		
	</Section>

	# save whole XML structure to output file
	<Action Php>
		Code saveXML($context->getVariable('$dom'),$context->getVariable('$output_file'));
	</Action>
</Section>	

Main xmlcreator_main