libatomprobe
Library for Atom Probe Tomography (APT) computation
XMLHelper.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Daniel Haley
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
18 
19 namespace AtomProbe{
20 
21 using std::string;
22 
23 void XMLFreeDoc(void* data)
24 {
25  xmlFreeDoc((xmlDocPtr)data);
26 }
27 
28 unsigned int XMLHelpNextType(xmlNodePtr &node, int nodeType)
29 {
30  do
31  {
32  node= node->next;
33  if(!node)
34  return 1;
35  }
36  while(node->type != nodeType);
37  return 0;
38 }
39 
40 //returns zero on success, nonzero on fail
41 unsigned int XMLHelpFwdToElem(xmlNodePtr &node, const char *nodeName)
42 {
43  if(!xmlStrcmp(node->name,(const xmlChar *) nodeName))
44  return (!node);
45  do
46  {
47  node=node->next;
48  }while(node != NULL &&
49  xmlStrcmp(node->name,(const xmlChar *) nodeName));
50  return (!node);
51 }
52 
53 unsigned int XMLHelpFwdNotElem(xmlNodePtr &node,const char *nodeName)
54 {
55  do
56  {
57  node=node->next;
58  }while(node !=NULL && node->type != XML_ELEMENT_NODE &&
59  !xmlStrcmp(node->name,(const xmlChar *)nodeName));
60 
61  return !node;
62 }
63 
64 string XMLHelpGetText(xmlNodePtr node)
65 {
66  string result;
67  XMLHelpNextType(node,XML_TEXT_NODE);
68  result =(char *) node->content;
69  return result;
70 }
71 
72 }
unsigned int XMLHelpFwdToElem(xmlNodePtr &node, const char *nodeName)
Definition: XMLHelper.cpp:41
unsigned int XMLHelpNextType(xmlNodePtr &node, int)
Definition: XMLHelper.cpp:28
std::string XMLHelpGetText(xmlNodePtr &node)
void XMLFreeDoc(void *data)
Free a xmlDoc pointer. For use in conjunction with std::unique_ptr for auto-deallocation.
Definition: XMLHelper.cpp:23
unsigned int XMLHelpFwdNotElem(xmlNodePtr &node, const char *nodeName)
Definition: XMLHelper.cpp:53