XML : Xerces XML parser, converting XMLCh* to float

I'm trying to read an XML string over a socket and parse it with the Xerces parser, but I'm having an issue with some of the values. It's strange because what I have done has worked at other points in the code, but it's not working when I've tried to reuse the logic in another place. Here's basically what I have done:

  void Parser::ParseAB(DOMNode* node)  {      const XMLCh* aNode = XMLString::transcode("a");      const XMLCh* bNode = XMLString::transcode("b");      DOMNode* child = node->getFirstChild();      XMLCh *val, *childName;      char* charValue;      double aVal, bVal;        while(child)      {          childName = (XMLCh*)child->getNodeName();          val = (XMLCh*)child->getTextContent();          charValue = (char*)val;          if(XMLString::equals(childName, aNode))          {              aVal = atof((const char*)val);          }else if(XMLString::equals(childName, bNode))          {              bValue = atof((const char*)val);          }else std::cout<<"Unrecognized option\n";          child = child->getNextSibling();      }      m_pInfo->setAB(aVal, bVal);    }    

I've been debugging the code in NetBeans 8.0.1, and when I mouse over "val" to check it's contents before it is stored in aVal, I see 0x600416920 L"33.456030344". This looks fine to me because 33.456030344 is the correct value that I'm trying to store. However, the call to atof() produces the value 3, which is clearly incorrect. If I convert the XMLCh* to char* and print the char* value, I also get 3. Similarly the value of bVal should be -31.32234, but the call to atof is returning a value of zero. When I convert this XMLCh* to a char* and print the char*, only the negative sign is printed. It seems to me that only the first character is being converted to a float, or something like that. This same logic has worked in numerous places in my code, and I'm not seeing why it won't work here. Is there some other way that I should go about converting the XMLCh* val to a floating point number with the correct value?

No comments:

Post a Comment