fipa_acl  1.4
Public Member Functions | List of all members
fipa::acl::XMLMessageParser Class Reference

#include <xml_message_parser.h>

Inherits fipa::acl::MessageParserImplementation.

Public Member Functions

bool parseData (const std::string &storage, ACLMessage &msg)
 
- Public Member Functions inherited from fipa::acl::MessageParserImplementation
virtual ~MessageParserImplementation ()
 

Detailed Description

Definition at line 10 of file xml_message_parser.h.

Member Function Documentation

◆ parseData()

bool fipa::acl::XMLMessageParser::parseData ( const std::string &  storage,
ACLMessage msg 
)
virtual

Reimplemented from fipa::acl::MessageParserImplementation.

Definition at line 11 of file xml_message_parser.cpp.

12 {
13  TiXmlDocument doc;
14 
15  // Load the string into XML doc
16  const char* parseResult = doc.Parse(storage.c_str());
17  // A non-null parseResult usually indicates an error, but we seem to get that every time.
18  if(parseResult != NULL)
19  {
20  // non-null means some error
21  LOG_WARN_S << "Parsing message XML failed for: " << parseResult;
22  }
23 
24  // The main node (fipa-message)
25  const TiXmlElement* messageElem = doc.FirstChildElement();
26 
27  if(messageElem->ValueStr() != "fipa-message")
28  {
29  LOG_WARN_S << "Parsing error: XML main node not named 'fipa-message' but " << messageElem->ValueStr();
30  return false;
31  }
32 
33  // Load communicative act attribute
34  try
35  {
36  msg.setPerformative(messageElem->Attribute("act"));
37  }
38  catch(const std::exception& e)
39  {
40  // This indicates the performative is unknown
41  LOG_WARN_S << "Parsing error performative: " << e.what();
42  return false;
43  }
44 
45  // If the conversation id is here, save it
46  const std::string* convID = messageElem->Attribute(std::string("conversation-id"));
47  if(convID != NULL)
48  {
49  msg.setConversationID(*convID);
50  }
51 
52  // Parse all child elements
53  const TiXmlElement * pChild;
54  for ( pChild = messageElem->FirstChildElement(); pChild != 0; pChild = pChild->NextSiblingElement())
55  {
56  if(!parseParameter(msg, pChild))
57  {
58  return false;
59  }
60  }
61 
62  return true;
63 }

The documentation for this class was generated from the following files: