KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Our C++ application reads configuration data from XML files that look something like this: <data> <value id="FOO1" name="foo1" size="10" description="the foo" .../> <value id="FOO2" name="foo2" size="10" description="the other foo" .../> ... <value id="FOO300" name="foo300" size="10" description="the last foo" .../> </data> The complete application configuration consist of ~2500 of these XML files (which translates into more than 1.5 million key/value attribute pairs). The XML files come from many different sources/teams and are validated against a schema. However, sometimes the <value/> nodes look like this: <value name="bar1" id="BAR1" description="the bar" size="20" ... /> or this: <value id="BAT1" description="the bat" name="bat1" size="25" ... /> To make this process fast, we are using Expat to parse the XML documents. Expat exposes the attributes as an array - like this: void ExpatParser::StartElement(const XML_Char* name, const XML_Char** atts) { // The attributes are stored in an array of XML_Char* where: // the nth element is the 'key' // the n+1 element is the value // the final element is NULL for (int i = 0; atts[i]; i += 2) { std::string key = atts[i]; std::string value = atts[i + 1]; ProcessAttribute (key, value); } } This puts all the responsibility onto our ProcessAttribute() function to read the 'key' an
Tags (comma-separated)
Save Edits
Cancel