* xmlC14NProcessNamespacesAxis: * @ctx: the C14N context * @node: the current node * * Prints out canonical namespace axis of the current node to the * buffer from C14N context as follows * * Canonical XML v 1.0 (http://www.w3.org/TR/xml-c14n) * * Namespace Axis * Consider a list L containing only namespace nodes in the * axis and in the node-set in lexicographic order (ascending). To
| 589 | * Returns 0 on success or -1 on fail. |
| 590 | */ |
| 591 | static int |
| 592 | xmlC14NProcessNamespacesAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur, int visible) |
| 593 | { |
| 594 | xmlNodePtr n; |
| 595 | xmlNsPtr ns, tmp; |
| 596 | xmlListPtr list; |
| 597 | int already_rendered; |
| 598 | int has_empty_ns = 0; |
| 599 | |
| 600 | if ((ctx == NULL) || (cur == NULL) || (cur->type != XML_ELEMENT_NODE)) { |
| 601 | xmlC14NErrParam(ctx); |
| 602 | return (-1); |
| 603 | } |
| 604 | |
| 605 | /* |
| 606 | * Create a sorted list to store element namespaces |
| 607 | */ |
| 608 | list = xmlListCreate(NULL, xmlC14NNsCompare); |
| 609 | if (list == NULL) { |
| 610 | xmlC14NErrMemory(ctx); |
| 611 | return (-1); |
| 612 | } |
| 613 | |
| 614 | /* check all namespaces */ |
| 615 | for(n = cur; n != NULL; n = n->parent) { |
| 616 | for(ns = n->nsDef; ns != NULL; ns = ns->next) { |
| 617 | tmp = xmlSearchNs(cur->doc, cur, ns->prefix); |
| 618 | |
| 619 | if((tmp == ns) && !xmlC14NIsXmlNs(ns) && xmlC14NIsVisible(ctx, ns, cur)) { |
| 620 | already_rendered = xmlC14NVisibleNsStackFind(ctx->ns_rendered, ns); |
| 621 | if(visible) { |
| 622 | if (xmlC14NVisibleNsStackAdd(ctx->ns_rendered, ns, cur) < 0) { |
| 623 | xmlC14NErrMemory(ctx); |
| 624 | goto error; |
| 625 | } |
| 626 | } |
| 627 | if(!already_rendered) { |
| 628 | xmlListInsert(list, ns); |
| 629 | } |
| 630 | if(xmlStrlen(ns->prefix) == 0) { |
| 631 | has_empty_ns = 1; |
| 632 | } |
| 633 | } |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | /** |
| 638 | * if the first node is not the default namespace node (a node with no |
| 639 | * namespace URI and no local name), then generate a space followed by |
| 640 | * xmlns="" if and only if the following conditions are met: |
| 641 | * - the element E that owns the axis is in the node-set |
| 642 | * - the nearest ancestor element of E in the node-set has a default |
| 643 | * namespace node in the node-set (default namespace nodes always |
| 644 | * have non-empty values in XPath) |
| 645 | */ |
| 646 | if(visible && !has_empty_ns) { |
| 647 | static xmlNs ns_default; |
| 648 |
no test coverage detected