Monday, February 26, 2007

phpMyAdmin and the "Client does not support authentication" Error

When you see the following error...
#1251 - Client does not support authentication protocol requested by server; consider upgrading MySQL client
...there is a problem with the password you created for a user. You'll need to run...
mysql> SET PASSWORD FOR 'username'@'host' = OLD_PASSWORD('password');
See http://dev.mysql.com/doc/refman/5.0/en/old-client.html for more information.

Friday, February 23, 2007

Firefox and Internet Explorer Development Tools

I always lose this, so here's the list of Firefox extensions I'm using
  • DOM Inspector
  • Firebug
  • Flashblock
  • Header Monitor
  • Live HTTP Headers
  • Web Developer
  • XML Developer Toolbar

On Internet Explorer, I have the IE Developer Toolbar

Tuesday, February 20, 2007

View Results from the Textml QueryAnalyzer Object

I wasn't sure if I had an error in my code or if I uncovered a bug in Textml's QueryAnalyzer, so I wrote a little ASP.NET page where I could pass in a search string and see what QueryAnalyzer would do with it. This is how I found the bug with their .NET implementation of the choice operator.

Here are the ASPX and C# files
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="QueryAnalyzer.aspx.cs"
Inherits="QueryAnalyzer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>QueryAnalyzer Test Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="txtQuery" runat="server"></asp:TextBox>
<asp:Button ID="btnRun" runat="server" Text="Run" /><br />
<div id="divQuery" runat="server"></div>
<div id="divError" runat="server"></div>
</form>
</body>
</html>

--

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Ixiasoft.TextmlServer;
using Ixiasoft.TextmlServer.Tools;

public partial class QueryAnalyzer : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
divError.InnerHtml = "";
divQuery.InnerHtml = "";
IxiaQueryAnalyzer TextmlQueryAnalyzer = new IxiaQueryAnalyzer();
try
{
string queryEdited =
TextmlQueryAnalyzer.GetXMLQueryString(txtQuery.Text, "words");
divQuery.InnerHtml = HttpUtility.HtmlEncode(queryEdited);
}
catch (Exception ex)
{
divError.InnerHtml += "<br />" + ex.ToString() +
"<br />" + ex.StackTrace.ToString() +
"<br />Passed to QueryAnalyzer: " +
HttpUtility.HtmlEncode(txtQuery.Text);
}
}
}
}

Wednesday, February 14, 2007

Searching Textml for Words with Tildes

Document searches in Textml are insensitive to case and ... in most cases ... special characters. For example, searches for "José Martí" and "jose marti" should return the same results set in the same order. But there is at least one exception to this, ñ. A search for "quinceañera" will return a different set of results when compared to "quinceanera." Ixiasoft has reported this is a feature based on requests from their Spanish-speaking partners and customers, which make sense because the two are different characters in the Spanish alphabet.

One solution is to add a hidden element to the document that contains the alternate spelling.

Another solution is to use the <oneof> element. To do this you would intercept each word at the application level and modify words with "ñ" or "n." That part of the query might look something like this:
<elem>quincea<oneof><choice>ñ</choice><choice>n</choice></oneof>era</elem>
If you have to support this particular feature, neither solution is very palatable.

UPDATE 1: If you try and pass the choice operator to the Textml QueryAnalyzer object in .NET, it will throw an exception. quincea[n,ñ]era as a search string will fail. I've submitted this bug to Ixiasoft and I'm waiting for a response.

UPDATE 2: Ixiasoft has responded that this is a bug and is due to be released in their newest package, 3.6.1.1542.

Sunday, February 11, 2007

Determine the Encoding of an XML File: Method 1

In Visual Studio 2003, I needed a way to determine the encoding of an XML file. I found some information about reading the byte order mark (BOM) on a file, but I couldn't get it to work properly. The alternative approach below seems to be working. In this example, I needed the file to be UTF-8.
String encoding = DetectEncodingXml(); 
if(encoding.IndexOf("UTF-8") > -1)
{
/* This is what we want. Run the code. */
}
else
{
/* Display error message. */
}
private string DetectEncodingXml()
{
try
{
XmlTextReader xreader = new XmlTextReader(openFileDialog.FileName);
xreader.Read();
Encoding xreaderEnc = xreader.Encoding;
string xreaderEncString = xreaderEnc.EncodingName;
return xreaderEncString;
}
catch(Exception ex)
{
return " Encoding could not be detected. ";
}
}

