Friday, April 27, 2007

Simple XML Parsing with PHP 4

Here's a very simple way to parse a small XML file with PHP 4 using the DOMXML module. This approach only makes sense since the file I'm working with is very small.
$qsOption = "";

// Make sure the file exists.
if ( !$dom = domxml_open_file("C:\path\to\file\file.xml") ) {
//echo "Error while parsing the document\n";
// We'll exit quietly instead.
$root = $dom->document_element();
$nodes = $dom->get_elements_by_tagname("topic");
$element = new DomElement();
foreach($nodes as $node)
$element = $node;
$qsOption = $qsOption . "<option value=\"" .
$element->get_attribute("tid") . "\">" .
$element->get_content() . "</option>";

PHP .ini File with IIS on Windows Server 2003

I had to install PHP 4 under IIS on Windows Server 2003. The manual installation went fine, but PHP was looking for the php.ini file in C:\WINDOWS. I already added my install directory, C:\php, to the PATH environment variable and rebooted the machine, but this didn't seem to matter.

Buried on one of the many posts on, I found a suggestion that worked. I had to add the following registry key (Start > Run > regedit)...
...with the string value name IniFilePath and the value c:\php. After I did this, I did a hard stop of IIS and restarted it and the change took fine and saw the proper php.ini file.
C:\>iisreset /stop
C:\>net start w3svc

Thursday, April 12, 2007

JavaScript Link to Nowhere

I am completely incapable of remembering this for the rare times I need it.

<a href="javascript:void(0);">my link to nowhere</a>

Wednesday, April 11, 2007

Updating the Noise Word File in SQL Server 2000

I was trying to update two noise word files in SQL Server 2000 today, but there was a file lock holding on tight. The files were:
  • C:\Program Files\Microsoft SQL Server\MSSQL\FTDATA\SQLServer\Config\noise.dat
  • C:\Program Files\Microsoft SQL Server\MSSQL\FTDATA\SQLServer\Config\noise.eng

I stopped all the SQL Server services and the Indexing Service, but the files were still locked. After a little Googling, I found Unlocker, a very handy tool. This told me that the Microsoft Search service had the lock. I used Unlocker to remove the locks, made my edits, and restared all the services (including Microsoft Search for good measure).

Monday, April 9, 2007

Turn Off DTD Validation When Processing an XML File

I've had two situtions recently where I needed to turn off DTD validation before processing an XML file in a .NET app. The ability to do so is in the class library, but there aren't a lot of examples. Here are two ways using two different objects:
XmlDocument doc = new XmlDocument();
doc.XmlResolver = null;
// or
XmlValidatingReader xmlReader =
new XmlValidatingReader(new XmlTextReader(openFileDialog1.FileName));
xmlReader.ValidationType = ValidationType.None;
In the second example, the user was browsing for an XML file on the network and they requested the ability to use a non-validating file for testing purposes.