* xmlXPathOrderDocElems: * @doc: an input document * * Call this routine to speed up XPath computation on static documents. * This stamps all the element nodes with the document order * Like for line information, the order is kept in the element->content * field, the value stored is actually - the node number (starting at -1) * to be able to differentiate from line numbers. * * Returns t
| 2456 | * of error. |
| 2457 | */ |
| 2458 | long |
| 2459 | xmlXPathOrderDocElems(xmlDocPtr doc) { |
| 2460 | ptrdiff_t count = 0; |
| 2461 | xmlNodePtr cur; |
| 2462 | |
| 2463 | if (doc == NULL) |
| 2464 | return(-1); |
| 2465 | cur = doc->children; |
| 2466 | while (cur != NULL) { |
| 2467 | if (cur->type == XML_ELEMENT_NODE) { |
| 2468 | cur->content = (void *) (-(++count)); |
| 2469 | if (cur->children != NULL) { |
| 2470 | cur = cur->children; |
| 2471 | continue; |
| 2472 | } |
| 2473 | } |
| 2474 | if (cur->next != NULL) { |
| 2475 | cur = cur->next; |
| 2476 | continue; |
| 2477 | } |
| 2478 | do { |
| 2479 | cur = cur->parent; |
| 2480 | if (cur == NULL) |
| 2481 | break; |
| 2482 | if (cur == (xmlNodePtr) doc) { |
| 2483 | cur = NULL; |
| 2484 | break; |
| 2485 | } |
| 2486 | if (cur->next != NULL) { |
| 2487 | cur = cur->next; |
| 2488 | break; |
| 2489 | } |
| 2490 | } while (cur != NULL); |
| 2491 | } |
| 2492 | return(count); |
| 2493 | } |
| 2494 | |
| 2495 | /** |
| 2496 | * xmlXPathCmpNodes: |