<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Brainwipe's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 00:14:51 GMT</pubDate>
    <description>DZone Snippets: Brainwipe's Code Snippets</description>
    <item>
      <title>Using cycling through input variables in PHP using foreach</title>
      <link>http://snippets.dzone.com/posts/show/3699</link>
      <description>This is a simple mechanism for cycling through all the inputs to a PHP script. If you're using $_GET (variables in the query string), $_POST (variables posted with a POST method on a form) or even $_SESSION (variables stored in the session) you can use this technique.&lt;br /&gt;&lt;br /&gt;This snippet prints out all the variables in the $_GET variable (the query string) .&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;foreach ($_GET as $key =&gt; $value)&lt;br /&gt;{&lt;br /&gt;print "$key has a value of $value";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 19 Mar 2007 16:02:20 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3699</guid>
      <author>brainwipe (Rob Lang)</author>
    </item>
    <item>
      <title>Using Rows.Find in ADO.NET</title>
      <link>http://snippets.dzone.com/posts/show/3698</link>
      <description>When using a DataTable in ADO.NET, you may want to search your table given a key. The Find method requires the index of the primary key to find the row that you're looking for. However, before you do this you must set the primary key of the Datatable. Setting the primary key in your database is not enough. To set the primary key, create a new column and then set the primary key field on the Datatable like so:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;br /&gt;// Create the DataColumn list for holding the columns of the primary keys. In this case, we are using only one primary key&lt;br /&gt;DataColumn[] primaryKeyColumns = new DataColumn[1];&lt;br /&gt;&lt;br /&gt;// Set the first primary key to the column 'id' in the datatable&lt;br /&gt;primaryKeyColumns[0] = myDataTable.Columns["id"];&lt;br /&gt;&lt;br /&gt;// Now apply the primary key to the datatable&lt;br /&gt;myDataTable.PrimaryKey = primaryKeyColumns;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 19 Mar 2007 16:01:02 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3698</guid>
      <author>brainwipe (Rob Lang)</author>
    </item>
    <item>
      <title>Moving nodes from one XmlDocument to another</title>
      <link>http://snippets.dzone.com/posts/show/3697</link>
      <description>In .NET has some powerful tools to deal with Xml. All Xml nodes need to be created in the context of a XmlDocument object. If you need to move the nodes from one Xml Document to another, it's not obvious that you can just copy the nodes from one XmlDocument to another, after all Xml is just text isn't it.&lt;br /&gt;&lt;br /&gt;Here's how to move all the nodes from one Xml Document to another:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;// Dont forget this one:&lt;br /&gt;using System.Xml;&lt;br /&gt;&lt;br /&gt;// First, get some documents together&lt;br /&gt;XmlDocument DocumentSource = new XmlDocument();&lt;br /&gt;XmlDocument DocumentDestination = new XmlDocument();&lt;br /&gt;&lt;br /&gt;// Load the documents with some nodes&lt;br /&gt;DocumentSource.LoadXml("");&lt;br /&gt;DocumentDestination.LoadXml("");&lt;br /&gt;&lt;br /&gt;// Now to do the conversion&lt;br /&gt;XmlNode tempNode = DocumentDestination.ImportNode( DocumentSource.FirstChild )&lt;br /&gt;&lt;br /&gt;// Now insert the fragment into the document&lt;br /&gt;DocumentDestination.FirsChild.AppendChild(tempNode);&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 19 Mar 2007 15:59:19 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3697</guid>
      <author>brainwipe (Rob Lang)</author>
    </item>
    <item>
      <title>From DataSet to XmlDocument</title>
      <link>http://snippets.dzone.com/posts/show/3696</link>
      <description>Ever had to take a DataSet from the database and turn it into an Xml Document in .NET? The process is a little messy because there is no direct conversion method. This is because Xml is streamed from the DataSet but the XmlDocument needs a string to load from. Here's my solution:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt; // This is the final document&lt;br /&gt;XmlDocument Data = new XmlDocument();&lt;br /&gt;&lt;br /&gt;// Create a string writer that will write the Xml to a string&lt;br /&gt;StringWriter stringWriter = new StringWriter();&lt;br /&gt;&lt;br /&gt;// The Xml Text writer acts as a bridge between the xml stream and the text stream&lt;br /&gt;XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);&lt;br /&gt;&lt;br /&gt;// Now take the Dataset and extract the Xml from it, it will write to the string writer&lt;br /&gt;content.WriteXml(xmlTextWriter, XmlWriteMode.IgnoreSchema);&lt;br /&gt;&lt;br /&gt;// Write the Xml out to a string&lt;br /&gt;string contentAsXmlString = stringWriter.ToString();&lt;br /&gt;&lt;br /&gt;// load the string of Xml into the document&lt;br /&gt;Data.LoadXml(contentAsXmlString);&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 19 Mar 2007 15:58:12 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3696</guid>
      <author>brainwipe (Rob Lang)</author>
    </item>
    <item>
      <title>From XmlDocument to XPath Document</title>
      <link>http://snippets.dzone.com/posts/show/3695</link>
      <description>It's not obvious how you might turn your standard XmlDocument into an XPathDocument as there is no direct method to do so. The best way is to make use of a reader for the conversion:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;XPathDocument xpathDoc = new XPathDocument (new XmlNodeReader(doc));&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 19 Mar 2007 15:57:33 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3695</guid>
      <author>brainwipe (Rob Lang)</author>
    </item>
  </channel>
</rss>
