Read returns a target node that satisfies the XPath specified by caller at StreamParser creation time. If there is no more satisfying target nodes after reading the rest of the XML document, io.EOF will be returned. At any time, any XML parsing error encountered will be returned, and the stream pars
()
| 486 | // undefined behavior. Also note, due to the streaming nature, calling Read() |
| 487 | // will automatically remove any previous target node(s) from the document tree. |
| 488 | func (sp *StreamParser) Read() (*Node, error) { |
| 489 | // Because this is a streaming read, we need to release/remove last |
| 490 | // target node from the node tree to free up memory. |
| 491 | if sp.p.streamNode != nil { |
| 492 | // We need to remove all siblings before the current stream node, |
| 493 | // because the document may contain unwanted nodes between the target |
| 494 | // ones (for example new line text node), which would otherwise |
| 495 | // accumulate as first childs, and slow down the stream over time |
| 496 | for sp.p.streamNode.PrevSibling != nil { |
| 497 | RemoveFromTree(sp.p.streamNode.PrevSibling) |
| 498 | } |
| 499 | sp.p.prev = sp.p.streamNode.Parent |
| 500 | RemoveFromTree(sp.p.streamNode) |
| 501 | sp.p.streamNode = nil |
| 502 | sp.p.streamNodePrev = nil |
| 503 | } |
| 504 | return sp.p.parse() |
| 505 | } |