Exemplo n.º 1
0
bool
XMLIndata::parseName( const DOMNode* name,
                      NameCollection& names ) 
{
   if ( XMLString::equals( name->getNodeName(), "name" ) ) {
      
      // Get attributes
      DOMNamedNodeMap* attributes = name->getAttributes();

      LangTypes::language_t lang;
      ItemTypes::name_t nameType;
      
      // Note that language attribute is #REQUIRED.
      DOMNode* attribute = 
         attributes->getNamedItem( X( "language" ) );
      MC2_ASSERT( attribute != NULL );
      MC2String langStr = 
         XMLUtility::transcodefromucs(attribute->getNodeValue() );
      // Replace any occurance of '_' with space.
      for (MC2String::iterator strIt = langStr.begin();
           strIt != langStr.end(); ++strIt){
         if ( *strIt == '_' ){
            *strIt = ' ';
         }
      }

      lang = LangTypes::getStringAsLanguage( langStr.c_str(), true );
      if ( lang == LangTypes::invalidLanguage ){
         mc2log << error << "Could not interpret language code of string"
                << endl;
         MC2_ASSERT(false);
      }

      // Note that type attribute is always present.
      attribute = 
         attributes->getNamedItem( X( "type" ) );
      MC2_ASSERT( attribute != NULL );
      const char* tmpStr = XMLUtility::transcodefromucs(
            attribute->getNodeValue() );
      nameType = ItemTypes::getStringAsNameType( tmpStr );
      delete [] tmpStr;

      // Get the name.
      tmpStr = XMLUtility::getChildTextValue( name );
      
      // Add name
      Name* tmpName = new Name( tmpStr, lang, nameType );
      names.addName( tmpName );
      mc2dbg << "Added name: " << (*tmpName) << endl;
      mc2dbg8 << "All names: " << names << endl;
      delete tmpStr;

      return true;
   } else {
      // Not a name node.
      mc2log << warn 
             << "XMLIndata::parseName:"
             << " not a name node."
             << name->getNodeName() << endl;
      return false;
   }
}