WURFL Patch Files

Applying you local fixes to the WURFL repository

The idea behind WURFL is that you get a newer version of the WURFL file as more accurate information becomes available and is added to the WURFL file.
Assuming you have licensed the WURFL repository commercially or are using a pre-2.2 version of the WURFL repository, you can theoretically modify your own private wurfl.xml copy to keep track of updates.
This operation, though, is not recommended. In addition to being error-prone and hard to manage, merging the updates with newer versions of the WURFL repository is not simple.
The introduction of the support for WURFL 'patch file' helps with this. Developers can add a 'wurfl_patch.xml' file to their system, which stores modified/enhanced groups and capability lists for new or existing WURFL devices.
When the WURFL is parsed, the patch file is also imported to build a modified version of the device database.

When to use the patch
There may be different reasons why one wishes to use a patch file. Here are some (there may be others):

What does the patch file look like?
The patchfile is very similar to the WURFL itself (but hopefully much shorter!). Bialetti is an Italian coffee-maker manufacturer. I'll add coffee-maker support for the WURFL with a patch:

wurfl_patch.xml

<wurfl_patch>
  <devices>
    <device user_agent="" fall_back="root" id="generic">
      <group id="magical_powers">
         <capability name="makes_good_coffee" value="false" />
         <capability name="average_coffee_preparation_time"
                   value="0" />
      </group>
      <group id="display">
	<capability name="resolution_height" value="200"/>
	<capability name="lucas_capa"
                   value="0"/>
      </group>
      <group id="new_group">
	<capability name="new_capa1"
                value="false"/>
	<capability name="new_capa2"
                value="0"/>
      </group>
      </device>
    <device user_agent="Nokia 20" fall_back="generic"
             id="nokia_generic_series20">
      <group id="new_group">
	<capability name="new_capa1" value="true"/>
	<capability name="new_capa2" value="34832798"/>
      </group>
      <group id="display">
	<capability name="resolution_height" value="3300"/>
      </group>
    </device>

    <!-- Adding a Coffeee Pot to the WURFL -->
    <device id="bialetti_ver61" user_agent="Bialetti 6.1"
           fall_back="generic">

      <group id="magical_powers">
         <capability name="makes_good_coffee"
            value="true" />
         <capability name="average_coffee_preparation_time"
            value="5" />
      </group>
      <group id="display">
	<capability name="resolution_width" value="190"/>
	<capability name="resolution_height" value="140"/>
	<capability name="lucas_capa" value="34832798"/>
      </group>
    </device>
  </devices>
</wurfl_patch>

There are a few things to observe about the patch file:

Example:
Let's assume we have a wurfl_patch.xml file like the one above and a mini wurfl.xml file like the one which follows:

<?xml version="1.0" encoding="UTF-8" ?> <wurfl>
 <devices>
  <device fall_back="root" id="generic" user_agent="">
   <group id="wml_ui">
    <capability name="access_key_support" value="false" />
     <capability name="wrap_mode_support" value="false" />
    </group>
   <group id="display">
    <capability name="resolution_width" value="90" />
     <capability name="resolution_height" value="40" />
    </group>
  </device>
  <device user_agent="Nokia 20" fall_back="generic"
         id="nokia_generic_series20">
   <group id="display">
    <capability name="resolution_width" value="260" />
     <capability name="resolution_height" value="440" />
    </group>
  </device>
  <device user_agent="Nokia 30" fall_back="nokia_generic_series20" 
             id="nokia_generic_series30">
   <group id="wml_ui">
    <capability name="access_key_support" value="true" />
    </group>
   <group id="display">

    <capability name="resolution_width" value="96" />
     <capability name="resolution_height" value="65" />
    </group>
  </device>
  <device user_agent="Nokia 40" fall_back="nokia_generic_series30" 
             id="nokia_generic_series40">
   <group id="display">
    <capability name="resolution_width" value="128" />
     <capability name="resolution_height" value="128" />
    </group>
  </device>
  <device user_agent="Nokia 60" fall_back="nokia_generic_series40" 
             id="nokia_generic_series60">
   <group id="wml_ui">
    <capability name="access_key_support" value="false" />
    </group>
  </device>
 </devices>
</wurfl>

The merged patch file (i.e. wurfl.xml patched with wurfl_patch.xml)
will be equivalent to this:

<?xml version="1.0" encoding="UTF-8"?>
<wurfl>

  <devices>
    <device fall_back="root" id="generic" user_agent="">
      <group id="wml_ui">
        <capability name="access_key_support" value="false"/>
        <capability name="wrap_mode_support" value="false"/>
      </group>
      <group id="display">
        <capability name="resolution_width" value="90"/>
        <capability name="resolution_height" value="200"/>
        <capability name="lucas_capa" value="0"/>
      </group>
      <group id="magical_powers">
        <capability name="makes_good_coffee" value="false"/>
        <capability name="average_coffee_preparation_time" value="0"/>
      </group>
      <group id="new_group">
        <capability name="new_capa1" value="false"/>
        <capability name="new_capa2" value="0"/>
      </group>
    </device>
    <device user_agent="Nokia 20" fall_back="generic"
          id="nokia_generic_series20">
      <group id="display">
        <capability name="resolution_width" value="260"/>
        <capability name="resolution_height" value="3300"/>
      </group>
      <group id="new_group">
        <capability name="new_capa1" value="true"/>
        <capability name="new_capa2" value="34832798"/>
      </group>
    </device>
    <device user_agent="Nokia 30"
               fall_back="nokia_generic_series20" 
               id="nokia_generic_series30">
      <group id="wml_ui">
        <capability name="access_key_support" value="true"/>
      </group>
      <group id="display">
        <capability name="resolution_width" value="96"/>
        <capability name="resolution_height" value="65"/>
      </group>
    </device>
    <device user_agent="Nokia 40"
               fall_back="nokia_generic_series30" 
               id="nokia_generic_series40">
      <group id="display">
        <capability name="resolution_width" value="128"/>
        <capability name="resolution_height" value="128"/>
      </group>
    </device>
    <device user_agent="Nokia 60"
               fall_back="nokia_generic_series40" 
               id="nokia_generic_series60">
      <group id="wml_ui">
        <capability name="access_key_support" value="false"/>
      </group>
    </device>
    <device id="bialetti_ver61" user_agent="Bialetti 6.1"
          fall_back="generic">
      <group id="magical_powers">
        <capability name="makes_good_coffee" value="true"/>
        <capability name="average_coffee_preparation_time"
          value="5"/>
      </group>
      <group id="display">
        <capability name="resolution_width" value="190"/>
        <capability name="resolution_height" value="140"/>
        <capability name="lucas_capa" value="34832798"/>
      </group>
    </device>
  </devices> 
</wurfl>