XMLDom::Save() Permission Problem

I had been hitting my head against the wall when I couldn’t get an edited XML file to save due to file permissions, even though I know that it was OK.

For some odd reason, when I went to save the XML file, it would try to write the file to the root directory, instead of the current working directory (where the file is read from).

As such, using realpath() to keep the complete system path to the XML file when you load it will make sure that DOM isn’t trying to save to the incorrect directory:

$myfile = 'myxml.xml';
$myfile = realpath($myfile);
$doc = new DOMDocument('1.0');

// Let's just add a couple of elements for good measure
$root = $doc->documentElement;

$title = $doc->createElement('title');
$title = $root->appendChild($title);

$text = $doc->createTextNode('This is a title');
$text = $title->appendChild($text);


Getting the HP 2400c Scanner working in Linux Ubuntu Karmic

I had a tough day working on Ubuntu to get a HP 2400c Scanner working today.

A list of problems included the drivers not being included in the Sane package – and after an upgrade to karmic a normal user couldn’t access the USB device.

Here’s a quick rundown of what I did to get it working.

1 – Download the HP scanner drivers from Elcot
2 – Install the drivers as root. The instructions are in the readme file.
3 – Create a new udev rule by creating the file /lib/udev/rules.d/71-scanner.rules
4 – In the rules file, paste in the following code:

#HP ScanJet 2400c
ACTION=="add", ATTRS{idVendor}=="03f0", ATTRS{idProduct}=="0a01", GROUP="scanner"

5 – Add the user to the scanners group.
6 – Run Sane or Xsane and be happy!

There was a bit of groping around as I hadn’t created my own udev file before without following the instructions or howtos for specific hardware.

The key point to know is that there are some very useful commands:
lsusb – lists info about the usb devices plugged in
udevadm monitor – outputs udev events and shows you the device paths for any devices plugged in / removed
udevadm info –query=all –path /devpath – Shows the udev properties of a specific device
udevadm info –attribute-walk –path /devpath – Shows the udev properties of a device and its parents
* devpath is the path output from udevadm monitor

Once I’d worked my head around these, I could put together the .rules file that I needed. This basically checks the vendor and device ID match, and that it is an ‘ADD’ action. Once confirmed, udev adds the group membership of the device to ‘scanner’ so that the users you want to use the scanner can actually use it!