QMCPACK
XMLParsingString.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2021 QMCPACK developers.
6 //
7 // File developed by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
8 // Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
9 //
10 // File refactored from: XMLParsingString.hpp
11 //////////////////////////////////////////////////////////////////////////////////////
12 
13 
14 /** @file
15  */
16 #include "XMLParsingString.h"
17 #include "libxmldefs.h"
18 
19 std::string getXMLAttributeValue(const xmlNodePtr cur, const std::string_view name)
20 {
21  std::string attr_value;
22  xmlChar* attr_char = xmlGetProp(cur, castCharToXMLChar(name.data()));
23  if (attr_char)
24  {
25  attr_value.assign(castXMLCharToChar(attr_char));
26  xmlFree(attr_char);
27  }
28  return attr_value;
29 }
A collection of put/get functions to read from or write to a xmlNode defined in libxml2.
XMLNodeString convert xmlNode contents into a std::string XMLAttrString convert one xmlNode attribute...
char * castXMLCharToChar(xmlChar *c)
assign a value from a node. Use specialization for classes.
Definition: libxmldefs.h:62
std::string getXMLAttributeValue(const xmlNodePtr cur, const std::string_view name)
get the value string for attribute name if name is unfound in cur you get an empty string back this i...
xmlChar * castCharToXMLChar(char *c)
unsafe char* to xmlChar* cast
Definition: libxmldefs.h:70