NCBI C++ ToolKit
node_manip.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /*
2  * Copyright (C) 2001-2003 Peter J Jones (pjones@pmade.org)
3  * All Rights Reserved
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name of the Author nor the names of its contributors
16  * may be used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
23  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  */
32 
33 /*
34  * $Id: node_manip.hpp 62198 2014-03-24 18:01:17Z satskyse $
35  * NOTE: This file was modified from its original version 0.6.0
36  * to fit the NCBI C++ Toolkit build framework and
37  * API and functionality requirements.
38  * Most importantly, it adds support for XML namespaces (see "namespace.hpp").
39  */
40 
41 /** @file
42  * This file contains the definition of the xml::node manipulation
43  * functions.
44 **/
45 
46 #ifndef _xmlwrapp_node_manip_h_
47 #define _xmlwrapp_node_manip_h_
48 
49 // libxml includes
50 #include <libxml/tree.h>
51 
52 namespace xml {
53 
54 namespace impl {
55 
56  //####################################################################
57  /**
58  * Insert a node somewhere in the child list of a parent node.
59  *
60  * @param parent The parent who's child list will be inserted into.
61  * @param before Insert to_add before this node, or, if this node is 0 (null), insert at the end of the child list.
62  * @param to_add The node to be copied and then inserted into the child list.
63  * @return The new node that was inserted into the child list.
64  * @author Peter Jones
65  **/
66  //####################################################################
67  xmlNodePtr node_insert (xmlNodePtr parent, xmlNodePtr before, xmlNodePtr to_add);
68 
69  //####################################################################
70  /**
71  * Replace a node with another one. The node being replaced will be
72  * freed from memory.
73  *
74  * @param old_node The old node to remove and free.
75  * @param new_node The new node to copy and insert where old node was.
76  * @return The new node that was crated from copying new_node and inserted into the child list where old_node was.
77  * @author Peter Jones
78  **/
79  //####################################################################
80  xmlNodePtr node_replace (xmlNodePtr old_node, xmlNodePtr new_node);
81 
82  //####################################################################
83  /**
84  * Erase a node from the child list, and then free it from memory.
85  *
86  * @param to_erase The node to remove and free.
87  * @return The node that was after to_erase (may be 0 (null) if to_erase was the last node in the list)
88  * @author Peter Jones
89  **/
90  //####################################################################
91  xmlNodePtr node_erase (xmlNodePtr to_erase);
92 
93  //####################################################################
94  /**
95  * Set the node and its children default namespace to the given. It is
96  * necessary to do when a node is inserted into a document which has
97  * a default namespace declared.
98  *
99  * @param node The node to start from.
100  * @param default_ns The pointer to the document default namespace
101  * @author Sergey Satskiy, NCBI
102  **/
103  //####################################################################
104  void set_children_default_ns (xmlNodePtr node, xmlNsPtr default_ns);
105 
106  //####################################################################
107  /**
108  * Check if the node holds default namespace definition
109  *
110  * @param node The node to be checked.
111  * @return true if the node holds default namespace definition.
112  * @author Sergey Satskiy, NCBI
113  **/
114  //####################################################################
115  bool has_default_ns_definition (xmlNodePtr node);
116 
117  //####################################################################
118  /**
119  * Check if the node, attributes and children use the namespace
120  *
121  * @param node The node to be checked.
122  * @param ns The namespace to match (pointer comparison is used)
123  * @return true if the namespace is used
124  * @author Sergey Satskiy, NCBI
125  **/
126  //####################################################################
127  bool is_ns_used (xmlNodePtr node, xmlNsPtr ns);
128 
129  //####################################################################
130  /**
131  * Replaces the node and its children default namespace with the given.
132  * It is required when a default namespace definition is added to the node.
133  *
134  * @param node The node to start from.
135  * @param newns The namespace to be set
136  * @author Sergey Satskiy, NCBI
137  **/
138  //####################################################################
139  void update_children_default_ns (xmlNodePtr node, xmlNsPtr newns);
140 
141  //####################################################################
142  /**
143  * Erases namespace definition in the node. libxml2 namespace is freed.
144  * The function does not check whether the namespace is used.
145  *
146  * @param node The node to delete from.
147  * @param definition The namespace to be erased
148  * @author Sergey Satskiy, NCBI
149  **/
150  //####################################################################
151  void erase_ns_definition (xmlNodePtr node, xmlNsPtr definition);
152 
153  //####################################################################
154  /**
155  * Searches for a namspace definition in the given node
156  *
157  * @param node The node to search in.
158  * @param prefix The namespace definition prefix
159  * @return pointer to the namespace definition or NULL if not found
160  * @author Sergey Satskiy, NCBI
161  **/
162  //####################################################################
163  xmlNsPtr lookup_ns_definition (xmlNodePtr node, const char *prefix);
164 
165  //####################################################################
166  /**
167  * Searches for a default namspace definition in the given node and above
168  *
169  * @param node The node to start the search from.
170  * @return pointer to the namespace definition or NULL if not found
171  * @author Sergey Satskiy, NCBI
172  **/
173  //####################################################################
174  xmlNsPtr lookup_default_ns_above (xmlNodePtr node);
175 
176  //####################################################################
177  /**
178  * Replaces old namspace with a new one in nodes and attributes all
179  * the way down in the hierarchy
180  *
181  * @param node The node to start with.
182  * @param oldNs The old namespace
183  * @param newNs The new namespace
184  * @author Sergey Satskiy, NCBI
185  **/
186  //####################################################################
187  void replace_ns (xmlNodePtr node, xmlNsPtr oldNs, xmlNsPtr newNs);
188 }
189 
190 }
191 #endif
xmlNodePtr node_replace(xmlNodePtr old_node, xmlNodePtr new_node)
Replace a node with another one.
Definition: node_manip.cpp:75
void erase_ns_definition(xmlNodePtr node, xmlNsPtr definition)
Erases namespace definition in the node.
Definition: node_manip.cpp:170
xmlNsPtr lookup_default_ns_above(xmlNodePtr node)
Searches for a default namspace definition in the given node and above.
Definition: node_manip.cpp:198
xmlNodePtr node_erase(xmlNodePtr to_erase)
Erase a node from the child list, and then free it from memory.
Definition: node_manip.cpp:108
void set_children_default_ns(xmlNodePtr node, xmlNsPtr default_ns)
Set the node and its children default namespace to the given.
Definition: node_manip.cpp:117
void update_children_default_ns(xmlNodePtr node, xmlNsPtr newns)
Replaces the node and its children default namespace with the given.
Definition: node_manip.cpp:157
bool is_ns_used(xmlNodePtr node, xmlNsPtr ns)
Check if the node, attributes and children use the namespace.
Definition: node_manip.cpp:139
void replace_ns(xmlNodePtr node, xmlNsPtr oldNs, xmlNsPtr newNs)
Replaces old namspace with a new one in nodes and attributes all the way down in the hierarchy.
Definition: node_manip.cpp:211
bool has_default_ns_definition(xmlNodePtr node)
Check if the node holds default namespace definition.
Definition: node_manip.cpp:129
xmlNodePtr node_insert(xmlNodePtr parent, xmlNodePtr before, xmlNodePtr to_add)
Insert a node somewhere in the child list of a parent node.
Definition: node_manip.cpp:54
xmlNsPtr lookup_ns_definition(xmlNodePtr node, const char *prefix)
Searches for a namspace definition in the given node.
Definition: node_manip.cpp:185
XML library namespace.
Definition: attributes.hpp:57
static const char * prefix[]
Definition: pcregrep.c:405
Modified on Tue May 28 05:50:49 2024 by modify_doxy.py rev. 669887