Archive for January, 2009

The Subtleties of XPath namespacing

Wednesday, January 28th, 2009

Typically when writing xml documents, you would tend to define a default namespace.

However, XPath has no concept of a “default” for namespaces. Instead it looks for the expression in the “null” namespace….something quite different.

<?xml version="1.0" encoding="utf-8"?>
<root xmlns="http://example.com/xml" xmlns:foo="http://example.com/xml/foo">
    <node id="1" />
    <foo:node id="2" />
    <node xmlns="" id="2" />
</root>

What are the distinctions here? There are three above: default namespace, declared namespace (foo:), and the null namespace (the last tag uses a null namespace).

<?xml version="1.0" encoding="utf-8"?>
<root>
    <node id="1" />
    <node id="2" />
    <node id="3" />
</root>

This code above here uses a null namespace for all tags.

XPath statements are reading these nodes with an assumption that all undeclared node names are from the “null namespace”.

Statements like this would work for the 2nd example:

my @nodes = $doc->findnodes('//node');

However, if applied to that first example, you would only get one match (), instead of the expected two (since the obvious non-match would be the tag using the document’s declared namespace.

This breaks down however, you cannot match on default namespace…you need to declare it as well.

You can only access null namespaces or declared namespaces from XPath. You cannot access defined default namespaces (unless it is defined as null).

my @nodes = $doc->findnodes('//foo:node');

Occasionally, this is just too much namespace madness to deal with — the easiest solution is to remove the default namespace from your xml (keep in mind if you’re intermixing xml, then this isn’t a good idea).


#PHP Example assuming the following xml snippet:

<?xml version="1.0" encoding="utf-8"?>
<root xmlns="http://example.com/xml" xmlns:foo="http://example.com/xml/foo">
    <node id="1" />
    <foo:node id="2" />
    <node xmlns="" id="2" />
</root>

...

$doc = new DOMDocument();
$doc->load($xml_filename);
$doc->childNodes->item(0)->removeAttributeNS('http://example.com/xml', '');

# Now you can use XPATH from the null namespace...and named namespace "foo"
# example.xsl

<xsl:template match="root/node">
...# matches first and 3rd node tags.
</xsl:template>

<xsl:template match="//foo:node">
... # matches 2nd node tag: <foo:node>
</xsl:template>

VN:F [1.8.4_1055]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.4_1055]
Rating: 0 (from 0 votes)

Defusing the Data Time-bomb with ODP and OFX

Friday, January 16th, 2009

“Tick-tock, tick-tock”…. As time inches forward, our files become obsolete, deprecated, and replaced by newer file formats. Try opening a file from WordPerfect 5.1 on your computer. How much longer will your office-suite support this antiquated file format?

According to this BBC article, there are many companies and individuals out there that are having a legacy problem with out-dated file format.

There is one solution to this problem that may help converting to newer formats down the road — convert all the media formats on your computer to an open format.

Using ODP files from OpenOffice instead of MS-Office works well on Mac, Linux, and Windows ensuring just about anyone can open a document created as ODP.

I continuously email banks and online financial institutions asking when and if they are ever going to support the OFX format. So far, most banks give me a “canned response” or tell me that I have to enable JavaScript to use their site. Not exactly the answer I was hoping for.

Proprietary audio file formats can be converted or created as OGG Vorbas and video formats as Theora.

VN:F [1.8.4_1055]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.4_1055]
Rating: 0 (from 0 votes)

Tips for Working from Home

Wednesday, January 14th, 2009

I’ve been working at home a portion of my work week for the past 12 years.

Definitely having a sectioned off area at home is the way to go. Preferably with a window you can open for fresh air and sunlight.

I use a time-tracker for Linux that allows you to create tasks and group those tasks by project. The timer sits in the taskbar with easy access to start/start and modify the time spent on a given task and project all together.

I find it great to setup tasks for even the mundane: like reading blogs, emails, etc. Typically I do this when I first start work, taking about 1 hour to go through all my personal emails, latest blogs I follow (most of which are work-related), and get through the planning stage of tasks and emails for the work-day.

After that I diligently track the amount of time spent on tasks…there is a benefit for billing purposes (a necessity when contracting), but is also instrumental in learning how long tasks generally take — every person is different. This helps with the estimation process in future projects as well. And you have reasons when someone says “That should only take you 5 minutes”, when infact its more like 30 minutes to an hour.

