in xpointer.c */ * xmlXIncludeCopyRange: * @ctxt: the XInclude context * @obj: the XPointer result from the evaluation. * * Build a node list tree copy of the XPointer result. * * Returns an xmlNodePtr list or NULL. * The caller has to free the node tree. */
| 823 | * The caller has to free the node tree. |
| 824 | */ |
| 825 | static xmlNodePtr |
| 826 | xmlXIncludeCopyRange(xmlXIncludeCtxtPtr ctxt, xmlXPathObjectPtr range) { |
| 827 | /* pointers to generated nodes */ |
| 828 | xmlNodePtr list = NULL, last = NULL, listParent = NULL; |
| 829 | xmlNodePtr tmp, tmp2; |
| 830 | /* pointers to traversal nodes */ |
| 831 | xmlNodePtr start, cur, end; |
| 832 | int index1, index2; |
| 833 | int level = 0, lastLevel = 0, endLevel = 0, endFlag = 0; |
| 834 | |
| 835 | if ((ctxt == NULL) || (range == NULL)) |
| 836 | return(NULL); |
| 837 | if (range->type != XPATH_RANGE) |
| 838 | return(NULL); |
| 839 | start = (xmlNodePtr) range->user; |
| 840 | |
| 841 | if ((start == NULL) || (start->type == XML_NAMESPACE_DECL)) |
| 842 | return(NULL); |
| 843 | end = range->user2; |
| 844 | if (end == NULL) |
| 845 | return(xmlDocCopyNode(start, ctxt->doc, 1)); |
| 846 | if (end->type == XML_NAMESPACE_DECL) |
| 847 | return(NULL); |
| 848 | |
| 849 | cur = start; |
| 850 | index1 = range->index; |
| 851 | index2 = range->index2; |
| 852 | /* |
| 853 | * level is depth of the current node under consideration |
| 854 | * list is the pointer to the root of the output tree |
| 855 | * listParent is a pointer to the parent of output tree (within |
| 856 | the included file) in case we need to add another level |
| 857 | * last is a pointer to the last node added to the output tree |
| 858 | * lastLevel is the depth of last (relative to the root) |
| 859 | */ |
| 860 | while (cur != NULL) { |
| 861 | /* |
| 862 | * Check if our output tree needs a parent |
| 863 | */ |
| 864 | if (level < 0) { |
| 865 | while (level < 0) { |
| 866 | /* copy must include namespaces and properties */ |
| 867 | tmp2 = xmlDocCopyNode(listParent, ctxt->doc, 2); |
| 868 | xmlAddChild(tmp2, list); |
| 869 | list = tmp2; |
| 870 | listParent = listParent->parent; |
| 871 | level++; |
| 872 | } |
| 873 | last = list; |
| 874 | lastLevel = 0; |
| 875 | } |
| 876 | /* |
| 877 | * Check whether we need to change our insertion point |
| 878 | */ |
| 879 | while (level < lastLevel) { |
| 880 | last = last->parent; |
| 881 | lastLevel --; |
| 882 | } |
no test coverage detected