2
$Id: XMLtools.h 15892 2013-04-03 08:49:18Z sloot $
3
$URL: https://ilk.uvt.nl/svn/sources/libticcutils/trunk/include/ticcutils/XMLtools.h $
5
Copyright (c) 1998 - 2013
6
ILK - Tilburg University
7
CLiPS - University of Antwerp
9
This file is part of ticcutils
11
timbl is free software; you can redistribute it and/or modify
12
it under the terms of the GNU General Public License as published by
13
the Free Software Foundation; either version 3 of the License, or
14
(at your option) any later version.
16
timbl is distributed in the hope that it will be useful,
17
but WITHOUT ANY WARRANTY; without even the implied warranty of
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
GNU General Public License for more details.
21
You should have received a copy of the GNU General Public License
22
along with this program; if not, see <http://www.gnu.org/licenses/>.
24
For questions and suggestions, see:
25
http://ilk.uvt.nl/software.html
30
#ifndef TICC_XML_TOOLS_H
31
#define TICC_XML_TOOLS_H
36
#include "libxml/tree.h"
40
inline xmlNode *XmlNewNode( const std::string& elem ){
41
return xmlNewNode( 0, (const xmlChar*)elem.c_str() );
44
inline xmlNode *XmlNewNode( xmlNs *ns, const std::string& elem ){
45
return xmlNewNode( ns, (const xmlChar*)elem.c_str() );
48
inline xmlNode *XmlNewComment( const std::string& elem ){
49
return xmlNewComment( (const xmlChar*)elem.c_str() );
52
inline xmlNode *XmlNewChild( xmlNode *node,
53
const std::string& elem ){
54
xmlNode *chld = xmlNewNode( 0, (const xmlChar*)elem.c_str() );
55
return xmlAddChild( node, chld );
58
inline xmlNode *XmlNewChild( xmlNode *node,
60
const std::string& elem ){
61
xmlNode *chld = xmlNewNode( ns, (const xmlChar*)elem.c_str() );
62
return xmlAddChild( node, chld );
65
inline xmlNode *XmlNewTextChild( xmlNode *node,
66
const std::string& elem,
67
const std::string& val ){
69
return xmlNewTextChild( node, 0, (xmlChar*)elem.c_str(), 0 );
71
return xmlNewTextChild( node, 0,
72
(const xmlChar*)elem.c_str(),
73
(const xmlChar*)val.c_str() );
76
inline xmlNode *XmlNewTextChild( xmlNode *node,
78
const std::string& elem,
79
const std::string& val ){
81
return xmlNewTextChild( node, ns,
82
(xmlChar*)elem.c_str(), 0 );
84
return xmlNewTextChild( node, ns,
85
(const xmlChar*)elem.c_str(),
86
(const xmlChar*)val.c_str() );
89
inline void XmlAddContent( xmlNode *node, const std::string& cont ){
90
xmlNodeAddContent( node, (const xmlChar*)cont.c_str() );
93
inline xmlAttr *XmlSetAttribute( xmlNode *node,
94
const std::string& att,
95
const std::string& val ){
96
return xmlSetProp( node,
97
(const xmlChar*)att.c_str(),
98
(const xmlChar*)val.c_str() );
101
inline std::string getAttribute( const xmlNode *node,
102
const std::string& att ){
104
xmlAttr *a = node->properties;
106
if ( att == (char*)a->name )
107
return (char *)a->children->content;
114
std::string getNS( const xmlNode *, std::string& );
115
inline std::string getNS( const xmlNode *n ) {
120
std::map<std::string,std::string> getNSvalues( const xmlNode * );
122
std::string serialize( const xmlNode& node );
124
inline std::string Name( const xmlNode *node ){
127
result = (char *)node->name;
132
inline std::string XmlContent( const xmlNode *node ){
135
xmlChar *tmp = xmlNodeListGetString( node->doc, node->children, 1 );
137
result = std::string( (char *)tmp );
145
friend std::ostream& operator << ( std::ostream& , const XmlDoc& );
147
XmlDoc( const std::string& );
149
xmlFreeDoc( the_doc );
151
void setRoot( xmlNode* );
152
xmlNode *getRoot() const;
153
xmlNode *MakeRoot( const std::string& );
154
const std::string toString() const;
159
inline std::ostream& operator << ( std::ostream& os, const XmlDoc& doc ){
160
os << doc.toString();
164
inline std::ostream& operator << ( std::ostream& os, const xmlNode& node ){
165
os << serialize( node );
169
inline std::ostream& operator << ( std::ostream& os, const xmlNode *node ){
170
os << serialize( *node );
174
std::list<xmlNode*> FindNodes( xmlNode *, const std::string& );
175
xmlNode *xPath( xmlNode *, const std::string& );