<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Tim Barcz - Common Sense</title>
    <link>http://www.timbarcz.com/blog/</link>
    <description>My Code is My Craft</description>
    <image>
      <url>http://www.timbarcz.com/blog/content/binary/channelImage.jpg</url>
      <title>Tim Barcz - Common Sense</title>
      <link>http://www.timbarcz.com/blog/</link>
    </image>
    <language>en-us</language>
    <copyright>Tim Barcz</copyright>
    <lastBuildDate>Tue, 03 Feb 2009 15:57:46 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>blog@timbarcz.com</managingEditor>
    <webMaster>blog@timbarcz.com</webMaster>
    <item>
      <trackback:ping>http://www.timbarcz.com/blog/Trackback.aspx?guid=bba271e7-293d-4a55-a9ad-7fb8febd46d3</trackback:ping>
      <pingback:server>http://www.timbarcz.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.timbarcz.com/blog/PermaLink,guid,bba271e7-293d-4a55-a9ad-7fb8febd46d3.aspx</pingback:target>
      <dc:creator>Tim Barcz</dc:creator>
      <wfw:comment>http://www.timbarcz.com/blog/CommentView,guid,bba271e7-293d-4a55-a9ad-7fb8febd46d3.aspx</wfw:comment>
      <wfw:commentRss>http://www.timbarcz.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=bba271e7-293d-4a55-a9ad-7fb8febd46d3</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/DontOvercomplicateTheIssue_8C17/image_2.png">
            <img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="184" alt="image" src="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/DontOvercomplicateTheIssue_8C17/image_thumb.png" width="214" align="right" border="0" />
          </a> I
felt compelled to write after seeing this very same issue come up twice in the last
week or so, once for a fellow developer and today for me.
</p>
        <h2>The Problem
</h2>
        <p>
We use a DataSet for assistance with testing our data layer (think <a href="http://code.google.com/p/ndbunit/">NDBUnit</a>). 
The problem we have is that when you generate the DataSet the XSD created contains
all these table adapters that bloat the file, in our app the file bloats to about
five times the regular size.  We've found that deleting the table adapters on
the file makes the file open up so much faster.  However, every time we make
a change to the database schema we have to regenerate the DataSet so that it matches
the schema.  As the table count has grown deleting these table adapters by hand
has grown wearisome.  All this is merely set up for me over-fixing the problem.
</p>
        <h2>My First (Wrong) Thought
</h2>
        <p>
I thought to myself, "hey this is XML I'll just load up and XML document and
query out the nodes (TableAdapters) I don't need and remove them from the document
and save it back."  While writing a quick bit of code I found writing more
code than I needed (at this point I was only at 6 lines).  Despite the file being
XML, I don't need to treat it as XML.  Understand that nothing about getting
rid of the TableAdapters relies on the "XML-ness" of the file, it's all
just text. Reminding myself of that...here's what I came up with...
</p>
        <h2>The Second (Correct) Solution
</h2>
        <p>
Simply treat the file as text and remove the piece you need, the only caveat is that
I'm dealing with XML and so if I remove a "piece" I have to remove the whole
"piece" (where "piece" means XmlNode).  The solution below
simply matches TableAdapter nodes and replaces them with empty text.  Simple.
</p>
        <div>
          <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 1:</span> var
path = <span style="color: #006080">@"C:\dev\sandbox\Website\src\IntegrationTests\TestData\Database.xsd"</span>;</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 2:</span> var
text = File.ReadAllText(path);</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 3:</span> File.WriteAllText(path,
Regex.Replace(text, <span style="color: #006080">"&lt;TableAdapter.*?&gt;.*?&lt;/TableAdapter&gt;"</span>, <span style="color: #006080">""</span>,
RegexOptions.Singleline));</pre>
          </div>
        </div>
        <h2>The Point
</h2>
        <p>
