| 1 |
|
| /* $Id$ |
| 2 |
|
| * |
| 3 |
|
| * This is free software, you may use it and distribute it under the same terms as |
| 4 |
|
| * Perl itself. |
| 5 |
|
| * |
| 6 |
|
| * Copyright 2001-2003 AxKit.com Ltd., 2002-2006 Christian Glahn, 2006-2009 Petr Pajas |
| 7 |
|
| */ |
| 8 |
|
| |
| 9 |
|
| #include "dom.h" |
| 10 |
|
| #include "perl-libxml-mm.h" |
| 11 |
|
| |
| 12 |
|
| /* #define warn(string) fprintf(stderr, string) */ |
| 13 |
|
| |
| 14 |
|
| #ifdef XS_WARNINGS |
| 15 |
|
| #define xs_warn(string) warn("%s",string) |
| 16 |
|
| #else |
| 17 |
|
| #define xs_warn(string) |
| 18 |
|
| #endif |
| 19 |
|
| |
| 20 |
|
| void |
| 21 |
|
| domClearPSVIInList(xmlNodePtr list); |
| 22 |
|
| |
| 23 |
|
| void |
| 24 |
72 |
| domClearPSVI(xmlNodePtr tree) { |
| 25 |
|
| xmlAttrPtr prop; |
| 26 |
|
| |
| 27 |
72 |
▶ | if (tree == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (tree == NULL) |
0 |
72 |
72 |
|
| 28 |
0 |
| return; |
| 29 |
72 |
▶ | if (tree->type == XML_ELEMENT_NODE) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tree->type == XML_ELEMENT_NODE) { |
23 |
49 |
72 |
|
| 30 |
23 |
| tree->psvi = NULL; |
| 31 |
23 |
| prop = tree->properties; |
| 32 |
29 |
▶ | while (prop != NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (prop != NULL) { |
6 |
23 |
29 |
|
| 33 |
6 |
▶ | if (tree->type == XML_ATTRIBUTE_NODE) |
Branch: 1 branch
| Branch | True | False | Total |
| if (tree->type == XML_ATTRIBUTE_NODE) |
0 |
6 |
6 |
|
| 34 |
0 |
| ((xmlAttrPtr) prop)->psvi = NULL; |
| 35 |
6 |
| domClearPSVIInList(prop->children); |
| 36 |
6 |
| prop = prop->next; |
| 37 |
|
| } |
| 38 |
49 |
▶ | } else if (tree->type == XML_DOCUMENT_NODE) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (tree->type == XML_DOCUMENT_NODE) { |
8 |
41 |
49 |
|
| 39 |
8 |
| ((xmlDocPtr) tree)->psvi = NULL; |
| 40 |
|
| } |
| 41 |
72 |
▶ | if (tree->children != NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (tree->children != NULL) |
28 |
44 |
72 |
|
| 42 |
28 |
| domClearPSVIInList(tree->children); |
| 43 |
|
| } |
| 44 |
|
| |
| 45 |
|
| void |
| 46 |
34 |
| domClearPSVIInList(xmlNodePtr list) { |
| 47 |
|
| xmlNodePtr cur; |
| 48 |
|
| |
| 49 |
34 |
▶ | if (list == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (list == NULL) |
0 |
34 |
34 |
|
| 50 |
0 |
| return; |
| 51 |
34 |
| cur = list; |
| 52 |
98 |
▶ | while (cur != NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (cur != NULL) { |
64 |
34 |
98 |
|
| 53 |
64 |
| domClearPSVI(cur); |
| 54 |
64 |
| cur = cur->next; |
| 55 |
|
| } |
| 56 |
|
| } |
| 57 |
|
| |
| 58 |
|
| /** |
| 59 |
|
| * Name: domReconcileNs |
| 60 |
|
| * Synopsis: void domReconcileNs( xmlNodePtr tree ); |
| 61 |
|
| * @tree: the tree to reconcile |
| 62 |
|
| * |
| 63 |
|
| * Reconciles namespacing on a tree by removing declarations |
| 64 |
|
| * of element and attribute namespaces that are already |
| 65 |
|
| * declared in the scope of the corresponding node. |
| 66 |
|
| **/ |
| 67 |
|
| |
| 68 |
|
| void |
| 69 |
19 |
| domAddNsDef(xmlNodePtr tree, xmlNsPtr ns) |
| 70 |
|
| { |
| 71 |
19 |
| xmlNsPtr i = tree->nsDef; |
| 72 |
22 |
▶ | while(i != NULL && i != ns) |
Branch: 2 branches
| Branch | True | False | Total |
| while(i != NULL && i != ns) |
3 |
19 |
22 |
| while(i != NULL && i != ns) |
3 |
0 |
3 |
|
| 73 |
3 |
| i = i->next; |
| 74 |
19 |
▶ | if( i == NULL ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( i == NULL ) |
19 |
0 |
19 |
|
| 75 |
|
| { |
| 76 |
19 |
| ns->next = tree->nsDef; |
| 77 |
19 |
| tree->nsDef = ns; |
| 78 |
|
| } |
| 79 |
19 |
| } |
| 80 |
|
| |
| 81 |
|
| char |
| 82 |
26 |
| domRemoveNsDef(xmlNodePtr tree, xmlNsPtr ns) |
| 83 |
|
| { |
| 84 |
26 |
| xmlNsPtr i = tree->nsDef; |
| 85 |
|
| |
| 86 |
26 |
▶ | if( ns == tree->nsDef ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( ns == tree->nsDef ) |
17 |
9 |
26 |
|
| 87 |
|
| { |
| 88 |
17 |
| tree->nsDef = tree->nsDef->next; |
| 89 |
17 |
| ns->next = NULL; |
| 90 |
17 |
| return(1); |
| 91 |
|
| } |
| 92 |
10 |
▶ | while( i != NULL ) |
Branch: 1 branch
| Branch | True | False | Total |
| while( i != NULL ) |
3 |
7 |
10 |
|
| 93 |
|
| { |
| 94 |
3 |
▶ | if( i->next == ns ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( i->next == ns ) |
2 |
1 |
3 |
|
| 95 |
|
| { |
| 96 |
2 |
| i->next = ns->next; |
| 97 |
2 |
| ns->next = NULL; |
| 98 |
2 |
| return(1); |
| 99 |
|
| } |
| 100 |
1 |
| i = i->next; |
| 101 |
|
| } |
| 102 |
7 |
| return(0); |
| 103 |
|
| } |
| 104 |
|
| |
| 105 |
|
| /* ns->next must be NULL, or bad things could happen */ |
| 106 |
|
| xmlNsPtr |
| 107 |
7 |
| _domAddNsChain(xmlNsPtr c, xmlNsPtr ns) |
| 108 |
|
| { |
| 109 |
7 |
▶ | if( c == NULL ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( c == NULL ) |
7 |
0 |
7 |
|
| 110 |
7 |
| return(ns); |
| 111 |
|
| else |
| 112 |
|
| { |
| 113 |
0 |
| xmlNsPtr i = c; |
| 114 |
0 |
▶ | while(i != NULL && i != ns) |
Branch: 2 branches
| Branch | True | False | Total |
| while(i != NULL && i != ns) |
0 |
0 |
0 |
| while(i != NULL && i != ns) |
0 |
0 |
0 |
|
| 115 |
0 |
| i = i->next; |
| 116 |
0 |
▶ | if(i == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if(i == NULL) |
0 |
0 |
0 |
|
| 117 |
|
| { |
| 118 |
0 |
| ns->next = c; |
| 119 |
0 |
| return(ns); |
| 120 |
|
| } |
| 121 |
|
| } |
| 122 |
0 |
| return(c); |
| 123 |
|
| } |
| 124 |
|
| |
| 125 |
|
| /* We need to be smarter with attributes, because the declaration is on the parent element */ |
| 126 |
|
| void |
| 127 |
13 |
| _domReconcileNsAttr(xmlAttrPtr attr, xmlNsPtr * unused) |
| 128 |
|
| { |
| 129 |
13 |
| xmlNodePtr tree = attr->parent; |
| 130 |
13 |
▶ | if (tree == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (tree == NULL) |
0 |
13 |
13 |
|
| 131 |
0 |
| return; |
| 132 |
13 |
▶ | if( attr->ns != NULL ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( attr->ns != NULL ) |
9 |
4 |
13 |
|
| 133 |
|
| { |
| 134 |
|
| xmlNsPtr ns; |
| 135 |
18 |
| if ((attr->ns->prefix != NULL) && |
| 136 |
9 |
| (xmlStrEqual(attr->ns->prefix, BAD_CAST "xml"))) { |
| 137 |
|
| /* prefix 'xml' has no visible declaration */ |
| 138 |
5 |
| ns = xmlSearchNsByHref(tree->doc, tree, XML_XML_NAMESPACE); |
| 139 |
5 |
| attr->ns = ns; |
| 140 |
5 |
| return; |
| 141 |
|
| } else { |
| 142 |
4 |
| ns = xmlSearchNs( tree->doc, tree->parent, attr->ns->prefix ); |
| 143 |
|
| } |
| 144 |
5 |
▶ | if( ns != NULL && ns->href != NULL && attr->ns->href != NULL && |
Branch: 2 branches
| Branch | True | False | Total |
| if( ns != NULL && ns->href != NULL && attr->ns->href != NULL && |
1 |
3 |
4 |
| if( ns != NULL && ns->href != NULL && attr->ns->href != NULL && |
1 |
0 |
1 |
|
| 145 |
1 |
| xmlStrcmp(ns->href,attr->ns->href) == 0 ) |
| 146 |
|
| { |
| 147 |
|
| /* Remove the declaration from the element */ |
| 148 |
1 |
▶ | if( domRemoveNsDef(tree, attr->ns) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( domRemoveNsDef(tree, attr->ns) ) |
1 |
0 |
1 |
|
| 149 |
|
| /* Queue up this namespace for freeing */ |
| 150 |
1 |
| *unused = _domAddNsChain(*unused, attr->ns); |
| 151 |
|
| |
| 152 |
|
| /* Replace the namespace with the one found */ |
| 153 |
1 |
| attr->ns = ns; |
| 154 |
|
| } |
| 155 |
|
| else |
| 156 |
|
| { |
| 157 |
|
| /* If the declaration is here, we don't need to do anything */ |
| 158 |
3 |
▶ | if( domRemoveNsDef(tree, attr->ns) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( domRemoveNsDef(tree, attr->ns) ) |
1 |
2 |
3 |
|
| 159 |
1 |
| domAddNsDef(tree, attr->ns); |
| 160 |
|
| else |
| 161 |
|
| { |
| 162 |
|
| /* Replace/Add the namespace declaration on the element */ |
| 163 |
2 |
| attr->ns = xmlCopyNamespace(attr->ns); |
| 164 |
2 |
▶ | if (attr->ns) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (attr->ns) { |
2 |
0 |
2 |
|
| 165 |
2 |
| domAddNsDef(tree, attr->ns); |
| 166 |
|
| } |
| 167 |
|
| } |
| 168 |
|
| } |
| 169 |
|
| } |
| 170 |
|
| } |
| 171 |
|
| |
| 172 |
|
| void |
| 173 |
179 |
| _domReconcileNs(xmlNodePtr tree, xmlNsPtr * unused) |
| 174 |
|
| { |
| 175 |
179 |
▶ | if( tree->ns != NULL |
Branch: 1 branch
| Branch | True | False | Total |
| if( tree->ns != NULL |
49 |
130 |
179 |
|
| 176 |
49 |
▶ | && ((tree->type == XML_ELEMENT_NODE) |
Branch: 1 branch
| Branch | True | False | Total |
| && ((tree->type == XML_ELEMENT_NODE) |
27 |
22 |
49 |
|
| 177 |
27 |
▶ | || (tree->type == XML_ATTRIBUTE_NODE))) |
Branch: 1 branch
| Branch | True | False | Total |
| || (tree->type == XML_ATTRIBUTE_NODE))) |
0 |
27 |
27 |
|
| 178 |
|
| { |
| 179 |
22 |
| xmlNsPtr ns = xmlSearchNs( tree->doc, tree->parent, tree->ns->prefix ); |
| 180 |
29 |
▶ | if( ns != NULL && ns->href != NULL && tree->ns->href != NULL && |
Branch: 2 branches
| Branch | True | False | Total |
| if( ns != NULL && ns->href != NULL && tree->ns->href != NULL && |
7 |
15 |
22 |
| if( ns != NULL && ns->href != NULL && tree->ns->href != NULL && |
7 |
0 |
7 |
|
| 181 |
7 |
| xmlStrcmp(ns->href,tree->ns->href) == 0 ) |
| 182 |
|
| { |
| 183 |
|
| /* Remove the declaration (if present) */ |
| 184 |
6 |
▶ | if( domRemoveNsDef(tree, tree->ns) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( domRemoveNsDef(tree, tree->ns) ) |
6 |
0 |
6 |
|
| 185 |
|
| /* Queue the namespace for freeing */ |
| 186 |
6 |
| *unused = _domAddNsChain(*unused, tree->ns); |
| 187 |
|
| |
| 188 |
|
| /* Replace the namespace with the one found */ |
| 189 |
6 |
| tree->ns = ns; |
| 190 |
|
| } |
| 191 |
|
| else |
| 192 |
|
| { |
| 193 |
|
| /* If the declaration is here, we don't need to do anything */ |
| 194 |
16 |
▶ | if( domRemoveNsDef(tree, tree->ns) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( domRemoveNsDef(tree, tree->ns) ) { |
11 |
5 |
16 |
|
| 195 |
11 |
| domAddNsDef(tree, tree->ns); |
| 196 |
|
| } |
| 197 |
|
| else |
| 198 |
|
| { |
| 199 |
|
| /* Restart the namespace at this point */ |
| 200 |
5 |
| tree->ns = xmlCopyNamespace(tree->ns); |
| 201 |
5 |
▶ | if (tree->ns) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tree->ns) { |
5 |
0 |
5 |
|
| 202 |
5 |
| domAddNsDef(tree, tree->ns); |
| 203 |
|
| } |
| 204 |
|
| } |
| 205 |
|
| } |
| 206 |
|
| } |
| 207 |
|
| /* Fix attribute namespacing */ |
| 208 |
179 |
▶ | if( tree->type == XML_ELEMENT_NODE ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( tree->type == XML_ELEMENT_NODE ) |
99 |
80 |
179 |
|
| 209 |
|
| { |
| 210 |
99 |
| xmlElementPtr ele = (xmlElementPtr) tree; |
| 211 |
|
| /* attributes is set to xmlAttributePtr, |
| 212 |
|
| but is an xmlAttrPtr??? */ |
| 213 |
99 |
| xmlAttrPtr attr = (xmlAttrPtr) ele->attributes; |
| 214 |
112 |
▶ | while( attr != NULL ) |
Branch: 1 branch
| Branch | True | False | Total |
| while( attr != NULL ) |
13 |
99 |
112 |
|
| 215 |
|
| { |
| 216 |
13 |
| _domReconcileNsAttr(attr, unused); |
| 217 |
13 |
| attr = attr->next; |
| 218 |
|
| } |
| 219 |
|
| } |
| 220 |
|
| { |
| 221 |
|
| /* Recurse through all child nodes */ |
| 222 |
179 |
| xmlNodePtr child = tree->children; |
| 223 |
236 |
▶ | while( child != NULL ) |
Branch: 1 branch
| Branch | True | False | Total |
| while( child != NULL ) |
57 |
179 |
236 |
|
| 224 |
|
| { |
| 225 |
57 |
| _domReconcileNs(child, unused); |
| 226 |
57 |
| child = child->next; |
| 227 |
|
| } |
| 228 |
|
| } |
| 229 |
179 |
| } |
| 230 |
|
| |
| 231 |
|
| void |
| 232 |
122 |
| domReconcileNs(xmlNodePtr tree) |
| 233 |
|
| { |
| 234 |
122 |
| xmlNsPtr unused = NULL; |
| 235 |
122 |
| _domReconcileNs(tree, &unused); |
| 236 |
122 |
▶ | if( unused != NULL ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( unused != NULL ) |
7 |
115 |
122 |
|
| 237 |
7 |
| xmlFreeNsList(unused); |
| 238 |
122 |
| } |
| 239 |
|
| |
| 240 |
|
| /** |
| 241 |
|
| * Name: domReadWellBalancedString |
| 242 |
|
| * Synopsis: xmlNodePtr domReadWellBalancedString( xmlDocPtr doc, xmlChar *string ) |
| 243 |
|
| * @doc: the document, the string should belong to |
| 244 |
|
| * @string: the string to parse |
| 245 |
|
| * |
| 246 |
|
| * this function is pretty neat, since you can read in well balanced |
| 247 |
|
| * strings and get a list of nodes, which can be added to any other node. |
| 248 |
|
| * (sure - this should return a doucment_fragment, but still it doesn't) |
| 249 |
|
| * |
| 250 |
|
| * the code is pretty heavy i think, but deep in my heard i believe it's |
| 251 |
|
| * worth it :) (e.g. if you like to read a chunk of well-balanced code |
| 252 |
|
| * from a databasefield) |
| 253 |
|
| * |
| 254 |
|
| * in 99% the cases i believe it is faster than to create the dom by hand, |
| 255 |
|
| * and skip the parsing job which has to be done here. |
| 256 |
|
| * |
| 257 |
|
| * the repair flag will not be recognized with the current libxml2 |
| 258 |
|
| **/ |
| 259 |
|
| xmlNodePtr |
| 260 |
43 |
| domReadWellBalancedString( xmlDocPtr doc, xmlChar* block, int repair ) { |
| 261 |
43 |
| int retCode = -1; |
| 262 |
43 |
| xmlNodePtr nodes = NULL; |
| 263 |
|
| |
| 264 |
43 |
▶ | if ( block ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( block ) { |
43 |
0 |
43 |
|
| 265 |
|
| /* read and encode the chunk */ |
| 266 |
43 |
| retCode = xmlParseBalancedChunkMemory( doc, |
| 267 |
|
| NULL, |
| 268 |
|
| NULL, |
| 269 |
|
| 0, |
| 270 |
|
| block, |
| 271 |
|
| &nodes ); |
| 272 |
|
| |
| 273 |
|
| /* retCode = xmlParseBalancedChunkMemoryRecover( doc, */ |
| 274 |
|
| /* NULL, */ |
| 275 |
|
| /* NULL, */ |
| 276 |
|
| /* 0, */ |
| 277 |
|
| /* block, */ |
| 278 |
|
| /* &nodes, */ |
| 279 |
|
| /* repair ); */ |
| 280 |
|
| |
| 281 |
|
| /* error handling */ |
| 282 |
43 |
▶ | if ( retCode != 0 && repair == 0 ) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ( retCode != 0 && repair == 0 ) { |
8 |
35 |
43 |
| if ( retCode != 0 && repair == 0 ) { |
8 |
0 |
8 |
|
| 283 |
|
| /* if the code was not well balanced, we will not return |
| 284 |
|
| * a bad node list, but we have to free the nodes */ |
| 285 |
8 |
| xmlFreeNodeList( nodes ); |
| 286 |
8 |
| nodes = NULL; |
| 287 |
|
| } |
| 288 |
|
| else { |
| 289 |
35 |
| xmlSetListDoc(nodes,doc); |
| 290 |
|
| } |
| 291 |
|
| } |
| 292 |
|
| |
| 293 |
43 |
| return nodes; |
| 294 |
|
| } |
| 295 |
|
| |
| 296 |
|
| /** |
| 297 |
|
| * internal helper: insert node to nodelist |
| 298 |
|
| * synopsis: xmlNodePtr insert_node_to_nodelist( leader, insertnode, followup ); |
| 299 |
|
| * while leader and followup are already list nodes. both may be NULL |
| 300 |
|
| * if leader is null the parents children will be reset |
| 301 |
|
| * if followup is null the parent last will be reset. |
| 302 |
|
| * leader and followup has to be followups in the nodelist!!! |
| 303 |
|
| * the function returns the node inserted. if a fragment was inserted, |
| 304 |
|
| * the first node of the list will returned |
| 305 |
|
| * |
| 306 |
|
| * i ran into a misconception here. there should be a normalization function |
| 307 |
|
| * for the DOM, so sequences of text nodes can get replaced by a single |
| 308 |
|
| * text node. as i see DOM Level 1 does not allow text node sequences, while |
| 309 |
|
| * Level 2 and 3 do. |
| 310 |
|
| **/ |
| 311 |
|
| int |
| 312 |
45 |
| domAddNodeToList(xmlNodePtr cur, xmlNodePtr leader, xmlNodePtr followup) |
| 313 |
|
| { |
| 314 |
45 |
| xmlNodePtr c1 = NULL, c2 = NULL, p = NULL; |
| 315 |
45 |
▶ | if ( cur ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( cur ) { |
45 |
0 |
45 |
|
| 316 |
45 |
| c1 = c2 = cur; |
| 317 |
45 |
▶ | if( leader ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( leader ) { |
39 |
6 |
45 |
|
| 318 |
39 |
| p = leader->parent; |
| 319 |
|
| } |
| 320 |
6 |
▶ | else if( followup ) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if( followup ) { |
6 |
0 |
6 |
|
| 321 |
6 |
| p = followup->parent; |
| 322 |
|
| } |
| 323 |
|
| else { |
| 324 |
0 |
| return 0; /* can't insert */ |
| 325 |
|
| } |
| 326 |
|
| |
| 327 |
45 |
▶ | if ( cur->type == XML_DOCUMENT_FRAG_NODE ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( cur->type == XML_DOCUMENT_FRAG_NODE ) { |
6 |
39 |
45 |
|
| 328 |
6 |
| c1 = cur->children; |
| 329 |
18 |
▶ | while ( c1 ){ |
Branch: 1 branch
| Branch | True | False | Total |
| while ( c1 ){ |
12 |
6 |
18 |
|
| 330 |
12 |
| c1->parent = p; |
| 331 |
12 |
| c1 = c1->next; |
| 332 |
|
| } |
| 333 |
6 |
| c1 = cur->children; |
| 334 |
6 |
| c2 = cur->last; |
| 335 |
6 |
| cur->last = cur->children = NULL; |
| 336 |
|
| } |
| 337 |
|
| else { |
| 338 |
39 |
| cur->parent = p; |
| 339 |
|
| } |
| 340 |
|
| |
| 341 |
45 |
▶ | if (c1 && c2 && c1!=leader) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (c1 && c2 && c1!=leader) { |
45 |
0 |
45 |
| if (c1 && c2 && c1!=leader) { |
45 |
0 |
45 |
| if (c1 && c2 && c1!=leader) { |
45 |
0 |
45 |
|
| 342 |
45 |
▶ | if ( leader ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( leader ) { |
39 |
6 |
45 |
|
| 343 |
39 |
| leader->next = c1; |
| 344 |
39 |
| c1->prev = leader; |
| 345 |
|
| } |
| 346 |
6 |
▶ | else if ( p ) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if ( p ) { |
6 |
0 |
6 |
|
| 347 |
6 |
| p->children = c1; |
| 348 |
|
| } |
| 349 |
|
| |
| 350 |
45 |
▶ | if ( followup ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( followup ) { |
14 |
31 |
45 |
|
| 351 |
14 |
| followup->prev = c2; |
| 352 |
14 |
| c2->next = followup; |
| 353 |
|
| } |
| 354 |
31 |
▶ | else if ( p ) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if ( p ) { |
31 |
0 |
31 |
|
| 355 |
31 |
| p->last = c2; |
| 356 |
|
| } |
| 357 |
|
| } |
| 358 |
45 |
| return 1; |
| 359 |
|
| } |
| 360 |
0 |
| return 0; |
| 361 |
|
| } |
| 362 |
|
| |
| 363 |
|
| /** |
| 364 |
|
| * domIsParent tests, if testnode is parent of the reference |
| 365 |
|
| * node. this test is very important to avoid circular constructs in |
| 366 |
|
| * trees. if the ref is a parent of the cur node the |
| 367 |
|
| * function returns 1 (TRUE), otherwise 0 (FALSE). |
| 368 |
|
| **/ |
| 369 |
|
| int |
| 370 |
89 |
| domIsParent( xmlNodePtr cur, xmlNodePtr refNode ) { |
| 371 |
89 |
| xmlNodePtr helper = NULL; |
| 372 |
|
| |
| 373 |
89 |
▶ | if ( cur == NULL || refNode == NULL) return 0; |
Branch: 2 branches
| Branch | True | False | Total |
| if ( cur == NULL || refNode == NULL) return 0; |
89 |
0 |
89 |
| if ( cur == NULL || refNode == NULL) return 0; |
0 |
89 |
89 |
|
| 374 |
89 |
▶ | if (refNode==cur) return 1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (refNode==cur) return 1; |
1 |
88 |
89 |
|
| 375 |
88 |
▶ | if ( cur->doc != refNode->doc |
Branch: 1 branch
| Branch | True | False | Total |
| if ( cur->doc != refNode->doc |
72 |
16 |
88 |
|
| 376 |
72 |
▶ | || refNode->children == NULL |
Branch: 1 branch
| Branch | True | False | Total |
| || refNode->children == NULL |
7 |
65 |
72 |
|
| 377 |
7 |
▶ | || cur->parent == (xmlNodePtr)cur->doc |
Branch: 1 branch
| Branch | True | False | Total |
| || cur->parent == (xmlNodePtr)cur->doc |
1 |
6 |
7 |
|
| 378 |
1 |
▶ | || cur->parent == NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| || cur->parent == NULL ) { |
0 |
1 |
1 |
|
| 379 |
87 |
| return 0; |
| 380 |
|
| } |
| 381 |
|
| |
| 382 |
1 |
▶ | if( refNode->type == XML_DOCUMENT_NODE ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( refNode->type == XML_DOCUMENT_NODE ) { |
0 |
1 |
1 |
|
| 383 |
0 |
| return 1; |
| 384 |
|
| } |
| 385 |
|
| |
| 386 |
1 |
| helper= cur; |
| 387 |
3 |
▶ | while ( helper && (xmlDocPtr) helper != cur->doc ) { |
Branch: 2 branches
| Branch | True | False | Total |
| while ( helper && (xmlDocPtr) helper != cur->doc ) { |
3 |
0 |
3 |
| while ( helper && (xmlDocPtr) helper != cur->doc ) { |
2 |
1 |
3 |
|
| 388 |
2 |
▶ | if( helper == refNode ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( helper == refNode ) { |
0 |
2 |
2 |
|
| 389 |
0 |
| return 1; |
| 390 |
|
| } |
| 391 |
2 |
| helper = helper->parent; |
| 392 |
|
| } |
| 393 |
|
| |
| 394 |
1 |
| return 0; |
| 395 |
|
| } |
| 396 |
|
| |
| 397 |
|
| int |
| 398 |
86 |
| domTestHierarchy(xmlNodePtr cur, xmlNodePtr refNode) |
| 399 |
|
| { |
| 400 |
86 |
▶ | if ( !refNode || !cur ) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ( !refNode || !cur ) { |
86 |
0 |
86 |
| if ( !refNode || !cur ) { |
0 |
86 |
86 |
|
| 401 |
0 |
| return 0; |
| 402 |
|
| } |
| 403 |
86 |
▶ | if (cur->type == XML_ATTRIBUTE_NODE) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cur->type == XML_ATTRIBUTE_NODE) { |
2 |
84 |
86 |
|
| 404 |
2 |
▶ | switch ( refNode->type ){ |
Branch: 1 branch
| Branch | True | False | Total |
| switch ( refNode->type ){ |
2 |
0 |
2 |
|
| 405 |
2 |
| case XML_TEXT_NODE: |
| 406 |
|
| case XML_ENTITY_REF_NODE: |
| 407 |
2 |
| return 1; |
| 408 |
|
| break; |
| 409 |
0 |
| default: |
| 410 |
0 |
| return 0; |
| 411 |
|
| break; |
| 412 |
|
| } |
| 413 |
|
| } |
| 414 |
|
| |
| 415 |
84 |
▶ | switch ( refNode->type ){ |
Branch: 1 branch
| Branch | True | False | Total |
| switch ( refNode->type ){ |
0 |
84 |
84 |
|
| 416 |
0 |
| case XML_ATTRIBUTE_NODE: |
| 417 |
|
| case XML_DOCUMENT_NODE: |
| 418 |
0 |
| return 0; |
| 419 |
|
| break; |
| 420 |
84 |
| default: |
| 421 |
84 |
| break; |
| 422 |
|
| } |
| 423 |
|
| |
| 424 |
84 |
▶ | if ( domIsParent( cur, refNode ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( domIsParent( cur, refNode ) ) { |
1 |
83 |
84 |
|
| 425 |
1 |
| return 0; |
| 426 |
|
| } |
| 427 |
|
| |
| 428 |
83 |
| return 1; |
| 429 |
|
| } |
| 430 |
|
| |
| 431 |
|
| int |
| 432 |
85 |
| domTestDocument(xmlNodePtr cur, xmlNodePtr refNode) |
| 433 |
|
| { |
| 434 |
85 |
▶ | if ( cur->type == XML_DOCUMENT_NODE ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( cur->type == XML_DOCUMENT_NODE ) { |
12 |
73 |
85 |
|
| 435 |
12 |
▶ | switch ( refNode->type ) { |
Branch: 1 branch
| Branch | True | False | Total |
| switch ( refNode->type ) { |
1 |
11 |
12 |
|
| 436 |
1 |
| case XML_ATTRIBUTE_NODE: |
| 437 |
|
| case XML_ELEMENT_NODE: |
| 438 |
|
| case XML_ENTITY_NODE: |
| 439 |
|
| case XML_ENTITY_REF_NODE: |
| 440 |
|
| case XML_TEXT_NODE: |
| 441 |
|
| case XML_CDATA_SECTION_NODE: |
| 442 |
|
| case XML_NAMESPACE_DECL: |
| 443 |
1 |
| return 0; |
| 444 |
|
| break; |
| 445 |
11 |
| default: |
| 446 |
11 |
| break; |
| 447 |
|
| } |
| 448 |
|
| } |
| 449 |
84 |
| return 1; |
| 450 |
|
| } |
| 451 |
|
| |
| 452 |
|
| void |
| 453 |
110 |
| domUnlinkNode( xmlNodePtr node ) { |
| 454 |
110 |
▶ | if ( node == NULL |
Branch: 1 branch
| Branch | True | False | Total |
| if ( node == NULL |
110 |
0 |
110 |
|
| 455 |
110 |
▶ | || ( node->prev == NULL |
Branch: 1 branch
| Branch | True | False | Total |
| || ( node->prev == NULL |
99 |
11 |
110 |
|
| 456 |
99 |
▶ | && node->next == NULL |
Branch: 1 branch
| Branch | True | False | Total |
| && node->next == NULL |
85 |
14 |
99 |
|
| 457 |
85 |
▶ | && node->parent == NULL ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| && node->parent == NULL ) ) { |
11 |
74 |
85 |
|
| 458 |
11 |
| return; |
| 459 |
|
| } |
| 460 |
|
| |
| 461 |
99 |
▶ | if (node->type == XML_DTD_NODE) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (node->type == XML_DTD_NODE) { |
11 |
88 |
99 |
|
| 462 |
|
| /* This clears the doc->intSubset pointer. */ |
| 463 |
11 |
| xmlUnlinkNode(node); |
| 464 |
11 |
| return; |
| 465 |
|
| } |
| 466 |
|
| |
| 467 |
88 |
▶ | if ( node->prev != NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( node->prev != NULL ) { |
11 |
77 |
88 |
|
| 468 |
11 |
| node->prev->next = node->next; |
| 469 |
|
| } |
| 470 |
|
| |
| 471 |
88 |
▶ | if ( node->next != NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( node->next != NULL ) { |
12 |
76 |
88 |
|
| 472 |
12 |
| node->next->prev = node->prev; |
| 473 |
|
| } |
| 474 |
|
| |
| 475 |
88 |
▶ | if ( node->parent != NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( node->parent != NULL ) { |
88 |
0 |
88 |
|
| 476 |
88 |
▶ | if ( node == node->parent->last ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( node == node->parent->last ) { |
76 |
12 |
88 |
|
| 477 |
76 |
| node->parent->last = node->prev; |
| 478 |
|
| } |
| 479 |
|
| |
| 480 |
88 |
▶ | if ( node == node->parent->children ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( node == node->parent->children ) { |
77 |
11 |
88 |
|
| 481 |
77 |
| node->parent->children = node->next; |
| 482 |
|
| } |
| 483 |
|
| } |
| 484 |
|
| |
| 485 |
88 |
| node->prev = NULL; |
| 486 |
88 |
| node->next = NULL; |
| 487 |
88 |
| node->parent = NULL; |
| 488 |
|
| } |
| 489 |
|
| |
| 490 |
|
| xmlNodePtr |
| 491 |
27 |
| domImportNode( xmlDocPtr doc, xmlNodePtr node, int move, int reconcileNS ) { |
| 492 |
27 |
| xmlNodePtr return_node = node; |
| 493 |
|
| |
| 494 |
27 |
▶ | if ( move ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( move ) { |
23 |
4 |
27 |
|
| 495 |
23 |
| return_node = node; |
| 496 |
23 |
| domUnlinkNode( node ); |
| 497 |
|
| } |
| 498 |
|
| else { |
| 499 |
4 |
▶ | if ( node->type == XML_DTD_NODE ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( node->type == XML_DTD_NODE ) { |
0 |
4 |
4 |
|
| 500 |
0 |
| return_node = (xmlNodePtr) xmlCopyDtd((xmlDtdPtr) node); |
| 501 |
|
| } |
| 502 |
|
| else { |
| 503 |
4 |
| return_node = xmlDocCopyNode( node, doc, 1 ); |
| 504 |
|
| } |
| 505 |
|
| } |
| 506 |
|
| |
| 507 |
|
| |
| 508 |
|
| /* tell all children about the new boss */ |
| 509 |
27 |
▶ | if ( node && node->doc != doc ) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ( node && node->doc != doc ) { |
27 |
0 |
27 |
| if ( node && node->doc != doc ) { |
27 |
0 |
27 |
|
| 510 |
|
| /* if the source document contained psvi, mark the current document as psvi tainted */ |
| 511 |
27 |
▶ | if (PmmIsPSVITainted(node->doc)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (PmmIsPSVITainted(node->doc)) |
22 |
5 |
27 |
| if (PmmIsPSVITainted(node->doc)) |
22 |
0 |
22 |
| if (PmmIsPSVITainted(node->doc)) |
0 |
22 |
22 |
|
| 512 |
0 |
▶ | PmmInvalidatePSVI(doc); |
Branch: 2 branches
| Branch | True | False | Total |
| PmmInvalidatePSVI(doc); |
0 |
0 |
0 |
| PmmInvalidatePSVI(doc); |
0 |
0 |
0 |
|
| 513 |
27 |
| xmlSetTreeDoc(return_node, doc); |
| 514 |
|
| } |
| 515 |
|
| |
| 516 |
27 |
▶ | if ( reconcileNS && doc && return_node |
Branch: 3 branches
| Branch | True | False | Total |
| if ( reconcileNS && doc && return_node |
20 |
7 |
27 |
| if ( reconcileNS && doc && return_node |
19 |
1 |
20 |
| if ( reconcileNS && doc && return_node |
19 |
0 |
19 |
|
| 517 |
19 |
▶ | && return_node->type != XML_ENTITY_REF_NODE ) { |
Branch: 1 branch
| Branch | True | False | Total |
| && return_node->type != XML_ENTITY_REF_NODE ) { |
19 |
0 |
19 |
|
| 518 |
19 |
| domReconcileNs(return_node); |
| 519 |
|
| } |
| 520 |
|
| |
| 521 |
27 |
| return return_node; |
| 522 |
|
| } |
| 523 |
|
| |
| 524 |
|
| /** |
| 525 |
|
| * Name: domName |
| 526 |
|
| * Synopsis: string = domName( node ); |
| 527 |
|
| * |
| 528 |
|
| * domName returns the full name for the current node. |
| 529 |
|
| * If the node belongs to a namespace it returns the prefix and |
| 530 |
|
| * the local name. otherwise only the local name is returned. |
| 531 |
|
| **/ |
| 532 |
|
| xmlChar* |
| 533 |
254 |
| domName(xmlNodePtr node) { |
| 534 |
254 |
| const xmlChar *prefix = NULL; |
| 535 |
254 |
| const xmlChar *name = NULL; |
| 536 |
254 |
| xmlChar *qname = NULL; |
| 537 |
|
| |
| 538 |
254 |
▶ | if ( node == NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( node == NULL ) { |
0 |
254 |
254 |
|
| 539 |
0 |
| return NULL; |
| 540 |
|
| } |
| 541 |
|
| |
| 542 |
254 |
| switch ( node->type ) { |
| 543 |
9 |
| case XML_XINCLUDE_START : |
| 544 |
|
| case XML_XINCLUDE_END : |
| 545 |
|
| case XML_ENTITY_REF_NODE : |
| 546 |
|
| case XML_ENTITY_NODE : |
| 547 |
|
| case XML_DTD_NODE : |
| 548 |
|
| case XML_ENTITY_DECL : |
| 549 |
|
| case XML_DOCUMENT_TYPE_NODE : |
| 550 |
|
| case XML_PI_NODE : |
| 551 |
|
| case XML_NOTATION_NODE : |
| 552 |
|
| case XML_NAMESPACE_DECL : |
| 553 |
9 |
| name = node->name; |
| 554 |
9 |
| break; |
| 555 |
|
| |
| 556 |
14 |
| case XML_COMMENT_NODE : |
| 557 |
14 |
| name = (const xmlChar *) "#comment"; |
| 558 |
14 |
| break; |
| 559 |
|
| |
| 560 |
16 |
| case XML_CDATA_SECTION_NODE : |
| 561 |
16 |
| name = (const xmlChar *) "#cdata-section"; |
| 562 |
16 |
| break; |
| 563 |
|
| |
| 564 |
55 |
| case XML_TEXT_NODE : |
| 565 |
55 |
| name = (const xmlChar *) "#text"; |
| 566 |
55 |
| break; |
| 567 |
|
| |
| 568 |
|
| |
| 569 |
1 |
| case XML_DOCUMENT_NODE : |
| 570 |
|
| case XML_HTML_DOCUMENT_NODE : |
| 571 |
|
| case XML_DOCB_DOCUMENT_NODE : |
| 572 |
1 |
| name = (const xmlChar *) "#document"; |
| 573 |
1 |
| break; |
| 574 |
|
| |
| 575 |
1 |
| case XML_DOCUMENT_FRAG_NODE : |
| 576 |
1 |
| name = (const xmlChar *) "#document-fragment"; |
| 577 |
1 |
| break; |
| 578 |
|
| |
| 579 |
158 |
| case XML_ELEMENT_NODE : |
| 580 |
|
| case XML_ATTRIBUTE_NODE : |
| 581 |
158 |
▶ | if ( node->ns != NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( node->ns != NULL ) { |
33 |
125 |
158 |
|
| 582 |
33 |
| prefix = node->ns->prefix; |
| 583 |
|
| } |
| 584 |
158 |
| name = node->name; |
| 585 |
158 |
| break; |
| 586 |
|
| |
| 587 |
0 |
| case XML_ELEMENT_DECL : |
| 588 |
0 |
| prefix = ((xmlElementPtr) node)->prefix; |
| 589 |
0 |
| name = node->name; |
| 590 |
0 |
| break; |
| 591 |
|
| |
| 592 |
0 |
| case XML_ATTRIBUTE_DECL : |
| 593 |
0 |
| prefix = ((xmlAttributePtr) node)->prefix; |
| 594 |
0 |
| name = node->name; |
| 595 |
0 |
| break; |
| 596 |
|
| } |
| 597 |
|
| |
| 598 |
254 |
▶ | if ( prefix != NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( prefix != NULL ) { |
21 |
233 |
254 |
|
| 599 |
21 |
| qname = xmlStrdup( prefix ); |
| 600 |
21 |
| qname = xmlStrcat( qname , (const xmlChar *) ":" ); |
| 601 |
21 |
| qname = xmlStrcat( qname , name ); |
| 602 |
|
| } |
| 603 |
|
| else { |
| 604 |
233 |
| qname = xmlStrdup( name ); |
| 605 |
|
| } |
| 606 |
|
| |
| 607 |
254 |
| return qname; |
| 608 |
|
| } |
| 609 |
|
| |
| 610 |
|
| /** |
| 611 |
|
| * Name: domAppendChild |
| 612 |
|
| * Synopsis: xmlNodePtr domAppendChild( xmlNodePtr par, xmlNodePtr newCld ); |
| 613 |
|
| * @par: the node to append to |
| 614 |
|
| * @newCld: the node to append |
| 615 |
|
| * |
| 616 |
|
| * Returns newCld on success otherwise NULL |
| 617 |
|
| * The function will unbind newCld first if nesseccary. As well the |
| 618 |
|
| * function will fail, if par or newCld is a Attribute Node OR if newCld |
| 619 |
|
| * is a parent of par. |
| 620 |
|
| * |
| 621 |
|
| * If newCld belongs to a different DOM the node will be imported |
| 622 |
|
| * implicit before it gets appended. |
| 623 |
|
| **/ |
| 624 |
|
| xmlNodePtr |
| 625 |
64 |
| domAppendChild( xmlNodePtr self, |
| 626 |
|
| xmlNodePtr newChild ){ |
| 627 |
64 |
| xmlNodePtr fragment = NULL; |
| 628 |
64 |
▶ | if ( self == NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( self == NULL ) { |
0 |
64 |
64 |
|
| 629 |
0 |
| return newChild; |
| 630 |
|
| } |
| 631 |
|
| |
| 632 |
127 |
| if ( !(domTestHierarchy(self, newChild) |
| 633 |
63 |
| && domTestDocument(self, newChild))){ |
| 634 |
1 |
| croak("appendChild: HIERARCHY_REQUEST_ERR\n"); |
| 635 |
|
| return NULL; |
| 636 |
|
| } |
| 637 |
|
| |
| 638 |
63 |
▶ | if ( newChild->doc == self->doc ){ |
Branch: 1 branch
| Branch | True | False | Total |
| if ( newChild->doc == self->doc ){ |
60 |
3 |
63 |
|
| 639 |
60 |
| domUnlinkNode( newChild ); |
| 640 |
|
| } |
| 641 |
|
| else { |
| 642 |
|
| xs_warn("WRONG_DOCUMENT_ERR - non conform implementation\n"); |
| 643 |
|
| /* xmlGenericError(xmlGenericErrorContext,"WRONG_DOCUMENT_ERR\n"); */ |
| 644 |
3 |
| newChild = domImportNode( self->doc, newChild, 1, 0 ); |
| 645 |
|
| } |
| 646 |
|
| |
| 647 |
63 |
▶ | if ( self->children != NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( self->children != NULL ) { |
25 |
38 |
63 |
|
| 648 |
25 |
▶ | if (newChild->type == XML_DOCUMENT_FRAG_NODE ) |
Branch: 1 branch
| Branch | True | False | Total |
| if (newChild->type == XML_DOCUMENT_FRAG_NODE ) |
2 |
23 |
25 |
|
| 649 |
2 |
| fragment = newChild->children; |
| 650 |
25 |
| domAddNodeToList( newChild, self->last, NULL ); |
| 651 |
|
| } |
| 652 |
38 |
▶ | else if (newChild->type == XML_DOCUMENT_FRAG_NODE ) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (newChild->type == XML_DOCUMENT_FRAG_NODE ) { |
2 |
36 |
38 |
|
| 653 |
2 |
| xmlNodePtr c1 = NULL; |
| 654 |
2 |
| self->children = newChild->children; |
| 655 |
2 |
| fragment = newChild->children; |
| 656 |
2 |
| c1 = fragment; |
| 657 |
3 |
▶ | while ( c1 ){ |
Branch: 1 branch
| Branch | True | False | Total |
| while ( c1 ){ |
1 |
2 |
3 |
|
| 658 |
1 |
| c1->parent = self; |
| 659 |
1 |
| c1 = c1->next; |
| 660 |
|
| } |
| 661 |
2 |
| self->last = newChild->last; |
| 662 |
2 |
| newChild->last = newChild->children = NULL; |
| 663 |
|
| } |
| 664 |
|
| else { |
| 665 |
36 |
| self->children = newChild; |
| 666 |
36 |
| self->last = newChild; |
| 667 |
36 |
| newChild->parent= self; |
| 668 |
|
| } |
| 669 |
|
| |
| 670 |
63 |
▶ | if ( fragment ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( fragment ) { |
3 |
60 |
63 |
|
| 671 |
|
| /* we must reconcile all nodes in the fragment */ |
| 672 |
3 |
| newChild = fragment; /* return the first node in the fragment */ |
| 673 |
8 |
▶ | while ( fragment ) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ( fragment ) { |
5 |
3 |
8 |
|
| 674 |
5 |
| domReconcileNs(fragment); |
| 675 |
5 |
| fragment = fragment->next; |
| 676 |
|
| } |
| 677 |
|
| } |
| 678 |
60 |
▶ | else if ( newChild->type != XML_ENTITY_REF_NODE ) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if ( newChild->type != XML_ENTITY_REF_NODE ) { |
59 |
1 |
60 |
|
| 679 |
59 |
| domReconcileNs(newChild); |
| 680 |
|
| } |
| 681 |
|
| |
| 682 |
63 |
| return newChild; |
| 683 |
|
| } |
| 684 |
|
| |
| 685 |
|
| xmlNodePtr |
| 686 |
17 |
| domRemoveChild( xmlNodePtr self, xmlNodePtr old ) { |
| 687 |
17 |
▶ | if ( self == NULL || old == NULL ) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ( self == NULL || old == NULL ) { |
17 |
0 |
17 |
| if ( self == NULL || old == NULL ) { |
0 |
17 |
17 |
|
| 688 |
0 |
| return NULL; |
| 689 |
|
| } |
| 690 |
17 |
▶ | if ( old->type == XML_ATTRIBUTE_NODE |
Branch: 1 branch
| Branch | True | False | Total |
| if ( old->type == XML_ATTRIBUTE_NODE |
17 |
0 |
17 |
|
| 691 |
17 |
▶ | || old->type == XML_NAMESPACE_DECL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| || old->type == XML_NAMESPACE_DECL ) { |
0 |
17 |
17 |
|
| 692 |
0 |
| return NULL; |
| 693 |
|
| } |
| 694 |
17 |
▶ | if ( self != old->parent ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( self != old->parent ) { |
1 |
16 |
17 |
|
| 695 |
|
| /* not a child! */ |
| 696 |
1 |
| return NULL; |
| 697 |
|
| } |
| 698 |
|
| |
| 699 |
16 |
| domUnlinkNode( old ); |
| 700 |
16 |
▶ | if ( old->type == XML_ELEMENT_NODE ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( old->type == XML_ELEMENT_NODE ) { |
15 |
1 |
16 |
|
| 701 |
15 |
| domReconcileNs( old ); |
| 702 |
|
| } |
| 703 |
|
| |
| 704 |
16 |
| return old ; |
| 705 |
|
| } |
| 706 |
|
| |
| 707 |
|
| xmlNodePtr |
| 708 |
9 |
| domReplaceChild( xmlNodePtr self, xmlNodePtr new, xmlNodePtr old ) { |
| 709 |
9 |
| xmlNodePtr fragment = NULL; |
| 710 |
9 |
| xmlNodePtr fragment_next = NULL; |
| 711 |
9 |
▶ | if ( self== NULL ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( self== NULL ) |
0 |
9 |
9 |
|
| 712 |
0 |
| return NULL; |
| 713 |
|
| |
| 714 |
9 |
▶ | if ( new == old ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( new == old ) |
0 |
9 |
9 |
|
| 715 |
0 |
| return NULL; |
| 716 |
|
| |
| 717 |
9 |
▶ | if ( new == NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( new == NULL ) { |
0 |
9 |
9 |
|
| 718 |
|
| /* level2 sais nothing about this case :( */ |
| 719 |
0 |
| return domRemoveChild( self, old ); |
| 720 |
|
| } |
| 721 |
|
| |
| 722 |
9 |
▶ | if ( old == NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( old == NULL ) { |
0 |
9 |
9 |
|
| 723 |
0 |
| domAppendChild( self, new ); |
| 724 |
0 |
| return old; |
| 725 |
|
| } |
| 726 |
|
| |
| 727 |
18 |
| if ( !(domTestHierarchy(self, new) |
| 728 |
9 |
| && domTestDocument(self, new))){ |
| 729 |
0 |
| croak("replaceChild: HIERARCHY_REQUEST_ERR\n"); |
| 730 |
|
| return NULL; |
| 731 |
|
| } |
| 732 |
|
| |
| 733 |
9 |
▶ | if ( new->doc == self->doc ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( new->doc == self->doc ) { |
3 |
6 |
9 |
|
| 734 |
3 |
| domUnlinkNode( new ); |
| 735 |
|
| } |
| 736 |
|
| else { |
| 737 |
|
| /* WRONG_DOCUMENT_ERR - non conform implementation */ |
| 738 |
6 |
| new = domImportNode( self->doc, new, 1, 1 ); |
| 739 |
|
| } |
| 740 |
|
| |
| 741 |
9 |
▶ | if( old == self->children && old == self->last ) { |
Branch: 2 branches
| Branch | True | False | Total |
| if( old == self->children && old == self->last ) { |
5 |
4 |
9 |
| if( old == self->children && old == self->last ) { |
2 |
3 |
5 |
|
| 742 |
2 |
| domRemoveChild( self, old ); |
| 743 |
2 |
| domAppendChild( self, new ); |
| 744 |
|
| } |
| 745 |
7 |
▶ | else if ( new->type == XML_DOCUMENT_FRAG_NODE |
Branch: 1 branch
| Branch | True | False | Total |
| else if ( new->type == XML_DOCUMENT_FRAG_NODE |
1 |
6 |
7 |
|
| 746 |
1 |
▶ | && new->children == NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| && new->children == NULL ) { |
0 |
1 |
1 |
|
| 747 |
|
| /* want to replace with an empty fragment, then remove ... */ |
| 748 |
0 |
| fragment = new->children; |
| 749 |
0 |
| fragment_next = old->next; |
| 750 |
0 |
| domRemoveChild( self, old ); |
| 751 |
|
| } |
| 752 |
|
| else { |
| 753 |
7 |
| domAddNodeToList(new, old->prev, old->next ); |
| 754 |
7 |
| old->parent = old->next = old->prev = NULL; |
| 755 |
|
| } |
| 756 |
9 |
▶ | if ( fragment ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( fragment ) { |
0 |
9 |
9 |
|
| 757 |
0 |
▶ | while ( fragment && fragment != fragment_next ) { |
Branch: 2 branches
| Branch | True | False | Total |
| while ( fragment && fragment != fragment_next ) { |
0 |
0 |
0 |
| while ( fragment && fragment != fragment_next ) { |
0 |
0 |
0 |
|
| 758 |
0 |
| domReconcileNs(fragment); |
| 759 |
0 |
| fragment = fragment->next; |
| 760 |
|
| } |
| 761 |
9 |
▶ | } else if ( new->type != XML_ENTITY_REF_NODE ) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if ( new->type != XML_ENTITY_REF_NODE ) { |
9 |
0 |
9 |
|
| 762 |
9 |
| domReconcileNs(new); |
| 763 |
|
| } |
| 764 |
|
| |
| 765 |
9 |
| return old; |
| 766 |
|
| } |
| 767 |
|
| |
| 768 |
|
| |
| 769 |
|
| xmlNodePtr |
| 770 |
15 |
| domInsertBefore( xmlNodePtr self, |
| 771 |
|
| xmlNodePtr newChild, |
| 772 |
|
| xmlNodePtr refChild ){ |
| 773 |
15 |
| xmlNodePtr fragment = NULL; |
| 774 |
15 |
▶ | if ( refChild == newChild ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( refChild == newChild ) { |
0 |
15 |
15 |
|
| 775 |
0 |
| return newChild; |
| 776 |
|
| } |
| 777 |
|
| |
| 778 |
15 |
▶ | if ( self == NULL || newChild == NULL ) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ( self == NULL || newChild == NULL ) { |
15 |
0 |
15 |
| if ( self == NULL || newChild == NULL ) { |
0 |
15 |
15 |
|
| 779 |
0 |
| return NULL; |
| 780 |
|
| } |
| 781 |
|
| |
| 782 |
15 |
▶ | if ( refChild != NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( refChild != NULL ) { |
10 |
5 |
15 |
|
| 783 |
10 |
▶ | if ( refChild->parent != self |
Branch: 1 branch
| Branch | True | False | Total |
| if ( refChild->parent != self |
10 |
0 |
10 |
|
| 784 |
10 |
▶ | || ( newChild->type == XML_DOCUMENT_FRAG_NODE |
Branch: 1 branch
| Branch | True | False | Total |
| || ( newChild->type == XML_DOCUMENT_FRAG_NODE |
3 |
7 |
10 |
|
| 785 |
3 |
▶ | && newChild->children == NULL ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| && newChild->children == NULL ) ) { |
0 |
3 |
3 |
|
| 786 |
|
| /* NOT_FOUND_ERR */ |
| 787 |
0 |
| xmlGenericError(xmlGenericErrorContext,"NOT_FOUND_ERR\n"); |
| 788 |
0 |
| return NULL; |
| 789 |
|
| } |
| 790 |
|
| } |
| 791 |
|
| |
| 792 |
15 |
▶ | if ( self->children == NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( self->children == NULL ) { |
2 |
13 |
15 |
|
| 793 |
2 |
| return domAppendChild( self, newChild ); |
| 794 |
|
| } |
| 795 |
|
| |
| 796 |
26 |
| if ( !(domTestHierarchy( self, newChild ) |
| 797 |
13 |
| && domTestDocument( self, newChild ))) { |
| 798 |
1 |
| croak("insertBefore/insertAfter: HIERARCHY_REQUEST_ERR\n"); |
| 799 |
|
| return NULL; |
| 800 |
|
| } |
| 801 |
|
| |
| 802 |
12 |
▶ | if ( self->doc == newChild->doc ){ |
Branch: 1 branch
| Branch | True | False | Total |
| if ( self->doc == newChild->doc ){ |
8 |
4 |
12 |
|
| 803 |
8 |
| domUnlinkNode( newChild ); |
| 804 |
|
| } |
| 805 |
|
| else { |
| 806 |
4 |
| newChild = domImportNode( self->doc, newChild, 1, 0 ); |
| 807 |
|
| } |
| 808 |
|
| |
| 809 |
12 |
▶ | if ( newChild->type == XML_DOCUMENT_FRAG_NODE ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( newChild->type == XML_DOCUMENT_FRAG_NODE ) { |
3 |
9 |
12 |
|
| 810 |
3 |
| fragment = newChild->children; |
| 811 |
|
| } |
| 812 |
12 |
▶ | if ( refChild == NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( refChild == NULL ) { |
3 |
9 |
12 |
|
| 813 |
3 |
| domAddNodeToList(newChild, self->last, NULL); |
| 814 |
|
| } |
| 815 |
|
| else { |
| 816 |
9 |
| domAddNodeToList(newChild, refChild->prev, refChild); |
| 817 |
|
| } |
| 818 |
|
| |
| 819 |
12 |
▶ | if ( fragment ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( fragment ) { |
3 |
9 |
12 |
|
| 820 |
3 |
| newChild = fragment; /* return the first node in the fragment */ |
| 821 |
9 |
▶ | while ( fragment && fragment != refChild ) { |
Branch: 2 branches
| Branch | True | False | Total |
| while ( fragment && fragment != refChild ) { |
9 |
0 |
9 |
| while ( fragment && fragment != refChild ) { |
6 |
3 |
9 |
|
| 822 |
6 |
| domReconcileNs(fragment); |
| 823 |
6 |
| fragment = fragment->next; |
| 824 |
|
| } |
| 825 |
9 |
▶ | } else if ( newChild->type != XML_ENTITY_REF_NODE ) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if ( newChild->type != XML_ENTITY_REF_NODE ) { |
9 |
0 |
9 |
|
| 826 |
9 |
| domReconcileNs(newChild); |
| 827 |
|
| } |
| 828 |
|
| |
| 829 |
12 |
| return newChild; |
| 830 |
|
| } |
| 831 |
|
| |
| 832 |
|
| /* |
| 833 |
|
| * this function does not exist in the spec although it's useful |
| 834 |
|
| */ |
| 835 |
|
| xmlNodePtr |
| 836 |
6 |
| domInsertAfter( xmlNodePtr self, |
| 837 |
|
| xmlNodePtr newChild, |
| 838 |
|
| xmlNodePtr refChild ){ |
| 839 |
6 |
▶ | if ( refChild == NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( refChild == NULL ) { |
2 |
4 |
6 |
|
| 840 |
2 |
| return domInsertBefore( self, newChild, NULL ); |
| 841 |
|
| } |
| 842 |
4 |
| return domInsertBefore( self, newChild, refChild->next ); |
| 843 |
|
| } |
| 844 |
|
| |
| 845 |
|
| xmlNodePtr |
| 846 |
0 |
| domReplaceNode( xmlNodePtr oldNode, xmlNodePtr newNode ) { |
| 847 |
0 |
| xmlNodePtr prev = NULL, next = NULL, par = NULL, fragment = NULL; |
| 848 |
|
| |
| 849 |
0 |
▶ | if ( oldNode == NULL |
Branch: 1 branch
| Branch | True | False | Total |
| if ( oldNode == NULL |
0 |
0 |
0 |
|
| 850 |
0 |
▶ | || newNode == NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| || newNode == NULL ) { |
0 |
0 |
0 |
|
| 851 |
|
| /* NOT_FOUND_ERROR */ |
| 852 |
0 |
| return NULL; |
| 853 |
|
| } |
| 854 |
|
| |
| 855 |
0 |
▶ | if ( oldNode->type == XML_ATTRIBUTE_NODE |
Branch: 1 branch
| Branch | True | False | Total |
| if ( oldNode->type == XML_ATTRIBUTE_NODE |
0 |
0 |
0 |
|
| 856 |
0 |
▶ | || newNode->type == XML_ATTRIBUTE_NODE |
Branch: 1 branch
| Branch | True | False | Total |
| || newNode->type == XML_ATTRIBUTE_NODE |
0 |
0 |
0 |
|
| 857 |
0 |
▶ | || newNode->type == XML_DOCUMENT_NODE |
Branch: 1 branch
| Branch | True | False | Total |
| || newNode->type == XML_DOCUMENT_NODE |
0 |
0 |
0 |
|
| 858 |
0 |
▶ | || domIsParent( newNode, oldNode ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| || domIsParent( newNode, oldNode ) ) { |
0 |
0 |
0 |
|
| 859 |
|
| /* HIERARCHY_REQUEST_ERR |
| 860 |
|
| * wrong node type |
| 861 |
|
| * new node is parent of itself |
| 862 |
|
| */ |
| 863 |
0 |
| croak("replaceNode: HIERARCHY_REQUEST_ERR\n"); |
| 864 |
|
| return NULL; |
| 865 |
|
| } |
| 866 |
|
| |
| 867 |
0 |
| par = oldNode->parent; |
| 868 |
0 |
| prev = oldNode->prev; |
| 869 |
0 |
| next = oldNode->next; |
| 870 |
|
| |
| 871 |
0 |
▶ | if ( oldNode->_private == NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( oldNode->_private == NULL ) { |
0 |
0 |
0 |
|
| 872 |
0 |
| xmlUnlinkNode( oldNode ); |
| 873 |
|
| } |
| 874 |
|
| else { |
| 875 |
0 |
| domUnlinkNode( oldNode ); |
| 876 |
|
| } |
| 877 |
|
| |
| 878 |
0 |
▶ | if ( newNode->type == XML_DOCUMENT_FRAG_NODE ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( newNode->type == XML_DOCUMENT_FRAG_NODE ) { |
0 |
0 |
0 |
|
| 879 |
0 |
| fragment = newNode->children; |
| 880 |
|
| } |
| 881 |
0 |
▶ | if( prev == NULL && next == NULL ) { |
Branch: 2 branches
| Branch | True | False | Total |
| if( prev == NULL && next == NULL ) { |
0 |
0 |
0 |
| if( prev == NULL && next == NULL ) { |
0 |
0 |
0 |
|
| 882 |
|
| /* oldNode was the only child */ |
| 883 |
0 |
| domAppendChild( par , newNode ); |
| 884 |
|
| } |
| 885 |
|
| else { |
| 886 |
0 |
| domAddNodeToList( newNode, prev, next ); |
| 887 |
|
| } |
| 888 |
|
| |
| 889 |
0 |
▶ | if ( fragment ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( fragment ) { |
0 |
0 |
0 |
|
| 890 |
0 |
▶ | while ( fragment && fragment != next ) { |
Branch: 2 branches
| Branch | True | False | Total |
| while ( fragment && fragment != next ) { |
0 |
0 |
0 |
| while ( fragment && fragment != next ) { |
0 |
0 |
0 |
|
| 891 |
0 |
| domReconcileNs(fragment); |
| 892 |
0 |
| fragment = fragment->next; |
| 893 |
|
| } |
| 894 |
0 |
▶ | } else if ( newNode->type != XML_ENTITY_REF_NODE ) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if ( newNode->type != XML_ENTITY_REF_NODE ) { |
0 |
0 |
0 |
|
| 895 |
0 |
| domReconcileNs(newNode); |
| 896 |
|
| } |
| 897 |
|
| |
| 898 |
0 |
| return oldNode; |
| 899 |
|
| } |
| 900 |
|
| |
| 901 |
|
| xmlChar* |
| 902 |
192 |
| domGetNodeValue( xmlNodePtr n ) { |
| 903 |
192 |
| xmlChar * retval = NULL; |
| 904 |
192 |
▶ | if( n != NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( n != NULL ) { |
192 |
0 |
192 |
|
| 905 |
192 |
▶ | switch ( n->type ) { |
Branch: 1 branch
| Branch | True | False | Total |
| switch ( n->type ) { |
190 |
2 |
192 |
|
| 906 |
190 |
| case XML_ATTRIBUTE_NODE: |
| 907 |
|
| case XML_ENTITY_DECL: |
| 908 |
|
| case XML_TEXT_NODE: |
| 909 |
|
| case XML_COMMENT_NODE: |
| 910 |
|
| case XML_CDATA_SECTION_NODE: |
| 911 |
|
| case XML_PI_NODE: |
| 912 |
|
| case XML_ENTITY_REF_NODE: |
| 913 |
190 |
| break; |
| 914 |
2 |
| default: |
| 915 |
2 |
| return retval; |
| 916 |
|
| break; |
| 917 |
|
| } |
| 918 |
190 |
▶ | if ( n->type != XML_ENTITY_DECL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( n->type != XML_ENTITY_DECL ) { |
189 |
1 |
190 |
|
| 919 |
189 |
| retval = xmlXPathCastNodeToString(n); |
| 920 |
|
| } |
| 921 |
|
| else { |
| 922 |
1 |
▶ | if ( n->content != NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( n->content != NULL ) { |
1 |
0 |
1 |
|
| 923 |
|
| xs_warn(" dublicate content\n" ); |
| 924 |
1 |
| retval = xmlStrdup(n->content); |
| 925 |
|
| } |
| 926 |
0 |
▶ | else if ( n->children != NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if ( n->children != NULL ) { |
0 |
0 |
0 |
|
| 927 |
0 |
| xmlNodePtr cnode = n->children; |
| 928 |
|
| xs_warn(" use child content\n" ); |
| 929 |
|
| /* ok then toString in this case ... */ |
| 930 |
0 |
▶ | while (cnode) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (cnode) { |
0 |
0 |
0 |
|
| 931 |
0 |
| xmlBufferPtr buffer = xmlBufferCreate(); |
| 932 |
|
| /* buffer = xmlBufferCreate(); */ |
| 933 |
0 |
| xmlNodeDump( buffer, n->doc, cnode, 0, 0 ); |
| 934 |
0 |
▶ | if ( buffer->content != NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( buffer->content != NULL ) { |
0 |
0 |
0 |
|
| 935 |
|
| xs_warn( "add item" ); |
| 936 |
0 |
▶ | if ( retval != NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( retval != NULL ) { |
0 |
0 |
0 |
|
| 937 |
0 |
| retval = xmlStrcat( retval, buffer->content ); |
| 938 |
|
| } |
| 939 |
|
| else { |
| 940 |
0 |
| retval = xmlStrdup( buffer->content ); |
| 941 |
|
| } |
| 942 |
|
| } |
| 943 |
0 |
| xmlBufferFree( buffer ); |
| 944 |
0 |
| cnode = cnode->next; |
| 945 |
|
| } |
| 946 |
|
| } |
| 947 |
|
| } |
| 948 |
|
| } |
| 949 |
|
| |
| 950 |
190 |
| return retval; |
| 951 |
|
| } |
| 952 |
|
| |
| 953 |
|
| void |
| 954 |
60 |
| domSetNodeValue( xmlNodePtr n , xmlChar* val ){ |
| 955 |
60 |
▶ | if ( n == NULL ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( n == NULL ) |
0 |
60 |
60 |
|
| 956 |
0 |
| return; |
| 957 |
60 |
▶ | if ( val == NULL ){ |
Branch: 1 branch
| Branch | True | False | Total |
| if ( val == NULL ){ |
0 |
60 |
60 |
|
| 958 |
0 |
| val = (xmlChar *) ""; |
| 959 |
|
| } |
| 960 |
|
| |
| 961 |
60 |
▶ | if( n->type == XML_ATTRIBUTE_NODE ){ |
Branch: 1 branch
| Branch | True | False | Total |
| if( n->type == XML_ATTRIBUTE_NODE ){ |
1 |
59 |
60 |
|
| 962 |
|
| /* can't use xmlNodeSetContent - for Attrs it parses entities */ |
| 963 |
1 |
▶ | if ( n->children != NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( n->children != NULL ) { |
1 |
0 |
1 |
|
| 964 |
1 |
| n->last = NULL; |
| 965 |
1 |
| xmlFreeNodeList( n->children ); |
| 966 |
|
| } |
| 967 |
1 |
| n->children = xmlNewText( val ); |
| 968 |
1 |
| n->children->parent = n; |
| 969 |
1 |
| n->children->doc = n->doc; |
| 970 |
1 |
| n->last = n->children; |
| 971 |
|
| } |
| 972 |
|
| else { |
| 973 |
59 |
| xmlNodeSetContent( n, val ); |
| 974 |
|
| } |
| 975 |
|
| } |
| 976 |
|
| |
| 977 |
|
| |
| 978 |
|
| xmlNodeSetPtr |
| 979 |
0 |
| domGetElementsByTagName( xmlNodePtr n, xmlChar* name ){ |
| 980 |
0 |
| xmlNodeSetPtr rv = NULL; |
| 981 |
0 |
| xmlNodePtr cld = NULL; |
| 982 |
|
| |
| 983 |
0 |
▶ | if ( n != NULL && name != NULL ) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ( n != NULL && name != NULL ) { |
0 |
0 |
0 |
| if ( n != NULL && name != NULL ) { |
0 |
0 |
0 |
|
| 984 |
0 |
| cld = n->children; |
| 985 |
0 |
▶ | while ( cld != NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ( cld != NULL ) { |
0 |
0 |
0 |
|
| 986 |
0 |
▶ | if ( xmlStrcmp( name, cld->name ) == 0 ){ |
Branch: 1 branch
| Branch | True | False | Total |
| if ( xmlStrcmp( name, cld->name ) == 0 ){ |
0 |
0 |
0 |
|
| 987 |
0 |
▶ | if ( rv == NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( rv == NULL ) { |
0 |
0 |
0 |
|
| 988 |
0 |
| rv = xmlXPathNodeSetCreate( cld ) ; |
| 989 |
|
| } |
| 990 |
|
| else { |
| 991 |
0 |
| xmlXPathNodeSetAdd( rv, cld ); |
| 992 |
|
| } |
| 993 |
|
| } |
| 994 |
0 |
| cld = cld->next; |
| 995 |
|
| } |
| 996 |
|
| } |
| 997 |
|
| |
| 998 |
0 |
| return rv; |
| 999 |
|
| } |
| 1000 |
|
| |
| 1001 |
|
| |
| 1002 |
|
| xmlNodeSetPtr |
| 1003 |
0 |
| domGetElementsByTagNameNS( xmlNodePtr n, xmlChar* nsURI, xmlChar* name ){ |
| 1004 |
0 |
| xmlNodeSetPtr rv = NULL; |
| 1005 |
|
| |
| 1006 |
0 |
▶ | if ( nsURI == NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( nsURI == NULL ) { |
0 |
0 |
0 |
|
| 1007 |
0 |
| return domGetElementsByTagName( n, name ); |
| 1008 |
|
| } |
| 1009 |
|
| |
| 1010 |
0 |
▶ | if ( n != NULL && name != NULL ) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ( n != NULL && name != NULL ) { |
0 |
0 |
0 |
| if ( n != NULL && name != NULL ) { |
0 |
0 |
0 |
|
| 1011 |
0 |
| xmlNodePtr cld = n->children; |
| 1012 |
0 |
▶ | while ( cld != NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ( cld != NULL ) { |
0 |
0 |
0 |
|
| 1013 |
0 |
▶ | if ( xmlStrcmp( name, cld->name ) == 0 |
Branch: 1 branch
| Branch | True | False | Total |
| if ( xmlStrcmp( name, cld->name ) == 0 |
0 |
0 |
0 |
|
| 1014 |
0 |
▶ | && cld->ns != NULL |
Branch: 1 branch
| Branch | True | False | Total |
| && cld->ns != NULL |
0 |
0 |
0 |
|
| 1015 |
0 |
▶ | && xmlStrcmp( nsURI, cld->ns->href ) == 0 ){ |
Branch: 1 branch
| Branch | True | False | Total |
| && xmlStrcmp( nsURI, cld->ns->href ) == 0 ){ |
0 |
0 |
0 |
|
| 1016 |
0 |
▶ | if ( rv == NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( rv == NULL ) { |
0 |
0 |
0 |
|
| 1017 |
0 |
| rv = xmlXPathNodeSetCreate( cld ) ; |
| 1018 |
|
| } |
| 1019 |
|
| else { |
| 1020 |
0 |
| xmlXPathNodeSetAdd( rv, cld ); |
| 1021 |
|
| } |
| 1022 |
|
| } |
| 1023 |
0 |
| cld = cld->next; |
| 1024 |
|
| } |
| 1025 |
|
| } |
| 1026 |
|
| |
| 1027 |
0 |
| return rv; |
| 1028 |
|
| } |
| 1029 |
|
| |
| 1030 |
|
| xmlNsPtr |
| 1031 |
0 |
| domNewNs ( xmlNodePtr elem , xmlChar *prefix, xmlChar *href ) { |
| 1032 |
0 |
| xmlNsPtr ns = NULL; |
| 1033 |
|
| |
| 1034 |
0 |
▶ | if (elem != NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (elem != NULL) { |
0 |
0 |
0 |
|
| 1035 |
0 |
| ns = xmlSearchNs( elem->doc, elem, prefix ); |
| 1036 |
|
| } |
| 1037 |
|
| /* prefix is not in use */ |
| 1038 |
0 |
▶ | if (ns == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ns == NULL) { |
0 |
0 |
0 |
|
| 1039 |
0 |
| ns = xmlNewNs( elem , href , prefix ); |
| 1040 |
|
| } else { |
| 1041 |
|
| /* prefix is in use; if it has same URI, let it go, otherwise it's |
| 1042 |
|
| an error */ |
| 1043 |
0 |
▶ | if (!xmlStrEqual(href, ns->href)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!xmlStrEqual(href, ns->href)) { |
0 |
0 |
0 |
|
| 1044 |
0 |
| ns = NULL; |
| 1045 |
|
| } |
| 1046 |
|
| } |
| 1047 |
0 |
| return ns; |
| 1048 |
|
| } |
| 1049 |
|
| |
| 1050 |
|
| xmlAttrPtr |
| 1051 |
66 |
| domGetAttrNode(xmlNodePtr node, const xmlChar *qname) { |
| 1052 |
66 |
| xmlChar * prefix = NULL; |
| 1053 |
66 |
| xmlChar * localname = NULL; |
| 1054 |
66 |
| xmlAttrPtr ret = NULL; |
| 1055 |
66 |
| xmlNsPtr ns = NULL; |
| 1056 |
|
| |
| 1057 |
66 |
▶ | if ( qname == NULL || node == NULL ) |
Branch: 2 branches
| Branch | True | False | Total |
| if ( qname == NULL || node == NULL ) |
66 |
0 |
66 |
| if ( qname == NULL || node == NULL ) |
0 |
66 |
66 |
|
| 1058 |
0 |
| return NULL; |
| 1059 |
|
| |
| 1060 |
|
| /* first try qname without namespace */ |
| 1061 |
66 |
| ret = xmlHasNsProp(node, qname, NULL); |
| 1062 |
66 |
▶ | if ( ret == NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( ret == NULL ) { |
30 |
36 |
66 |
|
| 1063 |
30 |
| localname = xmlSplitQName2(qname, &prefix); |
| 1064 |
30 |
▶ | if ( localname != NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( localname != NULL ) { |
16 |
14 |
30 |
|
| 1065 |
16 |
| ns = xmlSearchNs( node->doc, node, prefix ); |
| 1066 |
16 |
▶ | if ( ns != NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( ns != NULL ) { |
15 |
1 |
16 |
|
| 1067 |
|
| /* then try localname with the namespace bound to prefix */ |
| 1068 |
15 |
| ret = xmlHasNsProp( node, localname, ns->href ); |
| 1069 |
|
| } |
| 1070 |
16 |
▶ | if ( prefix != NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( prefix != NULL) { |
16 |
0 |
16 |
|
| 1071 |
16 |
| xmlFree( prefix ); |
| 1072 |
|
| } |
| 1073 |
16 |
| xmlFree( localname ); |
| 1074 |
|
| } |
| 1075 |
|
| } |
| 1076 |
66 |
▶ | if (ret && ret->type != XML_ATTRIBUTE_NODE) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (ret && ret->type != XML_ATTRIBUTE_NODE) { |
51 |
15 |
66 |
| if (ret && ret->type != XML_ATTRIBUTE_NODE) { |
8 |
43 |
51 |
|
| 1077 |
8 |
| return NULL; /* we don't want fixed attribute decls */ |
| 1078 |
|
| } |
| 1079 |
|
| else { |
| 1080 |
58 |
| return ret; |
| 1081 |
|
| } |
| 1082 |
|
| } |
| 1083 |
|
| |
| 1084 |
|
| xmlAttrPtr |
| 1085 |
0 |
| domSetAttributeNode( xmlNodePtr node, xmlAttrPtr attr ) { |
| 1086 |
0 |
▶ | if ( node == NULL || attr == NULL ) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ( node == NULL || attr == NULL ) { |
0 |
0 |
0 |
| if ( node == NULL || attr == NULL ) { |
0 |
0 |
0 |
|
| 1087 |
0 |
| return attr; |
| 1088 |
|
| } |
| 1089 |
0 |
▶ | if ( attr != NULL && attr->type != XML_ATTRIBUTE_NODE ) |
Branch: 2 branches
| Branch | True | False | Total |
| if ( attr != NULL && attr->type != XML_ATTRIBUTE_NODE ) |
0 |
0 |
0 |
| if ( attr != NULL && attr->type != XML_ATTRIBUTE_NODE ) |
0 |
0 |
0 |
|
| 1090 |
0 |
| return NULL; |
| 1091 |
0 |
▶ | if ( node == attr->parent ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( node == attr->parent ) { |
0 |
0 |
0 |
|
| 1092 |
0 |
| return attr; /* attribute is already part of the node */ |
| 1093 |
|
| } |
| 1094 |
0 |
▶ | if ( attr->doc != node->doc ){ |
Branch: 1 branch
| Branch | True | False | Total |
| if ( attr->doc != node->doc ){ |
0 |
0 |
0 |
|
| 1095 |
0 |
| attr = (xmlAttrPtr) domImportNode( node->doc, (xmlNodePtr) attr, 1, 1 ); |
| 1096 |
|
| } |
| 1097 |
|
| else { |
| 1098 |
0 |
| xmlUnlinkNode( (xmlNodePtr) attr ); |
| 1099 |
|
| } |
| 1100 |
|
| |
| 1101 |
|
| /* stolen from libxml2 */ |
| 1102 |
0 |
▶ | if ( attr != NULL ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( attr != NULL ) { |
0 |
0 |
0 |
|
| 1103 |
0 |
▶ | if (node->properties == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (node->properties == NULL) { |
0 |
0 |
0 |
|
| 1104 |
0 |
| node->properties = attr; |
| 1105 |
|
| } else { |
| 1106 |
0 |
| xmlAttrPtr prev = node->properties; |
| 1107 |
|
| |
| 1108 |
0 |
▶ | while (prev->next != NULL) prev = prev->next; |
Branch: 1 branch
| Branch | True | False | Total |
| while (prev->next != NULL) prev = prev->next; |
0 |
0 |
0 |
|
| 1109 |
0 |
| prev->next = attr; |
| 1110 |
0 |
| attr->prev = prev; |
| 1111 |
|
| } |
| 1112 |
|
| } |
| 1113 |
|
| |
| 1114 |
0 |
| return attr; |
| 1115 |
|
| } |
| 1116 |
|
| |
| 1117 |
|
| void |
| 1118 |
14 |
| domAttrSerializeContent(xmlBufferPtr buffer, xmlAttrPtr attr) |
| 1119 |
|
| { |
| 1120 |
|
| xmlNodePtr children; |
| 1121 |
|
| |
| 1122 |
14 |
| children = attr->children; |
| 1123 |
38 |
▶ | while (children != NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (children != NULL) { |
24 |
14 |
38 |
|
| 1124 |
24 |
| switch (children->type) { |
| 1125 |
19 |
| case XML_TEXT_NODE: |
| 1126 |
19 |
| xmlAttrSerializeTxtContent(buffer, attr->doc, |
| 1127 |
19 |
| attr, children->content); |
| 1128 |
19 |
| break; |
| 1129 |
5 |
| case XML_ENTITY_REF_NODE: |
| 1130 |
5 |
| xmlBufferAdd(buffer, BAD_CAST "&", 1); |
| 1131 |
5 |
| xmlBufferAdd(buffer, children->name, |
| 1132 |
|
| xmlStrlen(children->name)); |
| 1133 |
5 |
| xmlBufferAdd(buffer, BAD_CAST ";", 1); |
| 1134 |
5 |
| break; |
| 1135 |
0 |
| default: |
| 1136 |
|
| /* should not happen unless we have a badly built tree */ |
| 1137 |
0 |
| break; |
| 1138 |
|
| } |
| 1139 |
24 |
| children = children->next; |
| 1140 |
|
| } |
| 1141 |
14 |
| } |
| 1142 |
|
| |
| 1143 |
|
| |
| 1144 |
|
| int |
| 1145 |
|
| domNodeNormalize( xmlNodePtr node ); |
| 1146 |
|
| |
| 1147 |
|
| int |
| 1148 |
16 |
| domNodeNormalizeList( xmlNodePtr nodelist ) |
| 1149 |
|
| { |
| 1150 |
25 |
▶ | while ( nodelist ){ |
Branch: 1 branch
| Branch | True | False | Total |
| while ( nodelist ){ |
9 |
16 |
25 |
|
| 1151 |
9 |
▶ | if ( domNodeNormalize( nodelist ) == 0 ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( domNodeNormalize( nodelist ) == 0 ) |
0 |
9 |
9 |
|
| 1152 |
0 |
| return(0); |
| 1153 |
9 |
| nodelist = nodelist->next; |
| 1154 |
|
| } |
| 1155 |
16 |
| return(1); |
| 1156 |
|
| } |
| 1157 |
|
| |
| 1158 |
|
| int |
| 1159 |
12 |
| domNodeNormalize( xmlNodePtr node ) |
| 1160 |
|
| { |
| 1161 |
12 |
| xmlNodePtr next = NULL; |
| 1162 |
|
| |
| 1163 |
12 |
▶ | if ( node == NULL ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( node == NULL ) |
0 |
12 |
12 |
|
| 1164 |
0 |
| return(0); |
| 1165 |
|
| |
| 1166 |
12 |
| switch ( node->type ) { |
| 1167 |
3 |
| case XML_TEXT_NODE: |
| 1168 |
3 |
| while ( node->next |
| 1169 |
8 |
▶ | && node->next->type == XML_TEXT_NODE ) { |
Branch: 2 branches
| Branch | True | False | Total |
| && node->next->type == XML_TEXT_NODE ) { |
5 |
3 |
8 |
| && node->next->type == XML_TEXT_NODE ) { |
5 |
0 |
5 |
|
| 1170 |
5 |
| next = node->next; |
| 1171 |
5 |
| xmlNodeAddContent(node, next->content); |
| 1172 |
5 |
| xmlUnlinkNode( next ); |
| 1173 |
|
| |
| 1174 |
|
| /** |
| 1175 |
|
| * keep only nodes that are referred by perl (or GDOME) |
| 1176 |
|
| */ |
| 1177 |
5 |
▶ | if ( !next->_private ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( !next->_private ) |
5 |
0 |
5 |
|
| 1178 |
0 |
| xmlFreeNode( next ); |
| 1179 |
|
| } |
| 1180 |
3 |
| break; |
| 1181 |
7 |
| case XML_ELEMENT_NODE: |
| 1182 |
7 |
| domNodeNormalizeList( (xmlNodePtr) node->properties ); |
| 1183 |
9 |
| case XML_ATTRIBUTE_NODE: |
| 1184 |
|
| case XML_DOCUMENT_NODE: |
| 1185 |
9 |
| return( domNodeNormalizeList( node->children ) ); |
| 1186 |
|
| break; |
| 1187 |
0 |
| default: |
| 1188 |
0 |
| break; |
| 1189 |
|
| } |
| 1190 |
3 |
| return(1); |
| 1191 |
|
| } |
| 1192 |
|
| |
| 1193 |
|
| int |
| 1194 |
3 |
| domRemoveNsRefs(xmlNodePtr tree, xmlNsPtr ns) { |
| 1195 |
|
| xmlAttrPtr attr; |
| 1196 |
3 |
| xmlNodePtr node = tree; |
| 1197 |
|
| |
| 1198 |
3 |
▶ | if ((node == NULL) || (node->type != XML_ELEMENT_NODE)) return(0); |
Branch: 2 branches
| Branch | True | False | Total |
| if ((node == NULL) || (node->type != XML_ELEMENT_NODE)) return(0); |
3 |
0 |
3 |
| if ((node == NULL) || (node->type != XML_ELEMENT_NODE)) return(0); |
0 |
3 |
3 |
|
| 1199 |
5 |
▶ | while (node != NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (node != NULL) { |
4 |
1 |
5 |
|
| 1200 |
4 |
▶ | if (node->ns == ns) |
Branch: 1 branch
| Branch | True | False | Total |
| if (node->ns == ns) |
2 |
2 |
4 |
|
| 1201 |
2 |
| node->ns = NULL; /* remove namespace reference */ |
| 1202 |
4 |
| attr = node->properties; |
| 1203 |
5 |
▶ | while (attr != NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (attr != NULL) { |
1 |
4 |
5 |
|
| 1204 |
1 |
▶ | if (attr->ns == ns) |
Branch: 1 branch
| Branch | True | False | Total |
| if (attr->ns == ns) |
1 |
0 |
1 |
|
| 1205 |
1 |
| attr->ns = NULL; /* remove namespace reference */ |
| 1206 |
1 |
| attr = attr->next; |
| 1207 |
|
| } |
| 1208 |
|
| /* |
| 1209 |
|
| * Browse the full subtree, deep first |
| 1210 |
|
| */ |
| 1211 |
4 |
▶ | if (node->children != NULL && node->type != XML_ENTITY_REF_NODE) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (node->children != NULL && node->type != XML_ENTITY_REF_NODE) { |
1 |
3 |
4 |
| if (node->children != NULL && node->type != XML_ENTITY_REF_NODE) { |
1 |
0 |
1 |
|
| 1212 |
|
| /* deep first */ |
| 1213 |
1 |
| node = node->children; |
| 1214 |
3 |
▶ | } else if ((node != tree) && (node->next != NULL)) { |
Branch: 2 branches
| Branch | True | False | Total |
| } else if ((node != tree) && (node->next != NULL)) { |
1 |
2 |
3 |
| } else if ((node != tree) && (node->next != NULL)) { |
0 |
1 |
1 |
|
| 1215 |
|
| /* then siblings */ |
| 1216 |
0 |
| node = node->next; |
| 1217 |
3 |
▶ | } else if (node != tree) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (node != tree) { |
1 |
2 |
3 |
|
| 1218 |
|
| /* go up to parents->next if needed */ |
| 1219 |
2 |
▶ | while (node != tree) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (node != tree) { |
1 |
1 |
2 |
|
| 1220 |
1 |
▶ | if (node->parent != NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (node->parent != NULL) |
1 |
0 |
1 |
|
| 1221 |
1 |
| node = node->parent; |
| 1222 |
1 |
▶ | if ((node != tree) && (node->next != NULL)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ((node != tree) && (node->next != NULL)) { |
0 |
1 |
1 |
| if ((node != tree) && (node->next != NULL)) { |
0 |
0 |
0 |
|
| 1223 |
0 |
| node = node->next; |
| 1224 |
0 |
| break; |
| 1225 |
|
| } |
| 1226 |
1 |
▶ | if (node->parent == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (node->parent == NULL) { |
0 |
1 |
1 |
|
| 1227 |
0 |
| node = NULL; |
| 1228 |
0 |
| break; |
| 1229 |
|
| } |
| 1230 |
|
| } |
| 1231 |
|
| /* exit condition */ |
| 1232 |
1 |
▶ | if (node == tree) |
Branch: 1 branch
| Branch | True | False | Total |
| if (node == tree) |
1 |
0 |
1 |
|
| 1233 |
1 |
| node = NULL; |
| 1234 |
|
| } else |
| 1235 |
2 |
| break; |
| 1236 |
|
| } |
| 1237 |
3 |
| return(1); |
| 1238 |
|
| } |
| 1239 |
|
| |