<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: xml code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Mon, 12 May 2008 03:50:54 GMT</pubDate>
    <description>DZone Snippets: xml code</description>
    <item>
      <title>Adding helpful error messages to your Ruby code</title>
      <link>http://snippets.dzone.com/posts/show/5446</link>
      <description>This Ruby code raises an error if the XPath query fails because the attribute being queried did not exist for the given element. &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;  def map_pattr(node, fieldx, valuex)&lt;br /&gt;    begin&lt;br /&gt;    parameter = node.root.elements["parameter[@field='#{fieldx}']"]&lt;br /&gt;    parameter.add_attribute('value', valuex)&lt;br /&gt;    parameter&lt;br /&gt;    &lt;br /&gt;    rescue&lt;br /&gt;      puts 'feedpopulated.rb: map_attr() the field ' + fieldx + ' was not found in params.'&lt;br /&gt;      raise&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Notice that a raise statement is used to ensure that the system error message is raised and any further code execution is halted.&lt;br /&gt;&lt;br /&gt;Without adding a customized helpful message I would be left scratching my head trying to work out what the following system error message meant.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;./feedpopulated.rb:27:in `map_pattr': undefined method `add_attribute' for nil:NilClass (NoMethodError)&lt;br /&gt;     from ./feedpopulated.rb:51:in `create_record'&lt;br /&gt;     from ./feedpopulated.rb:49:in `each'&lt;br /&gt;     from ./feedpopulated.rb:49:in `create_record'&lt;br /&gt;     from ./recordx.rb:91:in `call_create'&lt;br /&gt;     from ./s3fileuploader_handler.rb:14:in `call'&lt;br /&gt;     from ./s3fileuploader_handler.rb:40:in `invoke'&lt;br /&gt;     from ./uploadtwitteraudio.rb:22:in `initialize'&lt;br /&gt;     from /usr/lib/ruby/1.8/rexml/element.rb:890:in `each'&lt;br /&gt;     from /usr/lib/ruby/1.8/rexml/xpath.rb:53:in `each'&lt;br /&gt;     from /usr/lib/ruby/1.8/rexml/element.rb:890:in `each'&lt;br /&gt;     from ./uploadtwitteraudio.rb:18:in `initialize'&lt;br /&gt;     from ./uploadtwitteraudio.rb:72:in `new'&lt;br /&gt;     from ./uploadtwitteraudio.rb:72&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Reference: &lt;a href="http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_exceptions.html"&gt;Programming Ruby: The Pragmatic Programmer's Guide - Exceptions, Catch, and Throw&lt;/a&gt; [ruby-doc.org]</description>
      <pubDate>Wed, 30 Apr 2008 11:40:47 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5446</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Helpful XPath examples</title>
      <link>http://snippets.dzone.com/posts/show/5443</link>
      <description>A few XPath examples copied from &lt;a href="http://www.w3schools.com/XPath/xpath_syntax.asp"&gt;XPath Syntax&lt;/a&gt; [w3schools.com]&lt;br /&gt;&lt;br /&gt;Predicates&lt;br /&gt;&lt;code&gt;&lt;br /&gt;/bookstore/book[1] 	# Selects the first book element that is the child of the bookstore element. &lt;br /&gt;                        # Note: IE5 and later has implemented that [0] should be the first node, &lt;br /&gt;                        # but according to the W3C standard it should have been [1]!!&lt;br /&gt;/bookstore/book[last()] 	# Selects the last book element that is the child of the bookstore element&lt;br /&gt;/bookstore/book[last()-1] 	# Selects the last but one book element that is the child of the bookstore element&lt;br /&gt;/bookstore/book[position()&lt;3] 	# Selects the first two book elements that are children of the bookstore element&lt;br /&gt;//title[@lang] 	# Selects all the title elements that have an attribute named lang&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Selecting Unknown Nodes&lt;br /&gt;&lt;code&gt;&lt;br /&gt;/bookstore/* 	# Selects all the child nodes of the bookstore element&lt;br /&gt;//* 	# Selects all elements in the document&lt;br /&gt;//title[@*] 	# Selects all title elements which have any attribute&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Selecting Several Paths&lt;br /&gt;&lt;code&gt;&lt;br /&gt;//book/title | //book/price  	# Selects all the title AND price elements of all book elements&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 29 Apr 2008 23:34:28 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5443</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Using ruby to upload multiple files to Amazon S3</title>
      <link>http://snippets.dzone.com/posts/show/5431</link>
      <description>This ruby code builds upon the code &lt;a href="http://snippets.dzone.com/posts/show/3062"&gt;S3 upload client for Ruby&lt;/a&gt; [dzone.com] by reading the account details and file details from XML files.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/env ruby&lt;br /&gt;#file : rubys3file2upload.rb&lt;br /&gt;&lt;br /&gt;require 'rubygems'&lt;br /&gt;require 'aws/s3'&lt;br /&gt;require 'rexml/document'&lt;br /&gt;include REXML&lt;br /&gt;&lt;br /&gt;class S3FileUpload&lt;br /&gt;&lt;br /&gt;  def initialize(xml_accounts_file, xml_upload_file)&lt;br /&gt;    initialize_account(xml_accounts_file)&lt;br /&gt;    main(xml_upload_file)&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  def initialize_account(accounts_file)&lt;br /&gt;&lt;br /&gt;    file = File.new(accounts_file)&lt;br /&gt;    doc = Document.new(file)&lt;br /&gt;&lt;br /&gt;    account = doc.root.elements['records/access']&lt;br /&gt;    h = Hash.new&lt;br /&gt;    h[:access_key_id] = account.elements['key_id'].text.to_s&lt;br /&gt;    h[:secret_access_key] = account.elements['secret'].text.to_s&lt;br /&gt;    AWS::S3::Base.establish_connection!(h)&lt;br /&gt;&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  def main(xml_upload_file)&lt;br /&gt;    file = File.new(xml_upload_file)&lt;br /&gt;    doc = Document.new(file)&lt;br /&gt;puts doc&lt;br /&gt;    doc.root.elements.each('records/file') do |f|&lt;br /&gt;      local_file = f.elements['local'].text.to_s&lt;br /&gt;      bucket = f.elements['bucket'].text.to_s&lt;br /&gt;      mime_type = f.elements['mime_type'].text.to_s&lt;br /&gt;      upload(local_file, mime_type, bucket)&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  def upload(local_file, mime_type, bucket)&lt;br /&gt;&lt;br /&gt;    base_name = File.basename(local_file)&lt;br /&gt;&lt;br /&gt;    puts "Uploading #{local_file} as '#{base_name}' to '#{bucket}'"&lt;br /&gt;&lt;br /&gt;    AWS::S3::S3Object.store(&lt;br /&gt;      base_name,&lt;br /&gt;      File.open(local_file),&lt;br /&gt;      bucket,&lt;br /&gt;      :content_type =&gt; mime_type,&lt;br /&gt;      :access =&gt; :public_read&lt;br /&gt;    )&lt;br /&gt;&lt;br /&gt;    puts "Uploaded!"&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;if __FILE__ == $0&lt;br /&gt;  s3fu = S3FileUpload.new('s3accounts.xml', 's3files2upload.xml')&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;file: s3accounts.xml&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;s3accounts&gt;&lt;br /&gt;  &lt;summary/&gt;&lt;br /&gt;  &lt;records&gt;&lt;br /&gt;    &lt;access id="100"&gt;&lt;name&gt;REPLACE_ME&lt;/name&gt;&lt;key_id&gt;REPLACE_ME&lt;/key_id&gt;&lt;secret&gt;REPLACE_ME&lt;/secret&gt;&lt;/access&gt;&lt;br /&gt;  &lt;/records&gt;&lt;br /&gt;&lt;/s3accounts&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;file: s3files2upload.xml&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;s3files2upload&gt;&lt;br /&gt;  &lt;summary/&gt;&lt;br /&gt;  &lt;records&gt;&lt;br /&gt;    &lt;file&gt;&lt;br /&gt;      &lt;local&gt;autocomplete.html&lt;/local&gt;&lt;br /&gt;      &lt;bucket&gt;t2000&lt;/bucket&gt;&lt;br /&gt;      &lt;mime_type&gt;text/html&lt;/mime_type&gt;&lt;br /&gt;    &lt;/file&gt;&lt;br /&gt;    &lt;file&gt;&lt;br /&gt;      &lt;local&gt;autocomplete2.html&lt;/local&gt;&lt;br /&gt;      &lt;bucket&gt;t2000&lt;/bucket&gt;&lt;br /&gt;      &lt;mime_type&gt;text/html&lt;/mime_type&gt;&lt;br /&gt;    &lt;/file&gt;&lt;br /&gt;    &lt;file&gt;&lt;br /&gt;      &lt;local&gt;autocomplete3.html&lt;/local&gt;&lt;br /&gt;      &lt;bucket&gt;t2000&lt;/bucket&gt;&lt;br /&gt;      &lt;mime_type&gt;text/html&lt;/mime_type&gt;&lt;br /&gt;    &lt;/file&gt;&lt;br /&gt;  &lt;/records&gt;&lt;br /&gt;&lt;/s3files2upload&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Note: The file given the correct permission could be read from http://t2000.s3.amazonaws.com/autocomplete.html&lt;br /&gt;&lt;br /&gt;Reference: http://amazon.rubyforge.org/</description>
      <pubDate>Sat, 26 Apr 2008 14:17:58 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5431</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Adding style to SVG</title>
      <link>http://snippets.dzone.com/posts/show/5392</link>
      <description>To reference a CSS file within an SVG file refer to the following example code.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?xml-stylesheet href="styles_austria_1.css" type="text/css"?&gt; &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Here's what an SVG CSS file looks like.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;.str1 {stroke:#0093DD;stroke-width:16;color:#0093DD}&lt;br /&gt;.str2 {stroke:#0093DD;stroke-width:12}&lt;br /&gt;.str3 {stroke:#0093DD;stroke-width:10}&lt;br /&gt;.str4 {stroke:#0093DD;stroke-width:6}&lt;br /&gt;&lt;br /&gt;.str0 {stroke:#DA251D;stroke-width:55;color:#DA251D}&lt;br /&gt;.str6 {stroke:#BB90BB;stroke-width:44;color:#BB90BB}&lt;br /&gt;.str5 {stroke:#0093DD;stroke-width:4}&lt;br /&gt;.str7 {stroke:#1F1A17;stroke-width:13}&lt;br /&gt;&lt;br /&gt;.fil0 {fill:none}&lt;br /&gt;.fil2 {fill:#1F1A17}&lt;br /&gt;.fil1 {fill:#C4E5FA}&lt;br /&gt;.fil3 {fill:#FFFFFF}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Source: &lt;a href="http://www.carto.net/papers/svg/samples/styles.shtml"&gt;Example for using CSS-Styles&lt;/a&gt; [carto.net]&lt;br /&gt;Reference: &lt;a href="http://www.w3.org/TR/SVG/styling.html#StylingWithCSS"&gt;Styling - SVG 1.1 - 20030114&lt;/a&gt; [w3.org]</description>
      <pubDate>Fri, 18 Apr 2008 21:37:11 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5392</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Converting text to SVG</title>
      <link>http://snippets.dzone.com/posts/show/5388</link>
      <description>First of all the Ruby code reads the text, splits it into an array and then saves it in XML format.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'rexml/document'&lt;br /&gt;include REXML&lt;br /&gt;&lt;br /&gt;a = "Open source is a development method for software that harnesses the power of distributed peer &lt;br /&gt;review and transparency of process. The promise of open source is better quality, higher reliability, &lt;br /&gt;more flexibility, lower cost, and an end to predatory vendor lock-in.".split(' ') &lt;br /&gt;&lt;br /&gt;doc = Document.new&lt;br /&gt;doc.add_element('text')&lt;br /&gt;oline = Element.new('line')&lt;br /&gt;&lt;br /&gt;char_count = 0&lt;br /&gt;a.each do |word|&lt;br /&gt;  &lt;br /&gt;  oword = Element.new('word')&lt;br /&gt;  oword.text = word.to_s&lt;br /&gt;  oword.add_attribute('length',char_count)&lt;br /&gt;  oline &lt;&lt; oword &lt;br /&gt;  char_count += word.length&lt;br /&gt;  &lt;br /&gt;  if char_count &gt; 50&lt;br /&gt;    doc.root &lt;&lt; oline&lt;br /&gt;    oline = Element.new('line')&lt;br /&gt;    char_count = 0&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;doc.root &lt;&lt; oline&lt;br /&gt;puts char_count&lt;br /&gt;puts doc&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Here's a sample of the XML created&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;text&gt;&lt;br /&gt;  &lt;line&gt;&lt;br /&gt;    &lt;word length='0'&gt;Open&lt;/word&gt;&lt;word length='4'&gt;source&lt;/word&gt;&lt;word length='10'&gt;is&lt;/word&gt;&lt;br /&gt;    &lt;word length='12'&gt;a&lt;/word&gt;&lt;word length='13'&gt;development&lt;/word&gt;&lt;word length='24'&gt;method&lt;/word&gt;&lt;br /&gt;    &lt;word length='30'&gt;for&lt;/word&gt;&lt;word length='33'&gt;software&lt;/word&gt;&lt;word length='41'&gt;that&lt;/word&gt;&lt;br /&gt;    &lt;word length='45'&gt;harnesses&lt;/word&gt;&lt;br /&gt;  &lt;/line&gt;&lt;br /&gt;  &lt;line&gt;&lt;br /&gt;    &lt;word length='0'&gt;the&lt;/word&gt;&lt;word length='3'&gt;power&lt;/word&gt;&lt;br /&gt;    &lt;word length='8'&gt;of&lt;/word&gt;&lt;word length='10'&gt;distributed&lt;/word&gt;&lt;word length='21'&gt;peer&lt;/word&gt;&lt;br /&gt;    &lt;word length='25'&gt;review&lt;/word&gt;&lt;word length='31'&gt;and&lt;/word&gt;&lt;word length='34'&gt;transparency&lt;/word&gt;&lt;br /&gt;    &lt;word length='46'&gt;of&lt;/word&gt;&lt;word length='48'&gt;process.&lt;/word&gt;&lt;br /&gt;  &lt;/line&gt;&lt;br /&gt;  &lt;line&gt;&lt;br /&gt;    &lt;word length='0'&gt;The&lt;/word&gt;&lt;br /&gt;    &lt;word length='3'&gt;promise&lt;/word&gt;&lt;word length='10'&gt;of&lt;/word&gt;&lt;word length='12'&gt;open&lt;/word&gt;&lt;br /&gt;    &lt;word length='16'&gt;source&lt;/word&gt;&lt;word length='22'&gt;is&lt;/word&gt;&lt;word length='24'&gt;better&lt;/word&gt;&lt;br /&gt;    &lt;word length='30'&gt;quality,&lt;/word&gt;&lt;word length='38'&gt;higher&lt;/word&gt;&lt;word length='44'&gt;reliability,&lt;/word&gt;&lt;br /&gt;  &lt;/line&gt;&lt;br /&gt;  &lt;line&gt;&lt;br /&gt;    &lt;word length='0'&gt;more&lt;/word&gt;&lt;word length='4'&gt;flexibility,&lt;/word&gt;&lt;word length='16'&gt;lower&lt;/word&gt;&lt;br /&gt;    &lt;word length='21'&gt;cost,&lt;/word&gt;&lt;word length='26'&gt;and&lt;/word&gt;&lt;word length='29'&gt;an&lt;/word&gt;&lt;br /&gt;    &lt;word length='31'&gt;end&lt;/word&gt;&lt;word length='34'&gt;to&lt;/word&gt;&lt;word length='36'&gt;predatory&lt;/word&gt;&lt;br /&gt;    &lt;word length='45'&gt;vendor&lt;/word&gt;&lt;br /&gt;  &lt;/line&gt;&lt;br /&gt;  &lt;line&gt;&lt;br /&gt;    &lt;word length='0'&gt;lock-in.&lt;/word&gt;&lt;br /&gt;  &lt;/line&gt;&lt;br /&gt;&lt;/text&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;The XML is then transformed to SVG using the following XSL file&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;br /&gt;&lt;br /&gt;&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt;&lt;br /&gt;&lt;br /&gt;&lt;xsl:output encoding="UTF-8"&lt;br /&gt;            method="xml"&lt;br /&gt;            indent="yes"/&gt;&lt;br /&gt;            &lt;br /&gt;  &lt;xsl:template match="text"&gt;&lt;br /&gt;    &lt;svg xmlns="http://www.w3.org/2000/svg" width="100%"&lt;br /&gt;                  xmlns:xlink="http://www.w3.org/1999/xlink" &gt;&lt;br /&gt;      &lt;g id="sketch" class="sketch"&gt;&lt;br /&gt;        &lt;xsl:apply-templates select="line"/&gt;&lt;br /&gt;      &lt;/g&gt;&lt;br /&gt;    &lt;/svg&gt;&lt;br /&gt;  &lt;/xsl:template&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;xsl:template match="line"&gt;&lt;br /&gt;    &lt;xsl:variable name="xfactor"&gt;12&lt;/xsl:variable&gt;&lt;br /&gt;    &lt;xsl:variable name="yfactor"&gt;20&lt;/xsl:variable&gt;&lt;br /&gt;    &lt;xsl:variable name="pos" select="position()"&gt;&lt;/xsl:variable&gt;&lt;br /&gt;    &lt;xsl:apply-templates select="word"&gt;&lt;br /&gt;      &lt;xsl:with-param name="xfactor" select="$xfactor"&gt;&lt;/xsl:with-param&gt;&lt;br /&gt;      &lt;xsl:with-param name="y" select="$pos * $yfactor + 10"&gt;&lt;/xsl:with-param&gt;&lt;br /&gt;    &lt;/xsl:apply-templates&gt;&lt;br /&gt;  &lt;/xsl:template&gt;&lt;br /&gt;&lt;br /&gt;  &lt;xsl:template match="word"&gt;&lt;br /&gt;    &lt;xsl:param name="xfactor"/&gt;&lt;br /&gt;    &lt;xsl:param name="y"/&gt;&lt;br /&gt;    &lt;text xmlns="http://www.w3.org/2000/svg" font-size="12pt" x="{@length * $xfactor +10}" y="{$y}" id="t1"&gt;&lt;xsl:value-of select="."/&gt;&lt;/text&gt;&lt;br /&gt;  &lt;/xsl:template&gt;&lt;br /&gt;&lt;/xsl:stylesheet&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;The final &lt;a href="http://www.twitxr.com/image/31865/"&gt;SVG output&lt;/a&gt; [twitxr.com] shows 5 lines of text with each word as a separate SVG text element.</description>
      <pubDate>Fri, 18 Apr 2008 18:14:11 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5388</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Append an XML element using the append operator</title>
      <link>http://snippets.dzone.com/posts/show/5382</link>
      <description>This Ruby code appends an XML node to an XML document using the append &lt;&lt; operator. &lt;br /&gt;&lt;code&gt;&lt;br /&gt;      doc2 = Document.new(xml_svg)&lt;br /&gt;      obody.text = ''&lt;br /&gt;      obody &lt;&lt; doc2.root&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;In this example the original obody.text contained escaped xml, which was then initialised as an XML document and appended to obody to be processed as pure XML.</description>
      <pubDate>Thu, 17 Apr 2008 23:50:25 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5382</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Using XSLT to generate SVG</title>
      <link>http://snippets.dzone.com/posts/show/5375</link>
      <description>This XSL file is intended to be used as an SVG XSL template file which displays SVG content using Gorg (XSLT back-end processor).&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;br /&gt;&lt;br /&gt;&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt;&lt;br /&gt;&lt;br /&gt;&lt;xsl:output encoding="UTF-8"&lt;br /&gt;            method="xml"&lt;br /&gt;            indent="yes"/&gt;&lt;br /&gt;            &lt;br /&gt;  &lt;xsl:template match="mainpage"&gt;&lt;br /&gt;  &lt;svg xmlns="http://www.w3.org/2000/svg" width="100%"&lt;br /&gt;                xmlns:xlink="http://www.w3.org/1999/xlink" &gt;&lt;br /&gt;&lt;br /&gt;    &lt;g&gt;&lt;br /&gt;    &lt;text font-size="12pt" x="50" y="50" id="t2" stroke="olive"&gt;&lt;xsl:value-of select="title"/&gt;&lt;/text&gt;&lt;br /&gt;    &lt;/g&gt;&lt;br /&gt;&lt;br /&gt;  &lt;/svg&gt;&lt;br /&gt;  &lt;/xsl:template&gt;&lt;br /&gt;&lt;/xsl:stylesheet&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Reference: 'using XSLT to generate SVG' http://snurl.com/24pwo [carto.net] </description>
      <pubDate>Thu, 17 Apr 2008 10:45:36 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5375</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Instruct a shared whiteboard to save and refresh</title>
      <link>http://snippets.dzone.com/posts/show/5284</link>
      <description>The following code used with the ProjectX API informs the client web browser that the whiteboard will be refreshed in 5 seconds. It then archives the current whiteboard information, formats it, and sends a message to each web browser to refresh their view.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;project name="whiteboardqueue"&gt;&lt;br /&gt;  &lt;methods&gt;&lt;br /&gt;    &lt;method name="create"&gt;&lt;br /&gt;      &lt;params&gt;&lt;br /&gt;        &lt;param var="type"&gt;ecmascript&lt;/param&gt;&lt;br /&gt;        &lt;param var="body"&gt;startRefresh(5)&lt;/param&gt;&lt;br /&gt;        &lt;param var="sender"&gt;system&lt;/param&gt;&lt;br /&gt;      &lt;/params&gt;&lt;br /&gt;    &lt;/method&gt;&lt;br /&gt;    &lt;method name="timer"&gt;&lt;br /&gt;      &lt;params&gt;&lt;br /&gt;        &lt;param var="timer"&gt;5&lt;/param&gt;&lt;br /&gt;      &lt;/params&gt;&lt;br /&gt;    &lt;/method&gt;&lt;br /&gt;    &lt;method name="archive_and_format"&gt;&lt;br /&gt;      &lt;params/&gt;&lt;br /&gt;    &lt;/method&gt;&lt;br /&gt;    &lt;method name="create"&gt;&lt;br /&gt;      &lt;params&gt;&lt;br /&gt;        &lt;param var="type"&gt;ecmascript&lt;/param&gt;&lt;br /&gt;        &lt;param var="body"&gt;reloadDocument()&lt;/param&gt;&lt;br /&gt;        &lt;param var="sender"&gt;system&lt;/param&gt;&lt;br /&gt;      &lt;/params&gt;&lt;br /&gt;    &lt;/method&gt;&lt;br /&gt;  &lt;/methods&gt;&lt;br /&gt;&lt;/project&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;*update 1:14am*&lt;br /&gt;The &lt;a href="http://rorbuilder.info/r/whiteboardqueue/index2.svg"&gt;whiteboard demo&lt;/a&gt; [rorbuilder.info] allows the user to draw using the mouse within the web browser which renders SVG. Tested on Flock and Firefox.&lt;br /&gt;&lt;br /&gt;*update 4:42pm 28 Mar 08*&lt;br /&gt;You can also view the &lt;a href="http://rorbuilder.info/whiteboardqueue/whiteboardqueue_data.xml?passthru=1"&gt;whiteboard message queue&lt;/a&gt; [rorbuilder.info].&lt;br /&gt;&lt;br /&gt;*update 6:29pm Mar 08*&lt;br /&gt;I've created a short url (http://rubyurl.com/vxHD) (to demonstrate the cleaning of the whiteboard) which redirects to this http://rorbuilder.info/api/projectx.cgi?xml_project=&lt;project name="whiteboardqueue"&gt;&lt;methods&gt;&lt;method name="create"&gt;&lt;params&gt;&lt;param var="type"&gt;ecmascript&lt;/param&gt;&lt;param var="body"&gt;startRefresh(5)&lt;/param&gt;&lt;param var="sender"&gt;system&lt;/param&gt;&lt;/params&gt;&lt;/method&gt;&lt;method name="timer"&gt;&lt;params&gt;&lt;param var="timer"&gt;5&lt;/param&gt;&lt;/params&gt;&lt;/method&gt;&lt;method name="archive_and_format"&gt;&lt;params/&gt;&lt;/method&gt;&lt;method name="create"&gt;&lt;params&gt;&lt;param var="type"&gt;ecmascript&lt;/param&gt;&lt;param var="body"&gt;reloadDocument()&lt;/param&gt;&lt;param var="sender"&gt;system&lt;/param&gt;&lt;/params&gt;&lt;/method&gt;&lt;/methods&gt;&lt;/project&gt;&lt;br /&gt;&lt;br /&gt;I've </description>
      <pubDate>Thu, 27 Mar 2008 19:14:07 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5284</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Load PRX document and display elements</title>
      <link>http://snippets.dzone.com/posts/show/5250</link>
      <description>&lt;code&gt;&lt;br /&gt;//Using a simple curl library (not shown) to get xml text&lt;br /&gt;$curl = new CURL();&lt;br /&gt;//$prx contains the url of a PRX document (e.g. http://www.prxbuilder.com/link.aspx?p=1)&lt;br /&gt;$xml = $curl-&gt;get($prx);&lt;br /&gt;&lt;br /&gt;//Load the XML file&lt;br /&gt;$doc = new DOMDocument();&lt;br /&gt;$doc-&gt;loadXML($xml);&lt;br /&gt;&lt;br /&gt;//Retrieve specific PRX elements (subheadline, dateline, body)&lt;br /&gt;$subheadline = $doc-&gt;getElementsByTagName('subheadline')-&gt;item(0)-&gt;nodeValue;&lt;br /&gt;$dateline = $doc-&gt;getElementsByTagName('dateline')-&gt;item(0)-&gt;nodeValue;&lt;br /&gt;$body = $doc-&gt;getElementsByTagName('body')-&gt;item(0)-&gt;nodeValue;&lt;br /&gt;&lt;br /&gt;//Format and display - apply_filters is a WP function.&lt;br /&gt;$content = '&lt;p&gt;'.$subheadline.'&lt;/p&gt;';&lt;br /&gt;$content .= '&lt;p&gt;'.$dateline.'&lt;/p&gt;';&lt;br /&gt;$content .= '&lt;p&gt;'.$body.'&lt;/p&gt;';&lt;br /&gt;$content = apply_filters('the_content_rss', $content);&lt;br /&gt;$content = str_replace(']]&gt;', ']]&amp;gt;', $content);&lt;br /&gt;&lt;br /&gt;echo $content;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 18 Mar 2008 16:59:03 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5250</guid>
      <author>swhitley (Shannon Whitley)</author>
    </item>
    <item>
      <title>Load PRX document and display elements</title>
      <link>http://snippets.dzone.com/posts/show/5249</link>
      <description>&lt;code&gt;&lt;br /&gt;//Using a simple curl library (not shown) to get xml text&lt;br /&gt;$curl = new CURL();&lt;br /&gt;//$prx contains the url of a PRX document (e.g. http://www.prxbuilder.com/link.aspx?p=1)&lt;br /&gt;$xml = $curl-&gt;get($prx);&lt;br /&gt;&lt;br /&gt;//Load the XML file&lt;br /&gt;$doc = new DOMDocument();&lt;br /&gt;$doc-&gt;loadXML($xml);&lt;br /&gt;&lt;br /&gt;//Retrieve specific PRX elements (subheadline, dateline, body)&lt;br /&gt;$subheadline = $doc-&gt;getElementsByTagName('subheadline')-&gt;item(0)-&gt;nodeValue;&lt;br /&gt;$dateline = $doc-&gt;getElementsByTagName('dateline')-&gt;item(0)-&gt;nodeValue;&lt;br /&gt;$body = $doc-&gt;getElementsByTagName('body')-&gt;item(0)-&gt;nodeValue;&lt;br /&gt;&lt;br /&gt;//Format and display - apply_filters is a WP function.&lt;br /&gt;$content = '&lt;p&gt;'.$subheadline.'&lt;/p&gt;';&lt;br /&gt;$content .= '&lt;p&gt;'.$dateline.'&lt;/p&gt;';&lt;br /&gt;$content .= '&lt;p&gt;'.$body.'&lt;/p&gt;';&lt;br /&gt;$content = apply_filters('the_content_rss', $content);&lt;br /&gt;$content = str_replace(']]&gt;', ']]&amp;gt;', $content);&lt;br /&gt;&lt;br /&gt;echo $content;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 18 Mar 2008 16:57:00 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5249</guid>
      <author>swhitley (Shannon Whitley)</author>
    </item>
  </channel>
</rss>
