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>Penscratch 2</name>
      <description>A clean, responsive writing theme with support for custom logos, featured images, fancy pull quotes, and more.</description>
      <demo_url>https://penscratch2demo.wordpress.com/</demo_url>
    </theme>
    <theme>
      <name>Heart And Style</name>
      <description>Heart And Style is a clean and well coded theme with a design primarily for feminine blogs but not limited to it.</description>
      <demo_url>https://heartandstyledemo.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>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>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>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>Button 2</name>
      <description>A stylish, lighthearted theme for crafters, hobbyists, and creatives.</description>
      <demo_url>https://button2demo.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>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>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>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>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>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>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>Veeva</name>
      <description>A colorful theme for personal bloggers</description>
      <demo_url>https://veevademo.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>Entrepreneur</name>
      <description>Entrepreneur was built for small businesses and startups, and its ease-of-setup and crisp, modern look is one you will love. A stunning home page displays large, fully-responsive featured images to brilliantly introduce you and your business, and multiple custom navigation menus and razor-sharp whitespace and typography make information discovery on your website a pleasure. Clean, professional, and minimalist; this and more makes Entrepreneur the right choice for your online business profile.</description>
      <demo_url>https://entrepreneurdemo.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>
    <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>Ixion</name>
      <description>A theme for non-profits, organizations, and schools.</description>
      <demo_url>https://ixiondemo.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