The point is the first solution, while correct, was more complex than it needed to
be.  Using a little bit of RegEx to wipe clean certain nodes, I get exactly what
I want in three lines of code.  Moral of the story?  <strong>Don't overcomplicate
what doesn't need to be.</strong></p>
        <img width="0" height="0" src="http://www.timbarcz.com/blog/aggbug.ashx?id=bba271e7-293d-4a55-a9ad-7fb8febd46d3" />
      </body>
      <title>Don't Overcomplicate The Issue</title>
      <guid isPermaLink="false">http://www.timbarcz.com/blog/PermaLink,guid,bba271e7-293d-4a55-a9ad-7fb8febd46d3.aspx</guid>
      <link>http://www.timbarcz.com/blog/DontOvercomplicateTheIssue.aspx</link>
      <pubDate>Tue, 03 Feb 2009 15:57:46 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/DontOvercomplicateTheIssue_8C17/image_2.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="184" alt="image" src="http://www.timbarcz.com/blog/content/binary/WindowsLiveWriter/DontOvercomplicateTheIssue_8C17/image_thumb.png" width="214" align="right" border="0" /&gt;&lt;/a&gt; I
felt compelled to write after seeing this very same issue come up twice in the last
week or so, once for a fellow developer and today for me.
&lt;/p&gt;
&lt;h2&gt;The Problem
&lt;/h2&gt;
&lt;p&gt;
We use a DataSet for assistance with testing our data layer (think &lt;a href="http://code.google.com/p/ndbunit/"&gt;NDBUnit&lt;/a&gt;).&amp;#160;
The problem we have is that when you generate the DataSet the XSD created contains
all these table adapters that bloat the file, in our app the file bloats to about
five times the regular size.&amp;#160; We've found that deleting the table adapters on
the file makes the file open up so much faster.&amp;#160; However, every time we make
a change to the database schema we have to regenerate the DataSet so that it matches
the schema.&amp;#160; As the table count has grown deleting these table adapters by hand
has grown wearisome.&amp;#160; All this is merely set up for me over-fixing the problem.
&lt;/p&gt;
&lt;h2&gt;My First (Wrong) Thought
&lt;/h2&gt;
&lt;p&gt;
I thought to myself, &amp;quot;hey this is XML I'll just load up and XML document and
query out the nodes (TableAdapters) I don't need and remove them from the document
and save it back.&amp;quot;&amp;#160; While writing a quick bit of code I found writing more
code than I needed (at this point I was only at 6 lines).&amp;#160; Despite the file being
XML, I don't need to treat it as XML.&amp;#160; Understand that nothing about getting
rid of the TableAdapters relies on the &amp;quot;XML-ness&amp;quot; of the file, it's all
just text. Reminding myself of that...here's what I came up with...
&lt;/p&gt;
&lt;h2&gt;The Second (Correct) Solution
&lt;/h2&gt;
&lt;p&gt;
Simply treat the file as text and remove the piece you need, the only caveat is that
I'm dealing with XML and so if I remove a &amp;quot;piece&amp;quot; I have to remove the whole
&amp;quot;piece&amp;quot; (where &amp;quot;piece&amp;quot; means XmlNode).&amp;#160; The solution below
simply matches TableAdapter nodes and replaces them with empty text.&amp;#160; Simple.
&lt;/p&gt;
&lt;div&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 1:&lt;/span&gt; var
path = &lt;span style="color: #006080"&gt;@&amp;quot;C:\dev\sandbox\Website\src\IntegrationTests\TestData\Database.xsd&amp;quot;&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 2:&lt;/span&gt; var
text = File.ReadAllText(path);&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 3:&lt;/span&gt; File.WriteAllText(path,
Regex.Replace(text, &lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;TableAdapter.*?&amp;gt;.*?&amp;lt;/TableAdapter&amp;gt;&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;,
RegexOptions.Singleline));&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h2&gt;The Point
&lt;/h2&gt;
&lt;p&gt;
The point is the first solution, while correct, was more complex than it needed to
be.&amp;#160; Using a little bit of RegEx to wipe clean certain nodes, I get exactly what
I want in three lines of code.&amp;#160; Moral of the story?&amp;#160; &lt;strong&gt;Don't overcomplicate
what doesn't need to be.&lt;/strong&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.timbarcz.com/blog/aggbug.ashx?id=bba271e7-293d-4a55-a9ad-7fb8febd46d3" /&gt;</description>
      <comments>http://www.timbarcz.com/blog/CommentView,guid,bba271e7-293d-4a55-a9ad-7fb8febd46d3.aspx</comments>
      <category>Common Sense</category>
      <category>Musings</category>
      <category>Tips &amp; Tricks</category>
    </item>
  </channel>
</rss>