Friday, February 9, 2007

Getting the ASPX File Name

I only used this once, and quickly changed my approach so I didn't need to rely on it, but here's how you can get the name of the ASPX file you're viewing.
string pageName = this.Page.GetType().Name.Replace("_", ".");
Of course, there's also
Request.ServerVariables["SCRIPT_NAME"]
and
HttpContext.Current.Request.Path
and
System.IO.Path.GetFileNameWithoutExtension(Request.FilePath)

Transforming XML with XSL: Method 1

There are several ways to transform an XML document with XSL. This is one approach that includes passing parameters to the XSL and assumes the transformation is targeted for a <div> element. You'll need the following namespaces added, assuming this is an ASP.NET website: System.IO, System.Xml.Xsl, System.Xml.XPath. This should be wrapped in a try/catch block.
XPathDocument xpathDocument = new XPathDocument(this.Server.MapPath("/xml/test.xml"));
XslCompiledTransform xpathTransform = new XslCompiledTransform();
StringWriter xpathWriter = new StringWriter();
XsltArgumentList xslArg = new XsltArgumentList();
xpathTransform.Load(this.Server.MapPath("/xsl/toText.xsl"));
xslArg.AddParam("path", "", imgPath); /* imgPath defined elsewhere */
xslArg.AddParam("country", "", country); /* country defined elsewhere */
xpathTransform.Transform(xpathDocument, xslArg, xpathWriter);
divXml.InnerHtml = xpathWriter.ToString(); /* divXml is a control on the ASPX page */


UPDATE: Why would you need this approach versus using the Xml control? I ran into a situation where some legacy XSL used the document() function and called a file on the network. I needed to 1) use impersonation and 2) set XmlSetting when I called Load().

Tuesday, February 6, 2007

Set Selected DropDownList Item By Value

Given an ASP.NET DropDownList control and a value, you can set the selected item in that list if the value exists. There are a couple of ways to do this, but this approach takes into consideration that the value may not be found in the list.

This is an example of what you could have on an ASPX page:
<asp:DropDownList ID="ddlDb" runat="server">
<asp:ListItem Value="all" Selected="True">All</asp:ListItem>
<asp:ListItem Value="opt1">Option One</asp:ListItem>
<asp:ListItem Value="opt2">Option Two</asp:ListItem>
</asp:DropDownList>
This is an example of how to set the selected item:
ListItem li = ddlDb.Items.FindByValue("opt1");
if (li != null) ddlDb.SelectedIndex = ddlDb.Items.IndexOf(li);
Another method is below, but it will throw System.ArgumentOutOfRangeException if the value is not found:
ddlDb.SelectedValue = "opt1";

Sunday, February 4, 2007

Random Table Background Image

This was a quick hack for a friend to get a random background image set for a table. You should be able to add this just about anywhere in the <body> tag. This would also work just for a table cell.

<script language="javascript">
<!--
onload = function() {
/* If you change the directory, make sure you update it here. */
var imageDirectory = "http://www.yourwebsite.com/images/";
/* If you want to add more images on your own, put the the file name in the middle
of the list here. Make sure there are quotes around it and a comma at the end. */
var imageArray = new Array("image3.gif",
"image6.gif",
"image1.gif",
"image4.gif",
"image2.gif",
"image5.gif");
var imageArrayLength = imageArray.length; // Leave these next few lines alone
var pseudoRandomNumber = ( Math.round( Math.random() * (imageArrayLength - 1) ) );
document.getElementById("tableImage").style.backgroundImage="url('" +
"imageDirectory + imageArray[pseudoRandomNumber] + "')";
}
//-->
</script>
<noscript>
<style type="text/css">
#tableImage {
background-image:url('http://www.yourwebsite.com/images/image3.gif');
}
</style>
</noscript>

<table id="tableImage" height="431" width="465">
<tr><td> </td></tr>
</table>

UPDATE: This is OLD. You should look for a better solution.