I also create subtasks for a feature I’m working: design and architecture (planning), coding (development), and testing (qa). All three of these can add up quick, and it is good to know for yourself and your client that you work at this level or productivity. Billing becomes easier once you are ready to submit a final invoice when consulting.

As for freelance work, I typically try to get 50% of the payment up front for smaller projects (1-2 days). If I’m working on a larger project (weeks or months), I like to work out a standard invoice planning (every 2 weeks or once a month). Keep in mind this can be paid by the client on a NET-30 or even NET-90, which means you may not see a check after invoicing for another 1-3 months. Planning is essential when it comes to floating the period to cover bills yourself.

I like to play music, typically punk or heavy metal when I’m in the code phase, I feel it amps me up and gets me focused with a bit of adrenaline. This is only sustainable for an hour or two, but is a good helper to get that initial development phase moving.

Silence is golden when I’m trying to hash out the framework or design pattern for a project. I will close the door, and ask my family to keep the noise level to a minimum. If that isn’t possible, then going to the local library and using the free wifi access gets me the environment I need when concentration is a priority. Just remember to bring your external mouse; if you’re like me, working on a laptop can cause neck pain and other pain for extended periods of time.

Occassionally I will work on my own personal projects, blog, etc. after dinner, after my wife goes to bed. Around 10pm — I have learned that no matter what, my cutoff time needs to be 2am for this sort of stuff, and only once or twice a week. Never on an evening where I’m working onsite the next day.

I try to start work at 9am when I’m working from home, getting the flexibility from your boss and co-workers that anytime between 8am and 11am is perfectly acceptable. Having a flexible, work-from-home friendly manager makes these concerns trivial.

Also, if you start late, work late. Especially when working fulltime where hourly pay is not a factor. Your employer deserves 4 hours of real work a day (taken from Agile development process where the best teams in the world yield a top of 50% productivity). Its important to re-inforce that you’re more productive at home without the distractions. Even just emailing the team saying that you’re working from home, and if someone asks about it the next day, or volunteer that you worked from home purposefully because you wanted to give the high priority task the attention it deserves without distractions that can occur onsite.

One important aspect of working from home (and onsite as well) is to take breaks. Ideally, with exercise involved. Take 30 minutes to walk around the block or take the dogs to park and toss the ball around for awhile. Sometimes I even walk to park, and nap on the grassy knoll just to get the stress out. It has a huge impact on my productivity when I return refreshed.

If you’re stuck on a task that is giving you problems, perhaps its the case where the solution is easy, but finding it is difficult. Do something completely un-related, empty the dish washer, clean the dog doo in the back yard. I find when I do this, more times than not, the answer pops into my head when I’m not obsessing infront of the screen or banging my head against the wall in search of it.

Working from home has its advantages, as with everything there are two sides to the coin. Communication tends to suffer. Hopefully you’re team has a chatroom available that everyone should be in during the work day. If not Instant Messaging is the next best thing. Great for quick conversations, not so great for long conversations. I find it best to keep the discussions for the days I’m at work, or to pickup a phone. The phone, or skype can save both people time when it comes to not having to type out a 30 minute conversation.

Screen sharing programs can be good for those working remote. A picture is worth a thousand words, and the phone call to accompany it will be nearly as good as pair-programming onsite.

My final rule of thumb? Don’t bite off more than you can chew. If you’re new to something, be forthcoming — “I’ll have to research that before I can give you an estimate”. There’s nothing better than finishing a task earlier, and allowing a little breathing room, versus overbooking and working late to meet a deadline.

  • time trackers ( set project groups, and feature tasks, then stage for each (qa, design, dev)
  • get quiet when quiet is necessary ( go to library, ask family for quiet time, shut door )
  • scope your projects for a daily success rate ( break monstrous tasks into digestable chunks )
  • let your team know that you’ll be out for an hour or two ( and when you’ll be back )
  • don’t be afraid to use the phone or skype
  • idle chatroom for the entire team
  • screen sharing programs for when a 2nd pair of eyes are needed.
VN:F [1.8.4_1055]
Rating: 10.0/10 (1 vote cast)
VN:F [1.8.4_1055]
Rating: +1 (from 1 vote)