<?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>Promethe's Blog &#187; xml</title>
	<atom:link href="http://blog.promethe.net/tag/xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.promethe.net</link>
	<description>Web, RIAs and chocolate spaghettis...</description>
	<lastBuildDate>Tue, 29 Jun 2010 09:24:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Edit XML Namespaces with sed</title>
		<link>http://blog.promethe.net/2009/06/13/edit-xml-namespaces-with-sed/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=edit-xml-namespaces-with-sed</link>
		<comments>http://blog.promethe.net/2009/06/13/edit-xml-namespaces-with-sed/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 13:54:29 +0000</pubDate>
		<dc:creator>Promethe</dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[shell script]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://blog.promethe.net/?p=346</guid>
		<description><![CDATA[Even if you are a high level programing language user, you sometimes have to use some good old tools to gain some productivity. Sed is one of those tools that might come to be handy. I recently needed to change the xmlns attribute of a lot of XML/XSL files and doing it file by file [...]]]></description>
			<content:encoded><![CDATA[<p>Even if you are a high level programing language user, you sometimes have to use some good old tools to gain some productivity. <a href="http://en.wikipedia.org/wiki/Sed" target="_blank">Sed</a> is one of those tools that might come to be handy.</p>
<p>I recently needed to change the xmlns attribute of a lot of XML/XSL files and doing it file by file would have been a real mess. So I wrote this little piece of script shell:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/sh</span>
&nbsp;
<span style="color: #007800;">NAMESPACE_NAME</span>=$<span style="color: #000000;">1</span>
<span style="color: #007800;">NAMESPACE_URI</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #000000;">2</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/\//\\\//g'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">FILE</span>=$<span style="color: #000000;">3</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> x<span style="color: #800000;">${NAMESPACE_NAME}</span> = <span style="color: #ff0000;">'x'</span> <span style="color: #660033;">-o</span> x<span style="color: #800000;">${NAMESPACE_URI}</span> = <span style="color: #ff0000;">'x'</span> <span style="color: #660033;">-o</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-f</span> <span style="color: #800000;">${FILE}</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'Usage:'</span> <span style="color: #800000;">${0}</span> <span style="color: #ff0000;">'NAMESPACE_NAME NAMESPACE_URI FILE'</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">42</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$FILE</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> s<span style="color: #000000; font-weight: bold;">/</span>xmlns:<span style="color: #800000;">${NAMESPACE_NAME}</span>=<span style="color: #000000; font-weight: bold;">\&quot;</span>.<span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000; font-weight: bold;">\&quot;</span><span style="color: #000000; font-weight: bold;">/</span>xmlns:<span style="color: #800000;">${NAMESPACE_NAME}</span><span style="color: #ff0000;">'=&quot;'</span><span style="color: #800000;">${NAMESPACE_URI}</span><span style="color: #000000; font-weight: bold;">\&quot;</span><span style="color: #000000; font-weight: bold;">/</span>g <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$FILE</span></pre></div></div>

<p>You can run the script with the following command line:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>change_namespace.sh myns http:<span style="color: #000000; font-weight: bold;">//</span>my.namespace.uri my_file.xml</pre></div></div>

<p>Where :</p>
<ul>
<li>myns is the namespace name (html, xsl, xhtml, etc...)</li>
<li>http://my.namespace.uri is the URI of the namespace</li>
<li>my_file.xml is the file to edit</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.promethe.net/2009/06/13/edit-xml-namespaces-with-sed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
