Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_Libxml2HandlerAdapter.cpp
Go to the documentation of this file.
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_LIBXML2
13 
16 
17 using namespace Teuchos;
18 
19 void xmlSAX2StartElement(void* handler,
20  const xmlChar* name,
21  const xmlChar** attr)
22 {
24 
25  std::string tag = (const char*) name;
27 
28  /* the attribute data is stored in a C array of C strings, in order
29  * {key1, val1, key2, val2, ...}. */
30 
31  for (int i=0; attr[i] != 0; i+=2)
32  {
33  std::string key = (const char*) attr[i];
34  std::string val = (const char*) attr[i+1];
35  attributes[key] = val;
36  }
37 
38  h->startElement(tag, attributes);
39 }
40 
41 void xmlSAX2EndElement(void* handler,
42  const xmlChar* name)
43 {
45 
46  std::string tag = (const char*) name;
47 
48  h->endElement(tag);
49 }
50 
51 void xmlSAX2CharacterData(void* handler,
52  const xmlChar* s,
53  int len)
54 {
55  char* str = new char[len+1];
56  strncpy(str, (const char*) s, len);
57 
58 
59  str[len] = '\0';
60  std::string chars = str;
61 
63  h->characters(chars);
64  delete [] str;
65 }
66 
67 #endif
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.
libxml2 adapter for the TreeBuildingXMLHandler
Templated Parameter List class.
void startElement(const std::string &tag, const Map &attributes)
Receive notification of the start of an element.
TreeBuildingXMLHandler assembles a XMLObject from your XML input.