Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_ExpatHandlerAdapter.cpp
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
11 
12 #ifdef HAVE_TEUCHOS_EXPAT
13 
15 
16 using namespace Teuchos;
17 
18 void expatStartElementHandler(void* handler,
19  const XML_Char* name,
20  const XML_Char** attr)
21 {
23 
24  std::string tag = name;
26 
27  /* the attribute data is stored in a C array of C strings, in order
28  * {key1, val1, key2, val2, ...}. */
29 
30  for (int i=0; attr[i] != 0; i+=2)
31  {
32  std::string key = attr[i];
33  std::string val = attr[i+1];
34  attributes[key] = val;
35  }
36 
37  h->startElement(tag, attributes);
38 }
39 
40 void expatEndElementHandler(void* handler,
41  const XML_Char* name)
42 {
44 
45  std::string tag = name;
46 
47  h->endElement(tag);
48 }
49 
50 void expatCharacterDataHandler(void* handler,
51  const XML_Char* s,
52  int len)
53 {
54  char* str = new char[len+1];
55  strncpy(str, s, len);
56 
57 
58  str[len] = '\0';
59  std::string chars = str;
60 
62  h->characters(chars);
63  delete [] str;
64 }
65 
66 #endif // HAVE_TEUCHOS_EXPAT
void characters(const std::string &chars)
Process character data.
Defines a class for assembling an XMLObject from XML input.
int endElement(const std::string &tag)
Receive notification of the end of an element.
void startElement(const std::string &tag, const Map &attributes)
Receive notification of the start of an element.
Expat adapter for the TreeBuildingXMLHandler.
TreeBuildingXMLHandler assembles a XMLObject from your XML input.