Interview Questions

189. You are developing a component that requries parsing a lot of XML tags ......

Microsoft Interview Questions and Answers


(Continued from previous question...)

189. You are developing a component that requries parsing a lot of XML tags ......

Question:
You are developing a component that requries parsing a lot of XML tags. You have abstracted the responsibility of finding the handler to a class named XMLElement Dictionary. Your will be invoking GetHandlerTag method of this class to find the corresponding handler method for a given element name (code snippet is shown below).

Typedef HRESULT(*PFNElementHandler)(IXMLAttribute* pAttributes, unsigned_int32nAttributes);

PFNElementHandler pfnElementHandler =( PFNElementHandler)
xmlElementDictionary.GetHandlerTag(elementName);
if(NULL!=pfnElementHandler)
{
(*pfnElementHandler)(pAttributes, nAttributes);
}

1. Define a datastructure that you will use inside this class to store the XML tags that you can use in your lookup logic for the fastest possible lookup on a given hardware. Call out your assumptions.
2. Implement the GetHandlerTag method.



maybe an answer:


each entry in lookup table:

#define MAX_NAME_LEN 256
typedef struct {
char tagname[MAX_NAME_LEN];
PFNElementHandler tagHandler;
} lookup_entry_t;


lookup_entry_t lookup_table[NUM_TAGS]; /* number of tags is known at compile time */

Use a hash function to hash(tagname) % NUM_TAGS and initialize its entry in the lookup_table with the handler.

(Continued on next question...)

Other Interview Questions