Brianary

Web programming news and random musings about web issues and other important stuff.

Monday, February 01, 2010

Converting between XDocument and XmlDocument, XElement and XmlElement

Here's a class to provide extension methods for conversion between System.Xml and System.Xml.Linq classes:

using System.Xml;
using System.Xml.Linq;

/// <summary>
/// Provides extension methods for simple conversion between System.Xml and System.Xml.Linq classes.
/// </summary>
public static class XmlLinqConversionExtensions
{
  /// <summary>
  /// Converts an XDocument to an XmlDocument.
  /// </summary>
  /// <param name="xdoc">The XDocument to convert.</param>
  /// <returns>The equivalent XmlDocument.</returns>
  public static XmlDocument ToXmlDocument(this XDocument xdoc)
  {
    var xmldoc = new XmlDocument();
    xmldoc.Load(xdoc.CreateReader());
    return xmldoc;
  }
  
  /// <summary>
  /// Converts an XmlDocument to an XDocument.
  /// </summary>
  /// <param name="xmldoc">The XmlDocument to convert.</param>
  /// <returns>The equivalent XDocument.</returns>
  public static XDocument ToXDocument(this XmlDocument xmldoc)
  {
    return XDocument.Load(xmldoc.CreateNavigator().ReadSubtree());
  }
  
  /// <summary>
  /// Converts an XElement to an XmlElement.
  /// </summary>
  /// <param name="xelement">The XElement to convert.</param>
  /// <returns>The equivalent XmlElement.</returns>
  public static XmlElement ToXmlElement(this XElement xelement)
  {
    return new XmlDocument().ReadNode(xelement.CreateReader()) as XmlElement;
  }
  
  /// <summary>
  /// Converts an XmlElement to an XElement.
  /// </summary>
  /// <param name="xmlelement">The XmlElement to convert.</param>
  /// <returns>The equivalent XElement.</returns>
  public static XElement ToXElement(this XmlElement xmlelement)
  {
    return XElement.Load(xmlelement.CreateNavigator().ReadSubtree());
  }
}

Tuesday, November 17, 2009

What's in your (Windows) path?

perl -le "@x=split/;/,$ENV{PATHEXT};for(split/;/,$ENV{PATH}){print;next unless chdir$_;print qq'\t'.join(qq'\n\t',map{<*$_>}@x)}"

This one-liner will list all executables currently in your path, so you can decide if maybe you want to trim that path a bit, maybe by transferring a few things to doskey macros.

If you add doskey macros, be sure to add a new string value to HKEY_CURRENT_USER\Software\Microsoft\Command Processor called Autorun with the data C:\WINDOWS\system32\doskey.exe /macrofile=macrofile.

Wednesday, November 11, 2009

Netflix Vista Media Center Plugin: working again

(yay)

Friday, November 06, 2009

Netflix Vista Media Center Plugin Broken. Again.

I wonder if the plugin now only supports the brand-new Windows 7, or if this is just buggy, buggy code. Was this broken by one of the near-daily patches Vista has been insisting on lately? Should I start second-guessing Microsoft patches, in case they downgrade functionality, similar to the way iTunes does?

Without Netflix in VMC, I have to decide whether to go back to Mythbuntu (auto commercial skip and better music playlists) or not. It's a shame after all those reinstalls it took to get the 'mature' Vista OS working. But then again, it'd be nice to be able to print again—my print server, which works fine under Linux, is no longer supported under Vista, so I'm supposed to replace it, even though it works fine. Not to mention that not one of my dozen or so gaming controllers works under Vista (or 7, for that matter).

Thursday, September 10, 2009

My current media center

So I have been forced, against my will, to install Windows on my television PC in order to see the Netflix online content I pay for.

I've fought countless Windows bluescreens in the process of setting this up (more on those in a later post), been frustrated by Windows Update failing and leaving my system in an un-update-able state, and been puzzled by Windows' consistent inability to recognize my network devices on any home computer I've set up in the last decade (I always end up booting into Linux to get the network drivers to spoon-feed to Windows). I even found out that switching the Media Center theme to "high visibility" irrevocably breaks the "Internet TV beta".

I have, however, come up with a decent list of software if you must put Windows on your TV:

  • Windows Media Center (it probably came with your Windows edition)
  • the Netflix plugin for WMC (the logo should be in WMC already, and will link to the download site)
  • Boxee alpha, a neat open-source media center with scores of plug-ins full of content (it's cross-platform if you don't have to use Windows)
  • hulu Desktop, another media center, just for hulu content (hulu hates Boxee for some reason, and must not have signed a multi-million dollar deal to become a Microsoft parner to show up in Media Center by default)
  • Steam, the iTunes of computer games
  • Google Earth just looks very cool on a big TV

Tuesday, August 18, 2009

Highlighting Text or Fields in Windows

How does Windows always incorrectly guess whether I want a field (such as a browser address bar) fully selected when I click it? It must use a similar algorithm to how it incorrectly judges when to suddenly highlight entire words when that is not my intention.

This is what I get for not using the keyboard exclusively, I guess.

Tuesday, August 11, 2009

Why are people still using IE6?

Dean Hachamovitch has an article, IEBlog : Engineering POV: IE6, on the IEBlog, about IE6's continued use. Basically, many IE6 users think it works fine for them, and don't see a reason to upgrade (note to malware authors: these people and IT departments should be easy exploits for some time yet).

Yes, keep "users in control of their PCs" (I assume this means Microsoft will allow me to uninstall their DRM layer in Windows 7?).

This does not mean people should have the expectation that the entire Internet should support Netscape 1.0, Lynx, WebTV 1.0, or MSIE 6. The Internet evolves (as do the security threats). If users want a static environment, they should go pick up a CD-ROM encyclopedia from 1992.

Sure, if a company wants to cater to the IE6 audience, they should spend the time, but I'd bet that someone unwilling or unable to upgrade to a secure web browser isn't as likely to be profitable enough to justify all of the extra work that requires.

I do have to observe that since Microsoft has lived by inertia, the reason IE usage grew for so long, and the reason Windows has utterly dominated for so many years, that it's refreshing to see them cursed by inertia, having to support Windows XP and IE6 for years to come.

Microsoft won't be able to kill XP/IE6 any more than the financial industry has been able to completely kill COBOL.