<?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>Dimuthu's Blog &#187; personal</title>
	<atom:link href="http://www.dimuthu.org/catagory/personal/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dimuthu.org</link>
	<description>Waiting for your comments</description>
	<lastBuildDate>Wed, 03 Feb 2010 02:03:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<image>
  <link>http://www.dimuthu.org</link>
  <url>http://www.dimuthu.org/favicon.ico</url>
  <title>Dimuthu's Blog</title>
</image>
		<item>
		<title>100 Posts For dimuthu.org</title>
		<link>http://www.dimuthu.org/blog/2009/03/01/100-posts-for-dimuthuorg/</link>
		<comments>http://www.dimuthu.org/blog/2009/03/01/100-posts-for-dimuthuorg/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 17:52:10 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[personal]]></category>
		<category><![CDATA[100 post]]></category>
		<category><![CDATA[dimuthu.org]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=956</guid>
		<description><![CDATA[100 Posts
42800+ Views
]]></description>
			<content:encoded><![CDATA[<h4>100 Posts</h4>
<div id="attachment_963" class="wp-caption aligncenter" style="width: 526px"><a href="http://www.dimuthu.org/wp-content/uploads/2009/03/blog_view1.jpg"><img class="size-full wp-image-963" title="Blog Stats" src="http://www.dimuthu.org/wp-content/uploads/2009/03/blog_view1.jpg" alt="Blog Stats" width="516" height="184" /></a><p class="wp-caption-text">Blog Stats</p></div>
<h4>42800+ Views</h4>
<div id="attachment_964" class="wp-caption aligncenter" style="width: 660px"><a href="http://www.dimuthu.org/wp-content/uploads/2009/03/graph_summary_barchart1.jpg"><img class="size-full wp-image-964" title="Visitor Stats" src="http://www.dimuthu.org/wp-content/uploads/2009/03/graph_summary_barchart1.jpg" alt="Visitor Stats" width="650" height="300" /></a><p class="wp-caption-text">Visitor Stats</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2009/03/01/100-posts-for-dimuthuorg/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Organic Chemistry &#8211; Reaction Simulator</title>
		<link>http://www.dimuthu.org/blog/2008/11/22/organic-chemistry-reaction-simulator/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/22/organic-chemistry-reaction-simulator/#comments</comments>
		<pubDate>Sat, 22 Nov 2008 05:24:24 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[Organic Chemistry]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[personal]]></category>
		<category><![CDATA[screenshots]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[G.C.E. A/L]]></category>
		<category><![CDATA[Reaction Simulator]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=683</guid>
		<description><![CDATA[Organic Reaction Simulator
It is a tool that simulates the organic reactions and automatically generate the IUPAC names for the organic compounds drawn by you. This covers most of the syllabus of the Organic Chemistry for G.C.E. A/L examination.
Features

 Nice Canvas to draw your Organic compounds.
Generates IUPAC names for the drawn component as possible. (It generates [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Organic Reaction Simulator</strong></p>
<p>It is a tool that simulates the organic reactions and automatically generate the IUPAC names for the organic compounds drawn by you. This covers most of the syllabus of the Organic Chemistry for G.C.E. A/L examination.</p>
<p><strong>Features</strong></p>
<ul>
<li> Nice Canvas to draw your Organic compounds.</li>
<li>Generates IUPAC names for the drawn component as possible. (It generates IUPAC names for almost all the compounds which G.C.E A/L examination expect students to know)</li>
<li>You can simulate reaction for organic compounds with preferred inorganic/organic compounds and the selected conditions. (Currently supporting 168 reactions)</li>
<li>Extensibility of adding IUPAC naming rules without the need of recompiling the code.</li>
<li>Extensibility of adding custom reactions, again without compiling a single line of code.</li>
</ul>
<p>Here is a screen shot of the main panel when &#8216;Aldole reaction&#8217; is simulated for some simple reactants.</p>
<div id="attachment_690" class="wp-caption aligncenter" style="width: 510px"><a href="http://www.dimuthu.org/wp-content/uploads/2008/11/aldole.jpg"><img class="size-full wp-image-690" title="Aldole Reaction - Reaction Simulator" src="http://www.dimuthu.org/wp-content/uploads/2008/11/aldole.jpg" alt="Aldole Reaction - Reaction Simulator" width="500" height="392" /></a><p class="wp-caption-text">Aldole Reaction - Reaction Simulator</p></div>
<p><strong>The Drawing Panel</strong></p>
<p>The &#8216;Reaction Simulator&#8217; app provides 2 views for the user. One is the main panel which shows and manages reactions which is shown in the above figure. The other view is the drawing panel. It will be not much different from your favorite drawing application.</p>
<div id="attachment_692" class="wp-caption aligncenter" style="width: 510px"><a href="http://www.dimuthu.org/wp-content/uploads/2008/11/drawing_panel.jpg"><img class="size-full wp-image-692" title="Drawing Panel - Reaction Simulator" src="http://www.dimuthu.org/wp-content/uploads/2008/11/drawing_panel.jpg" alt="Drawing Panel - Reaction Simulator" width="500" height="392" /></a><p class="wp-caption-text">Drawing Panel - Reaction Simulator</p></div>
<p>Here you can select elements and bond types to draw your organic compound. Additionally It has tools to move or delete selected parts of your drawing.</p>
<p>The other thing you may have already noticed, you don&#8217;t need to complete all the bonds for a particular element. Rather if you keep one side of a single bond unconnected, it will be automatically connected to a &#8216;H&#8217;(Hydrogen) at the rendering, similarly for double bond the default connecting element would be &#8216;O&#8217;(Oxygen), and for triple bond it is &#8216;N&#8217; (Nytrogen). And you don&#8217;t even need to bother about connecting bonds with an element, as if you connected only one bond to &#8216;C&#8217; all the other 3 possible bonds will be considered as connected with &#8216;H&#8217;s.</p>
<p>Just check the drawing panel on your own and find its user friendliness. Now after you finish designing your compound, just press &#8220;RETURN&#8221;.</p>
<div id="attachment_694" class="wp-caption aligncenter" style="width: 510px"><a href="http://www.dimuthu.org/wp-content/uploads/2008/11/iupac.jpg"><img class="size-full wp-image-694" title="IUPAC Name Generator - Reaction Simulator" src="http://www.dimuthu.org/wp-content/uploads/2008/11/iupac.jpg" alt="IUPAC Name Generator - Reaction Simulator" width="500" height="392" /></a><p class="wp-caption-text">IUPAC Name Generator - Reaction Simulator</p></div>
<p>Yea it will nicely render our compound, and look at the bottom, it has generated the IUPAC name for the compound.</p>
<p><strong>The Main Panel</strong></p>
<p>This contain a canvas that you can add, edit and delete organic compounds (so you will be directed to the &#8216;Drawing Panel&#8217;), some sidebar panels to select Inorganic compounds and additional conditions requires for the reactions and a set of buttons to start reactions and manage the result set. At the end of the sidebar there is a &#8216;help&#8217; button that directed you to the user guide.</p>
<p><strong>Extending IUPAC Naming Rules</strong></p>
<p>If you go to the &#8220;Data/IUPAC/&#8221; directory (you can view svn from here, <a href="http://svn.dimuthu.org/organic_chemistry/Organic_Reaction_Simulator/Data/IUPAC/">http://svn.dimuthu.org/organic_chemistry/Organic_Reaction_Simulator/Data/IUPAC/</a>) you can find there are set of .txt files (infact xmls) that defines the IUPAC rules.</p>
<p>If you open one of them (we will take al.txt), it would be something like this</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;IUPAC</span> <span style="color: #000066;">basename</span>=<span style="color: #ff0000;">"al"</span> <span style="color: #000066;">subname</span>=<span style="color: #ff0000;">"oxo"</span> <span style="color: #000066;">level</span>=<span style="color: #ff0000;">"6"</span> <span style="color: #000066;">nonumber</span>=<span style="color: #ff0000;">"true"</span> <span style="color: #000066;">affectto</span>=<span style="color: #ff0000;">"1"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bond</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"2"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;element</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"7"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/element<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bond<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bond</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"1"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;element</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"1"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/element<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bond<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/IUPAC<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>It is the naming rules for aldehyde compounds. (H-C=O). First it identify the the aldehyde by checking double bond to &#8216;O&#8217; (which is the element type &#8216;7&#8242;), and a single bond to &#8216;H&#8217; (which is the element type &#8216;1&#8242;). If the element group found, it will give the name &#8216;al&#8217; or &#8216;oxo&#8217; depending on whether it defines the main group of elements of the compound or not.</p>
<p>If you take a look at all these rules, you can have a good idea what each of these syntax mean. And may be you can add your own rules, if you find something missing or incorrect there.</p>
<p><strong>Extending the Reactions</strong></p>
<p>The reaction rules are stored in the &#8220;Data/Reactions/&#8221; directory ( <a href="http://svn.dimuthu.org/organic_chemistry/Organic_Reaction_Simulator/Data/Reactions/">http://svn.dimuthu.org/organic_chemistry/Organic_Reaction_Simulator/Data/Reactions/</a>).</p>
<p>I will take the first reaction we studied in the &#8216;Organic Chemistry&#8217; Class.</p>
<p>CH4 + Cl2 + hv  (dim light) &#8212;&#8212;&#8212;&#8212;&#8212;-&gt; CCl4 + H2</p>
<p>Here is the rule defining that reaction. (cl2hv.txt)</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;reaction</span> <span style="color: #000066;">inorganics</span>=<span style="color: #ff0000;">"Cl2"</span> <span style="color: #000066;">conditions</span>=<span style="color: #ff0000;">"hv"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;check<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bond</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"1"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
			<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;element</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"H"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
			<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/element<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bond<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/check<span style="font-weight: bold; color: black;">&gt;</span></span></span>

	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;reordering</span> <span style="color: #000066;">activity</span>=<span style="color: #ff0000;">"remain"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bond</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"1"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
			<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;check<span style="font-weight: bold; color: black;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;element</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"H"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
				<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/element<span style="font-weight: bold; color: black;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/check<span style="font-weight: bold; color: black;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;reordering</span> <span style="color: #000066;">activity</span>=<span style="color: #ff0000;">"remain"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
				<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;element</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"H"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
					<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;reordering</span> <span style="color: #000066;">activity</span>=<span style="color: #ff0000;">"replace"</span> <span style="color: #000066;">to</span>=<span style="color: #ff0000;">"Cl"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
					<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/reordering<span style="font-weight: bold; color: black;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/element<span style="font-weight: bold; color: black;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/reordering<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bond<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/reordering<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/reaction<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>If you take a close look at, what it says is if there exist inorganic &#8216;Cl2&#8242; and condition &#8216;hv&#8217; (reactions inorganics=&#8221;Cl2&#8243; conditions=&#8221;hv&#8221;), check for a &#8216;H&#8217; (element type=&#8221;H&#8221;) elements that is connected to a &#8216;C&#8217; element (which is the root of the XML) through a single bond (bond type=&#8221;1&#8243;), then don&#8217;t replace the &#8216;C&#8217; (reordering activity=&#8221;remain&#8221;) and don&#8217;t replace the bond type (reordering activity=&#8221;remain&#8221;), just replace the &#8216;H&#8217; with &#8216;Cl&#8217; (reordering activity=&#8221;replace&#8221; to=&#8221;Cl&#8221;). It is so simple as that.</p>
<p>These rules are applied to all the C elements in reactants. Look at the following figure for this rule in application.</p>
<div id="attachment_698" class="wp-caption aligncenter" style="width: 510px"><a href="http://www.dimuthu.org/wp-content/uploads/2008/11/cl2hv.jpg"><img class="size-full wp-image-698" title="Alkane + Cl2 Reaction - Reaction Simulator" src="http://www.dimuthu.org/wp-content/uploads/2008/11/cl2hv.jpg" alt="Alkane + Cl2 Reaction - Reaction Simulator" width="500" height="392" /></a><p class="wp-caption-text">Alkane + Cl2 Reaction - Reaction Simulator</p></div>
<p>These reaction rules can be as complex as you want. Specially when two or more reactants are involved in a reaction, rules defining that reaction will be little complex. Look at how aldole reaction (which is applied in the first figure of this post) is written in <a href="http://svn.dimuthu.org/organic_chemistry/Organic_Reaction_Simulator/Data/Reactions/aldole.txt">aldole.txt</a>.</p>
<p>There are all together 168 reactions currently defined in this way. If you found some reaction is missing, feel free to add a another rule file defining that reaction. And if you want to share that with others, just let me know <img src='http://www.dimuthu.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> , so I can integrate it in to the distribution.</p>
<p><strong>Download</strong></p>
<p>This software application is not yet in a official release. I just thought use this post to do a pre release of the &#8216;Reaction Simulator&#8217;. You can download the windows binary of the pre release version (343KB) from <a href="http://downloads.dimuthu.org/bins/chemistry/reaction_simulator_pre_release/reaction_simulator_pre_release.zip">http://downloads.dimuthu.org/bins/chemistry/reaction_simulator_pre_release/reaction_simulator_pre_release.zip</a></p>
<p><strong>Source Code</strong></p>
<p>SVN location for the source code of &#8216;Reaction Simulator&#8217; is <a href="http://svn.dimuthu.org/organic_chemistry/Organic_Reaction_Simulator/">http://svn.dimuthu.org/organic_chemistry/Organic_Reaction_Simulator/</a></p>
<p><strong>Known Limitations &#8211; Possible Improvements<br />
</strong></p>
<ul>
<li>Generation of IUPAC names and simulations of reactions are not supported for compounds which involves Benzene ring.</li>
<li>IUPAC names generation is not supported for cyclic compounds which are anyway not part of the G.C.E. A/L syllabus.</li>
<li>The set of elements, available in drawing compounds, set of inorganic compounds and conditions, available in reactions are fixed and cannot be extended without changing the code and recompiling.</li>
<li>You can&#8217;t start with an IUPAC name and derive the compound. Currently you always have to start with drawing the compound and then generate the IUPAC.</li>
<li>Only for windows!</li>
</ul>
<p><strong>Little Background</strong></p>
<p>4 years ago, When I was a level 2 student in the <a href="http://www.mrt.ac.lk/">University of Moratuwa</a>, I participated to a competition for making educational software tools organized by <a href="http://www.cse.mrt.ac.lk/">C.S.E</a> and <a href="http://www.nie.lk/">N.I.E (National Institute of Education)</a>. I submitted a software that teaches Organic Chemistry. It consisted of interactive tutorials targeting local G.C.E A/L exams with exercises and revisions in both Sinhala(My Mother tongue) and English languages(not in Unicode though). I got the second price for that.</p>
<p>After the award I decided to improve my software application by adding an &#8216;Organic Reaction Simulator&#8217;. In fact in the vacation of 2 weeks for the New Year, I could complete it.</p>
<p>Although the N.I.E supposed to distribute the applications submitted to the competition throughout the country, it didn&#8217;t happened. So I decided to publish at least the &#8216;Reaction Simulator&#8217; application which I actually didn&#8217;t submitted to the competition.</p>
<p><strong>Technologies Used</strong></p>
<p>This is completely written in C++. It hasn&#8217;t use MFC, because I thought MFC is too heavy for such a small application. I used a lightweight, small image library code taken with some custom changes from some windows game programming book.</p>
<p>This is using XML to load data about reactions and IUPAC names which I have described in details in the early part of the blog. It uses a small inbuilt xml parser (just one recursive function) to parse these xmls.</p>
<p>So it has no depenedencies to third party libraries, You can just chekcout the <a href="http://svn.dimuthu.org/organic_chemistry/Organic_Reaction_Simulator/">souce code from the svn</a>, open the visual studio project and compile it (press &#8216;F7&#8242;).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/22/organic-chemistry-reaction-simulator/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Perl XML Parsers And My Story</title>
		<link>http://www.dimuthu.org/blog/2008/07/28/perl-xml-parsers-and-my-story/</link>
		<comments>http://www.dimuthu.org/blog/2008/07/28/perl-xml-parsers-and-my-story/#comments</comments>
		<pubDate>Mon, 28 Jul 2008 16:50:27 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[personal]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/perl]]></category>
		<category><![CDATA[cgi]]></category>
		<category><![CDATA[libxml]]></category>
		<category><![CDATA[namespace]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[twig]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xmlxpath]]></category>
		<category><![CDATA[xpath]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=61</guid>
		<description><![CDATA[Last week I had an opportunity to write some CGI scripts in Perl. It is like going few years back in web development. And it gave me the answer why PHP become favorite over Perl among the web developers. It is not just PHP&#8217;s C-like friendly syntax, but also the ability to write inline script [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I had an opportunity to write some CGI scripts in Perl. It is like going few years back in web development. And it gave me the answer why PHP become favorite over Perl among the web developers. It is not just PHP&#8217;s C-like friendly syntax, but also the ability to write inline script in html may have been a big factor.</p>
<p>In there we came across parsing following type of XML.</p>
<pre><span style="font-weight: bold; color: black;">&lt;ns1:person</span>
       xmlns:ns1=<span style="color: #ff0000;">"http://dimuthu.org/example/perl_xml/xsd"</span><span style="font-weight: bold; color: black;">&gt;</span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns1:name<span style="font-weight: bold; color: black;">&gt;</span></span></span>PQR XYZ<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns1:name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns1:age<span style="font-weight: bold; color: black;">&gt;</span></span></span>25<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns1:age<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns1:person<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>We started to use <a href="http://search.cpan.org/~mirod/XML-Twig-3.32/">XML::Twig</a>. And it is pretty straightforward. Here was our code.</p>
<pre><span style="font-weight: bold; color: #000000;">use</span> XML::<span style="color: #006600;">Twig</span>;

<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$xml_str</span> = &lt;&lt;E;
<span style="font-weight: bold; color: black;">&lt;ns1:person</span>
    xmlns:ns1=<span style="color: #ff0000;">"http://dimuthu.org/example/perl_xml/xsd"</span><span style="font-weight: bold; color: black;">&gt;</span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns1:name<span style="font-weight: bold; color: black;">&gt;</span></span></span>PQR XYZ<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns1:name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ns1:age<span style="font-weight: bold; color: black;">&gt;</span></span></span>25<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns1:age<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ns1:person<span style="font-weight: bold; color: black;">&gt;</span></span></span>
E

<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$xt</span> = XML::<span style="color: #006600;">Twig</span>-&gt;<span style="color: #006600;">new</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$xt</span>-&gt;<span style="color: #006600;">parse</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$xml_str</span><span style="color: #66cc66;">)</span>;

<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$txt</span> = <span style="color: #0000ff;">$xt</span>-&gt;<span style="color: #006600;">root</span>-&gt;<span style="color: #006600;">findvalue</span><span style="color: #66cc66;">(</span>"//ns1:name"<span style="color: #66cc66;">)</span>;
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #0000ff;">$txt</span>;</pre>
<p>OK. It was working.</p>
<p>Anyway in practice we found that this is not the only way we receive the xml. That is the namespace prefix can be different. When you write an XML to an XML schema you are free to have your own prefixes for the namespaces. And in fact in practice different people, programs and vendors uses different prefixes.</p>
<p>So our program should be able to parse following XML too. (see the namespace prefix is changed)</p>
<pre><span style="font-weight: bold; color: black;">&lt;ns0:person</span>
    xmlns:ns0=<span style="color: #ff0000;">"http://dimuthu.org/example/perl_xml/xsd"</span><span style="font-weight: bold; color: black;">&gt;</span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;</span></span><span style="font-weight: bold; color: black;">ns0</span><span style="color: #009900;"><span style="font-weight: bold; color: black;">:name<span style="font-weight: bold; color: black;">&gt;</span></span></span>PQR XYZ<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/</span></span><span style="font-weight: bold; color: black;">ns0</span><span style="color: #009900;"><span style="font-weight: bold; color: black;">:name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;</span></span><span style="font-weight: bold; color: black;">ns0</span><span style="color: #009900;"><span style="font-weight: bold; color: black;">:age<span style="font-weight: bold; color: black;">&gt;</span></span></span>25<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/</span></span><span style="font-weight: bold; color: black;">ns0</span><span style="color: #009900;"><span style="font-weight: bold; color: black;">:age<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/</span></span><span style="font-weight: bold; color: black;">ns0</span><span style="color: #009900;"><span style="font-weight: bold; color: black;">:person<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>And with the default namespace.</p>
<pre><span style="font-weight: bold; color: black;">&lt;person</span> xmlns=<span style="color: #ff0000;">"http://dimuthu.org/example/perl_xml/xsd"</span><span style="font-weight: bold; color: black;">&gt;</span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">name<span style="font-weight: bold; color: black;">&gt;</span></span></span>PQR XYZ<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">age<span style="font-weight: bold; color: black;">&gt;</span></span></span>25<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">age<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">person<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>Both these occasions our code failed. And normally whenever there is an API to parse XPath, you can register namespaces. But XML::Twit there was no something like that. That made us to jump to use <a href="http://search.cpan.org/~pajas/XML-LibXML-1.66/">XML::LibXML</a>. It is apparently little complicated than the simple Twig API. But it did work. (Look later for the code using XML::LibXML)</p>
<p>The story is actually there is a way to register namespaces in Twit, in fact it is not in  XML::Twit, it is in the XML::Twit:XPath module which is hardly any documented. It just duplicate the Twit API adding some functionalities to deal with namespaces. Apparently not the most elegant way of designing an API. Anyway Here is the code that works written using XML::Twit:XPath.</p>
<pre><span style="font-weight: bold; color: #000000;">use</span> XML::<span style="color: #006600;">Twig</span>;
<span style="font-weight: bold; color: #000000;">use</span> XML::<span style="color: #006600;">Twig</span>::<span style="color: #006600;">XPath</span>;

<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$xml_str</span> = &lt;&lt;E;

<span style="font-weight: bold; color: black;">&lt;person</span> xmlns=<span style="color: #ff0000;">"http://dimuthu.org/example/perl_xml/xsd"</span><span style="font-weight: bold; color: black;">&gt;</span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">name<span style="font-weight: bold; color: black;">&gt;</span></span></span>PQR XYZ<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">age<span style="font-weight: bold; color: black;">&gt;</span></span></span>25<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">age<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">person<span style="font-weight: bold; color: black;">&gt;</span></span></span>

E

<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$xtp</span> = XML::<span style="color: #006600;">Twig</span>::<span style="color: #006600;">XPath</span>-&gt;<span style="color: #006600;">new</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$xtp</span>-&gt;<span style="color: #006600;">parse</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$xml_str</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$xtp</span>-&gt;<span style="color: #006600;">set_namespace</span><span style="color: #66cc66;">(</span>'ns',
       'http://dimuthu.org/example/perl_xml/xsd'<span style="color: #66cc66;">)</span>;

<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$txt</span> = <span style="color: #0000ff;">$xtp</span>-&gt;<span style="color: #006600;">root</span>-&gt;<span style="color: #006600;">findvalue</span><span style="color: #66cc66;">(</span>'//ns:name'<span style="color: #66cc66;">)</span>;
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #0000ff;">$txt</span>;</pre>
<p>Note that I have register the namespace to the prefix &#8216;ns&#8217;, so in xpath quires I can use this prefix to refer namespaces.</p>
<p>Anyway Perl is not bad, it has dozens of modules to do the same thing. So just for the reference I will note down it here,</p>
<p>Using <a href="http://search.cpan.org/~msergeant/XML-XPath-1.13/XPath.pm">XML:XPath</a>,</p>
<pre><span style="font-weight: bold; color: #000000;">use</span> XML::<span style="color: #006600;">XPath</span>;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$xml_str</span> = &lt;&lt;E;

<span style="font-weight: bold; color: black;">&lt;person</span> xmlns=<span style="color: #ff0000;">"http://dimuthu.org/example/perl_xml/xsd"</span><span style="font-weight: bold; color: black;">&gt;</span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">name<span style="font-weight: bold; color: black;">&gt;</span></span></span>PQR XYZ<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">age<span style="font-weight: bold; color: black;">&gt;</span></span></span>25<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">age<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">person<span style="font-weight: bold; color: black;">&gt;</span></span></span>

E

<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$xp</span> = XML::<span style="color: #006600;">XPath</span>-&gt;<span style="color: #006600;">new</span><span style="color: #66cc66;">(</span>xml =&gt; <span style="color: #0000ff;">$xml_str</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$xp</span>-&gt;<span style="color: #006600;">set_namespace</span><span style="color: #66cc66;">(</span>'ns',
       'http://dimuthu.org/example/perl_xml/xsd<span style="color: #66cc66;">')</span>;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$txt</span> = <span style="color: #0000ff;">$xp</span>-&gt;<span style="color: #006600;">findvalue</span><span style="color: #66cc66;">('</span>//ns:name'<span style="color: #66cc66;">)</span>; <span style="font-style: italic; color: #808080;"># get name </span>

<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #0000ff;">$txt</span>;</pre>
<p>Then Using <a href="http://search.cpan.org/~pajas/XML-LibXML-1.66/LibXML.pod">XML::LibXML</a>;</p>
<pre><span style="font-weight: bold; color: #000000;">use</span> XML::<span style="color: #006600;">LibXML</span>;

<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$xml_str</span> = &lt;&lt;E;

<span style="font-weight: bold; color: black;">&lt;person</span> xmlns=<span style="color: #ff0000;">"http://dimuthu.org/example/perl_xml/xsd"</span><span style="font-weight: bold; color: black;">&gt;</span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">name<span style="font-weight: bold; color: black;">&gt;</span></span></span>PQR XYZ<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">age<span style="font-weight: bold; color: black;">&gt;</span></span></span>25<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">age<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">person<span style="font-weight: bold; color: black;">&gt;</span></span></span>

E

<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$xl</span>= XML::<span style="color: #006600;">LibXML</span>-&gt;<span style="color: #006600;">new</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$xml</span> = <span style="color: #0000ff;">$xl</span>-&gt;<span style="color: #006600;">parse_string</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$xml_str</span><span style="color: #66cc66;">)</span>;

<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$xpc</span> = XML::<span style="color: #006600;">LibXML</span>::<span style="color: #006600;">XPathContext</span>-&gt;<span style="color: #006600;">new</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$xml</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$xpc</span>-&gt;<span style="color: #006600;">registerNs</span><span style="color: #66cc66;">(</span>'ns',
        'http://dimuthu.org/example/perl_xml/xsd<span style="color: #66cc66;">')</span>;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$txt</span> = <span style="color: #0000ff;">$xpc</span>-&gt;<span style="color: #006600;">findvalue</span><span style="color: #66cc66;">(</span>'//ns:name'<span style="color: #66cc66;">)</span>; <span style="font-style: italic; color: #808080;"># get name </span>

<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #0000ff;">$txt</span>;</pre>
<p>So it is all for this post, And one reason I didn&#8217;t tell you earlier and so obvious why PHP is popular over Perl. Look at<a href="http://php.net/simplexml"> http://php.net/dom</a> or <a href="http://php.net/simplexml">http://php.net/simplexml.</a> It has a great documentation for every function to the every needle. Whenever Perl, Ruby thinking of going pass PHP, they have to consider this aspect too more seriously.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/07/28/perl-xml-parsers-and-my-story/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Welcome to dimuthu.org</title>
		<link>http://www.dimuthu.org/blog/2008/07/19/welcome-to-dimuthuorg/</link>
		<comments>http://www.dimuthu.org/blog/2008/07/19/welcome-to-dimuthuorg/#comments</comments>
		<pubDate>Sat, 19 Jul 2008 11:11:19 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[personal]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[dimuthu.org]]></category>
		<category><![CDATA[me]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=3</guid>
		<description><![CDATA[I have been blogging in wordpress http://dimuthuc.wordpress.com and blogspot http://dimuthuc.blogspot.com for sometime now. And I have been blogging a lot around my working area from http://phpwebservices.blogspot.com.
Still I m not a regular blogger. And I dont think having my own blog with my own domain name will do any different  . But it s always [...]]]></description>
			<content:encoded><![CDATA[<p>I have been blogging in wordpress <a title="My Wordpress blog" href="http://dimuthuc.wordpress.com">http://dimuthuc.wordpress.com</a> and blogspot <a title="My Blogspot blog" href="http://dimuthuc.blogspot.com">http://dimuthuc.blogspot.com</a> for sometime now. And I have been blogging a lot around my working area from <a title="The PHP Webservices blog" href="http://phpwebservices.blogspot.com">http://phpwebservices.blogspot.com</a>.</p>
<p>Still I m not a regular blogger. And I dont think having my own blog with my own domain name will do any different <img src='http://www.dimuthu.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> . But it s always worth do a try.  Now I can install my favorite software and favorite plug-ins, themes and customize them to the full extend. Lacking of these features were the main reason I moved here and there before this. So I hope I will do more blogging in here.</p>
<p>So what will I blog? I have had some hits  for my blogs on Axis2/C, WSDL2C codegen tool, WSF/PHP and web services areas. And definitely I will continue blogging more and more on that space. And I should update the blog with the interesting things I learn from the work and studies that worth to share with everyone.</p>
<p>Hope to see you through many blogs!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/07/19/welcome-to-dimuthuorg/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
