title: extract attribute values from XML file (starlet)
body: <p>I have a small xml file with five entries in it:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;posts&gt;
    &lt;row Id="4" PostTypeId="1" AcceptedAnswerId="7" CreationDate="2008-07-31T21:42:52.667" Score="630" ViewCount="42817" Body="&amp;lt;p&amp;gt;I want to use a track-bar to change a form's opacity.&amp;lt;/p&amp;gt;&amp;#xA;&amp;#xA;&amp;lt;p&amp;gt;This is my code:&amp;lt;/p&amp;gt;&amp;#xA;&amp;#xA;&amp;lt;pre&amp;gt;&amp;lt;code&amp;gt;decimal trans = trackBar1.Value / 5000;&amp;#xA;this.Opacity = trans;&amp;#xA;&amp;lt;/code&amp;gt;&amp;lt;/pre&amp;gt;&amp;#xA;&amp;#xA;&amp;lt;p&amp;gt;When I build the application, it gives the following error:&amp;lt;/p&amp;gt;&amp;#xA;&amp;#xA;&amp;lt;blockquote&amp;gt;&amp;#xA;  &amp;lt;p&amp;gt;Cannot implicitly convert type &amp;lt;code&amp;gt;'decimal'&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;'double'&amp;lt;/code&amp;gt;&amp;lt;/p&amp;gt;&amp;#xA;&amp;lt;/blockquote&amp;gt;&amp;#xA;&amp;#xA;&amp;lt;p&amp;gt;I tried using &amp;lt;code&amp;gt;trans&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt; but then the control doesn't work. This code worked fine in a past VB.NET project.&amp;lt;/p&amp;gt;&amp;#xA;" OwnerUserId="8" LastEditorUserId="3641067" LastEditorDisplayName="Rich B" LastEditDate="2019-07-19T01:39:54.173" LastActivityDate="2019-07-19T01:39:54.173" Title="Convert Decimal to Double?" Tags="&amp;lt;c#&amp;gt;&amp;lt;floating-point&amp;gt;&amp;lt;type-conversion&amp;gt;&amp;lt;double&amp;gt;&amp;lt;decimal&amp;gt;" AnswerCount="13" CommentCount="2" FavoriteCount="48" CommunityOwnedDate="2012-10-31T16:42:47.213" /&gt;
    &lt;row Id="6" PostTypeId="1" AcceptedAnswerId="31" CreationDate="2008-07-31T22:08:08.620" Score="281" ViewCount="18214" Body="&amp;lt;p&amp;gt;I have an absolutely positioned &amp;lt;code&amp;gt;div&amp;lt;/code&amp;gt; containing several children, one of which is a relatively positioned &amp;lt;code&amp;gt;div&amp;lt;/code&amp;gt;. When I use a &amp;lt;code&amp;gt;percentage-based width&amp;lt;/code&amp;gt; on the child &amp;lt;code&amp;gt;div&amp;lt;/code&amp;gt;, it collapses to &amp;lt;code&amp;gt;0 width&amp;lt;/code&amp;gt; on IE7, but not on Firefox or Safari.&amp;lt;/p&amp;gt;&amp;#xA;&amp;#xA;&amp;lt;p&amp;gt;If I use &amp;lt;code&amp;gt;pixel width&amp;lt;/code&amp;gt;, it works. If the parent is relatively positioned, the percentage width on the child works.&amp;lt;/p&amp;gt;&amp;#xA;&amp;#xA;&amp;lt;ol&amp;gt;&amp;#xA;&amp;lt;li&amp;gt;Is there something I'm missing here?&amp;lt;/li&amp;gt;&amp;#xA;&amp;lt;li&amp;gt;Is there an easy fix for this besides the &amp;lt;code&amp;gt;pixel-based width&amp;lt;/code&amp;gt; on the&amp;#xA;child?&amp;lt;/li&amp;gt;&amp;#xA;&amp;lt;li&amp;gt;Is there an area of the CSS specification that covers this?&amp;lt;/li&amp;gt;&amp;#xA;&amp;lt;/ol&amp;gt;&amp;#xA;" OwnerUserId="9" LastEditorUserId="3641067" LastEditorDisplayName="Rich B" LastEditDate="2019-07-19T01:43:04.077" LastActivityDate="2019-07-19T01:43:04.077" Title="Percentage width child element in absolutely positioned parent on Internet Explorer 7" Tags="&amp;lt;html&amp;gt;&amp;lt;css&amp;gt;&amp;lt;internet-explorer-7&amp;gt;" AnswerCount="6" CommentCount="0" FavoriteCount="10" /&gt;
    &lt;row Id="7" PostTypeId="2" ParentId="4" CreationDate="2008-07-31T22:17:57.883" Score="425" Body="&amp;lt;p&amp;gt;An explicit cast to double like this isn't necessary:&amp;lt;/p&amp;gt;&amp;#xA;&amp;#xA;&amp;lt;pre&amp;gt;&amp;lt;code&amp;gt;double trans = (double) trackBar1.Value / 5000.0;&amp;#xA;&amp;lt;/code&amp;gt;&amp;lt;/pre&amp;gt;&amp;#xA;&amp;#xA;&amp;lt;p&amp;gt;Identifying the constant as &amp;lt;code&amp;gt;5000.0&amp;lt;/code&amp;gt; (or as &amp;lt;code&amp;gt;5000d&amp;lt;/code&amp;gt;) is sufficient:&amp;lt;/p&amp;gt;&amp;#xA;&amp;#xA;&amp;lt;pre&amp;gt;&amp;lt;code&amp;gt;double trans = trackBar1.Value / 5000.0;&amp;#xA;double trans = trackBar1.Value / 5000d;&amp;#xA;&amp;lt;/code&amp;gt;&amp;lt;/pre&amp;gt;&amp;#xA;" OwnerUserId="9" LastEditorUserId="4020527" LastEditDate="2017-12-16T05:06:57.613" LastActivityDate="2017-12-16T05:06:57.613" CommentCount="0" /&gt;
    &lt;row Id="9" PostTypeId="1" AcceptedAnswerId="1404" CreationDate="2008-07-31T23:40:59.743" Score="1742" ViewCount="555183" Body="&amp;lt;p&amp;gt;Given a &amp;lt;code&amp;gt;DateTime&amp;lt;/code&amp;gt; representing a person's birthday, how do I calculate their age in years?  &amp;lt;/p&amp;gt;&amp;#xA;" OwnerUserId="1" LastEditorUserId="3956566" LastEditorDisplayName="Rich B" LastEditDate="2018-04-21T17:48:14.477" LastActivityDate="2019-06-26T15:25:44.253" Title="How do I calculate someone's age in C#?" Tags="&amp;lt;c#&amp;gt;&amp;lt;.net&amp;gt;&amp;lt;datetime&amp;gt;" AnswerCount="63" CommentCount="5" FavoriteCount="436" CommunityOwnedDate="2011-08-16T19:40:43.080" /&gt;
    &lt;row Id="11" PostTypeId="1" AcceptedAnswerId="1248" CreationDate="2008-07-31T23:55:37.967" Score="1444" ViewCount="149445" Body="&amp;lt;p&amp;gt;Given a specific &amp;lt;code&amp;gt;DateTime&amp;lt;/code&amp;gt; value, how do I display relative time, like:&amp;lt;/p&amp;gt;&amp;#xA;&amp;#xA;&amp;lt;ul&amp;gt;&amp;#xA;&amp;lt;li&amp;gt;2 hours ago&amp;lt;/li&amp;gt;&amp;#xA;&amp;lt;li&amp;gt;3 days ago&amp;lt;/li&amp;gt;&amp;#xA;&amp;lt;li&amp;gt;a month ago&amp;lt;/li&amp;gt;&amp;#xA;&amp;lt;/ul&amp;gt;&amp;#xA;" OwnerUserId="1" LastEditorUserId="6479704" LastEditorDisplayName="user2370523" LastEditDate="2017-06-04T15:51:19.780" LastActivityDate="2019-05-26T02:31:53.863" Title="Calculate relative time in C#" Tags="&amp;lt;c#&amp;gt;&amp;lt;datetime&amp;gt;&amp;lt;time&amp;gt;&amp;lt;datediff&amp;gt;&amp;lt;relative-time-span&amp;gt;" AnswerCount="37" CommentCount="3" FavoriteCount="539" CommunityOwnedDate="2009-09-04T13:15:59.820" /&gt;
  &lt;/posts&gt;
  </code></pre>
  
  <p>I am interested in extracting only the Title and Body from each of the 5 entries. The best I could come up so far is using starlet:</p>
  
  <pre><code>xmlstarlet sel -T -t -m '/posts/row' -v "concat(@Body,'|', @Title)" -n very_small_posts.xml
  </code></pre>
  
  <p>very_small_posts.xml is the xml file with the above 5 entries. The problem with this the output has XML tags in them and I see empty lines too. Like below (output of first row):</p>
  
  <pre><code>&lt;p&gt;I want to use a track-bar to change a form's opacity.&lt;/p&gt;
  
  &lt;p&gt;This is my code:&lt;/p&gt;
  
  &lt;pre&gt;&lt;code&gt;decimal trans = trackBar1.Value / 5000;
  this.Opacity = trans;
  &lt;/code&gt;&lt;/pre&gt;
  
  &lt;p&gt;When I build the application, it gives the following error:&lt;/p&gt;
  
  &lt;blockquote&gt;
    &lt;p&gt;Cannot implicitly convert type &lt;code&gt;'decimal'&lt;/code&gt; to &lt;code&gt;'double'&lt;/code&gt;&lt;/p&gt;
  &lt;/blockquote&gt;
  
  &lt;p&gt;I tried using &lt;code&gt;trans&lt;/code&gt; and &lt;code&gt;double&lt;/code&gt; but then the control doesn't work. This code worked fine in a past VB.NET project.&lt;/p&gt;
  |Convert Decimal to Double?
  </code></pre>
  
  <p>Is there a way to clean them up? I want to see only regular text as output without any tags....and possibly with the attribute names preceding the values. I do not want to see <code>&lt;p&gt;, &lt;/p&gt;, &lt;blockquote&gt;</code>, ..in my output. Any suggestions?</p>
  
  <p>Preferred output (for first row):</p>
  
  <pre><code>Body=I want to use a track-bar to change a form's opacity. This is my code: decimal trans = trackBar1.Value / 5000; this.Opacity = trans; When I build the application, it gives the following error: Cannot implicitly convert type 'decimal' to 'double'I tried using trans and double but then the control doesn't work. This code worked fine in a past VB.NET project.
  Title=Convert Decimal to Double?
  </code></pre>