MCPcopy Index your code
hub / github.com/antchfx/xmlquery / Read

Method Read

parse.go:488–505  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

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.
488func (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}

Callers 5

TestCDATAFunction · 0.45
TestCachingFunction · 0.45

Calls 2

RemoveFromTreeFunction · 0.85
parseMethod · 0.80

Tested by 5

TestCDATAFunction · 0.36
TestCachingFunction · 0.36