* xmlC14NProcessNode: * @ctx: the pointer to C14N context object * @cur: the node to process * * Processes the given node * * Returns non-negative value on success or negative value on fail */
| 1525 | * Returns non-negative value on success or negative value on fail |
| 1526 | */ |
| 1527 | static int |
| 1528 | xmlC14NProcessNode(xmlC14NCtxPtr ctx, xmlNodePtr cur) |
| 1529 | { |
| 1530 | int ret = 0; |
| 1531 | int visible; |
| 1532 | |
| 1533 | if ((ctx == NULL) || (cur == NULL)) { |
| 1534 | xmlC14NErrParam(ctx); |
| 1535 | return (-1); |
| 1536 | } |
| 1537 | |
| 1538 | visible = xmlC14NIsVisible(ctx, cur, cur->parent); |
| 1539 | switch (cur->type) { |
| 1540 | case XML_ELEMENT_NODE: |
| 1541 | ret = xmlC14NProcessElementNode(ctx, cur, visible); |
| 1542 | break; |
| 1543 | case XML_CDATA_SECTION_NODE: |
| 1544 | case XML_TEXT_NODE: |
| 1545 | /* |
| 1546 | * Text Nodes |
| 1547 | * the string value, except all ampersands are replaced |
| 1548 | * by &, all open angle brackets (<) are replaced by <, all closing |
| 1549 | * angle brackets (>) are replaced by >, and all #xD characters are |
| 1550 | * replaced by 
. |
| 1551 | */ |
| 1552 | /* cdata sections are processed as text nodes */ |
| 1553 | /* todo: verify that cdata sections are included in XPath nodes set */ |
| 1554 | if ((visible) && (cur->content != NULL)) { |
| 1555 | xmlChar *buffer; |
| 1556 | |
| 1557 | buffer = xmlC11NNormalizeText(cur->content); |
| 1558 | if (buffer != NULL) { |
| 1559 | xmlOutputBufferWriteString(ctx->buf, |
| 1560 | (const char *) buffer); |
| 1561 | xmlFree(buffer); |
| 1562 | } else { |
| 1563 | xmlC14NErrMemory(ctx); |
| 1564 | return (-1); |
| 1565 | } |
| 1566 | } |
| 1567 | break; |
| 1568 | case XML_PI_NODE: |
| 1569 | /* |
| 1570 | * Processing Instruction (PI) Nodes- |
| 1571 | * The opening PI symbol (<?), the PI target name of the node, |
| 1572 | * a leading space and the string value if it is not empty, and |
| 1573 | * the closing PI symbol (?>). If the string value is empty, |
| 1574 | * then the leading space is not added. Also, a trailing #xA is |
| 1575 | * rendered after the closing PI symbol for PI children of the |
| 1576 | * root node with a lesser document order than the document |
| 1577 | * element, and a leading #xA is rendered before the opening PI |
| 1578 | * symbol of PI children of the root node with a greater document |
| 1579 | * order than the document element. |
| 1580 | */ |
| 1581 | if (visible) { |
| 1582 | if (ctx->pos == XMLC14N_AFTER_DOCUMENT_ELEMENT) { |
| 1583 | xmlOutputBufferWriteString(ctx->buf, "\x0A<?"); |
| 1584 | } else { |
no test coverage detected