You are here

Archive for No name

Pseudocode for Item object

  1. class Item {
  2.     int id;                     /* id */
Source code: 

XML Parser: Statement of Problem


World of Warcraft is an enormously popular MMORPG. Recently, Blizzard Entertainment announced that they had surpassed 11.5 million subscribers worldwide.

One of the many services offered by Blizzard Entertainment is the Armory which allows players to view their characters and others online. Items are also searchable through a recent update. All of the dynamic content (characters and items) are served as XML content which is then passed through XSL stylesheets to present the HTML content. This allows those who have the interest to query the Armory for the XML representation of an item or a character and then parse it locally.


Write an XML parser that processes an item's XML data and generates a data representation of that item.

Implementation Details

The XML data is stored in files with one paragraph per file.

The parser function should accept a single parameter, a filename, and return the expected object.

Elements that contain data as references not in the XML paragraphs can be left in the format present in the elements. The damageData element and the current attribute of the durability element may be ignored.

Implementations do not need to be object-oriented.


Four items have been randomly selected as test data:

  • 41660: Deadly Gladiator's Dragonhide Robes
  • 40503: Valorous Cryptstalker Tunic
  • 40526: Gown of the Spell-Weaver
  • 44006: Obsidian Greathelm

This data is by no means representative of what would need to be done to fully implement a parser for all equippable items in World of Warcraft. However, for the purpose of this exercise, it will suffice.

Based on the XML paragraphs, a generated item should have the following basic structure (expressed in "pseudo-Java"):

  1. class Item {
  2.     int id;                     /* id */
  3.     String name;                /* name */
  4.     String icon;                /* icon */
  5.     int quality;                /* overallQualityId */
  7.     int bonding;                /* bonding */
  8.     int classId;                /* classId */
  9.     int equipInventoryType;     /* equipData/inventoryType */
  10.     String equipSubclass;       /* equipData/subclassName */
  12.     int strength;               /* bonusStrength */
  13.     int agility;                /* bonusAgility */
  14.     int stamina;                /* bonusStamina */
  15.     int intellect;              /* bonusIntellect */
  16.     int spirit;                 /* bonusSpirit */
  17.     int armor;                  /* armor */
  18.     int addedArmor;             /* armor[armorBonus] */
  19.     String[] sockets;           /* one per socketData/socket */
  21.     int maxDurability;          /* durability[max] */
  22.     String[] allowedClasses;    /* one per allowableClasses/class */
  23.     int requiredLevel;          /* requiredLevel */
  24.     int attackPower;            /* bonusAttackPower */
  25.     int critRating;             /* bonusCritRating */
  26.     int expertiseRating;        /* bonusExpertiseRating */
  27.     int hasteRating;            /* bonusHasteRating */
  28.     int hitRating;              /* bonusHitRating */
  29.     int spellpower;             /* bonusSpellPower */
  30.     int resilience;             /* bonusResilience */
  32.     Spells[] spells;            /* one per spellData/spell */
  34.     ItemSet itemSet;            /* setData */
  35.     ItemSource source;          /* source */
  36. }
  38. class Spell {
  39.     int trigger;                /* trigger */
  40.     String desc;                /* desc */
  41. }
  43. class ItemSet {
  44.     String name;                /* name */
  45.     String[] items;             /* one per item */
  46.     Map<int, String> bonuses;   /* setBonus[ threshold ], setBonus[ desc ] */
  47. }
  50. class ItemSource {
  51.     String sourceType;          /* [value] */
  53.     /* These are only defined when sourceType == "sourceType.creatureDrop" */
  54.     int areaId;                 /* [areaId] */
  55.     String areaName;            /* [areaName] */
  56.     int creatureId;             /* [creatureId] */
  57.     String creatureName;        /* [creatureName] */
  58.     String difficulty;          /* [difficulty] */
  59.     int dropRate;               /* [dropRate] */
  60. }

If not specified by the XML data:

  • All integer values should return 0.
  • All strings should return null or the appropriate language equivalent thereof.
  • All arrays should be empty.

The returned data representations should match the above access terms unless language convention dictates otherwise. (For example, in a Java implementation, the methods would use the standard get... names, e.g. getStrength() in place of strength.)


  1. Clarified how the XML is stored. (2009/01/14)
  2. Removed object-oriented-specific terminology. (2009/01/14)
  3. Changed requirement on the value of unspecified arrays. (2009/01/14)
  4. Changed requirement on the durability element. (2009/01/25)

Implementations: Introduction

While trying to decide how to approach a given project a few weeks ago, I had the choice of using one of several programming languages. This prompted me to look around for ideas of what other people had said comparing languages.

In my opinion, the best comparison I found was David Howard's essay C++ vs Java vs Python vs Ruby : a first impression. While mostly devoid of bias, what really won me over was the ability to compare the implementations of his example matter, a "Red-Black tree algorithm."

Fortunately, for me, the project I was working on did not need anything spectacular for a user interface or deployment. However, most "real" projects are limited by some requirement based around usage or target audience. Writing custom web applications is usually limited by the abilities of the target webserver. Writing applications for deployment on desktop machines is limited by the support for the target OS and its GUI in the programming language or libraries. Writing applications for deployment on a security-audited machine can require the application only being able to use what is already installed.

Since I do not plan to be limited to a particular platform, application, etc. in the future, I find it behooves me to learn how to implement tasks (some "real-world", some "toy") in various languages (and, in some instances, various libraries within the languages). Each implementation will have its own article and will be written with my thoughts as I go. (Or that's the intention anyway.)

By posting what I come up with publicly, I hope to help others looking to fulfill these tasks and I hope to get people more knowledgeable than I to comment on what I've done wrong.

XML parser sample 4 (44006.xml)

Source code: 

XML parser sample 3 (40526.xml)

Source code: 

XML parser sample 2 (40503.xml)

Source code: 

XML parser sample 1 (41660.xml)

Source code: