* xmlTextReaderReadString: * @reader: the xmlTextReaderPtr used * * Reads the contents of an element or a text node as a string. * * Returns a string containing the contents of the Element or Text node, * or NULL if the reader is positioned on any other type of node. * The string must be deallocated by the caller. */
| 1735 | * The string must be deallocated by the caller. |
| 1736 | */ |
| 1737 | xmlChar * |
| 1738 | xmlTextReaderReadString(xmlTextReaderPtr reader) |
| 1739 | { |
| 1740 | xmlNodePtr node, cur; |
| 1741 | xmlBufPtr buf; |
| 1742 | xmlChar *ret; |
| 1743 | |
| 1744 | if ((reader == NULL) || (reader->node == NULL)) |
| 1745 | return(NULL); |
| 1746 | |
| 1747 | node = (reader->curnode != NULL) ? reader->curnode : reader->node; |
| 1748 | switch (node->type) { |
| 1749 | case XML_TEXT_NODE: |
| 1750 | case XML_CDATA_SECTION_NODE: |
| 1751 | break; |
| 1752 | case XML_ELEMENT_NODE: |
| 1753 | if ((xmlTextReaderDoExpand(reader) == -1) || |
| 1754 | (node->children == NULL)) |
| 1755 | return(NULL); |
| 1756 | break; |
| 1757 | case XML_ATTRIBUTE_NODE: |
| 1758 | /* TODO */ |
| 1759 | break; |
| 1760 | default: |
| 1761 | break; |
| 1762 | } |
| 1763 | |
| 1764 | buf = xmlBufCreateSize(30); |
| 1765 | if (buf == NULL) { |
| 1766 | xmlTextReaderErrMemory(reader); |
| 1767 | return(NULL); |
| 1768 | } |
| 1769 | xmlBufSetAllocationScheme(buf, XML_BUFFER_ALLOC_DOUBLEIT); |
| 1770 | |
| 1771 | cur = node; |
| 1772 | while (cur != NULL) { |
| 1773 | switch (cur->type) { |
| 1774 | case XML_TEXT_NODE: |
| 1775 | case XML_CDATA_SECTION_NODE: |
| 1776 | xmlBufCat(buf, cur->content); |
| 1777 | break; |
| 1778 | |
| 1779 | case XML_ELEMENT_NODE: |
| 1780 | if (cur->children != NULL) { |
| 1781 | cur = cur->children; |
| 1782 | continue; |
| 1783 | } |
| 1784 | break; |
| 1785 | |
| 1786 | default: |
| 1787 | break; |
| 1788 | } |
| 1789 | |
| 1790 | if (cur == node) |
| 1791 | goto done; |
| 1792 | |
| 1793 | while (cur->next == NULL) { |
| 1794 | cur = cur->parent; |
nothing calls this directly
no test coverage detected