InnerText returns the text between the start and end tags of the object.
()
| 139 | |
| 140 | // InnerText returns the text between the start and end tags of the object. |
| 141 | func (n *Node) InnerText() string { |
| 142 | var output func(*strings.Builder, *Node) |
| 143 | output = func(b *strings.Builder, n *Node) { |
| 144 | switch n.Type { |
| 145 | case TextNode, CharDataNode: |
| 146 | b.WriteString(n.Data) |
| 147 | case CommentNode: |
| 148 | default: |
| 149 | for child := n.FirstChild; child != nil; child = child.NextSibling { |
| 150 | output(b, child) |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | var b strings.Builder |
| 156 | output(&b, n) |
| 157 | return b.String() |
| 158 | } |
| 159 | |
| 160 | // ChildNodes returns all the child nodes of the current node, |
| 161 | // including text, comments, and char data. |