<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: escape code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 17 May 2008 21:48:28 GMT</pubDate>
    <description>DZone Snippets: escape code</description>
    <item>
      <title>ProjectX client-side code</title>
      <link>http://snippets.dzone.com/posts/show/5150</link>
      <description>This Ruby code uses a unified XML format to create a password record on a web server. It's intended to be run as a batch file which gets called from another Ruby application called maintain_projectx which gets called from a cronjob.&lt;br /&gt;&lt;br /&gt;In this example the password is stored on the server not for authentication but simply to provide a reminder service in the event the user forgets it.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'net/http'&lt;br /&gt;require 'rexml/document'&lt;br /&gt;include REXML&lt;br /&gt;&lt;br /&gt;class ProjectXClient&lt;br /&gt;  attr :doc&lt;br /&gt;  def initialize(raw_url)&lt;br /&gt;    url = URI.escape(raw_url)&lt;br /&gt;    xml_data = Net::HTTP.get_response(URI.parse(url)).body&lt;br /&gt;    @doc = Document.new(xml_data)&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;if __FILE__ == $0&lt;br /&gt;&lt;br /&gt;  xml_project = &lt;&lt;PROJECT&lt;br /&gt;  &lt;project name='password'&gt;&lt;br /&gt;    &lt;method name='create'&gt;&lt;br /&gt;      &lt;params&gt;&lt;br /&gt;        &lt;param var='password' val='p6789c'/&gt;&lt;br /&gt;        &lt;param var='title' val='hotmail'/&gt;&lt;br /&gt;      &lt;/params&gt;&lt;br /&gt;    &lt;/method&gt;&lt;br /&gt;  &lt;/project&gt;&lt;br /&gt;PROJECT&lt;br /&gt;  &lt;br /&gt;  pxc = ProjectXClient.new("http://yourdomain.com/p/projectx.cgi?xml_project=" + xml_project)&lt;br /&gt;  doc = pxc.doc&lt;br /&gt;  puts doc&lt;br /&gt;    &lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;output -what's returned from the server is an XML response containing a result. The result echos the method executed and the output from that method, which in this instance is the xml record node 'entry'.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;result method='rtn_create'&gt;&lt;br /&gt;  &lt;append id='19367'&gt;&lt;br /&gt;    &lt;entry id='19367'&gt;&lt;br /&gt;      &lt;password&gt;p6789c&lt;/password&gt;&lt;br /&gt;      &lt;title&gt;hotmail&lt;/title&gt;&lt;br /&gt;      &lt;description/&gt;&lt;br /&gt;    &lt;/entry&gt;&lt;br /&gt;  &lt;/append&gt;&lt;br /&gt;&lt;/result&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Mon, 18 Feb 2008 18:49:42 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5150</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>add-escapes - escape chars in a string</title>
      <link>http://snippets.dzone.com/posts/show/2622</link>
      <description>&lt;code&gt;&lt;br /&gt;    add-escapes: func [&lt;br /&gt;        "Insert the esc-with value before each instance of val, unless it's part of a list of things to ignore."&lt;br /&gt;        series   [string!]&lt;br /&gt;        val      [char!] "the char to escape"&lt;br /&gt;        esc-with [char!] "the char to escape it with"&lt;br /&gt;        /ignore special [block!] "block of strings to ignore"&lt;br /&gt;        /local rule=&lt;br /&gt;    ][&lt;br /&gt;        rule=: copy/deep [&lt;br /&gt;            any [&lt;br /&gt;                ; ignore rule will be added here if needed&lt;br /&gt;                mark: val (insert mark esc-with) skip&lt;br /&gt;                | skip&lt;br /&gt;            ]&lt;br /&gt;        ]&lt;br /&gt;        ; If they have things they want us to ignore, add a rule at the&lt;br /&gt;        ; beginning of the ANY rule, and a pipe symbol after it.&lt;br /&gt;        if special [&lt;br /&gt;            ; rule=/2 is the ANY block&lt;br /&gt;            ; pipe 1 is DELIMIT param&lt;br /&gt;            ; pipe 2 is new rule 'OR separator&lt;br /&gt;            insert rule=/2 reduce [delimit copy special '| '|]&lt;br /&gt;        ]&lt;br /&gt;        parse/all series rule=&lt;br /&gt;        series&lt;br /&gt;    ]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 19 Sep 2006 02:24:38 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2622</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
  </channel>
</rss>
