Skip to content

Commit

Permalink
chore: remove unused leafnodes array and element tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshNarayanJha committed Nov 10, 2024
1 parent bd06065 commit f1f9575
Showing 1 changed file with 0 additions and 21 deletions.
21 changes: 0 additions & 21 deletions internal/pkg/crawl/extractor/xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import (
"strings"
)

type LeafNode struct {
Path string `json:"path"`
Value string `json:"value"`
}

func XML(resp *http.Response) (URLs []*url.URL, sitemap bool, err error) {
xmlBody, err := io.ReadAll(resp.Body)
if err != nil {
Expand All @@ -27,12 +22,6 @@ func XML(resp *http.Response) (URLs []*url.URL, sitemap bool, err error) {
reader := bytes.NewReader(xmlBody)
decoder := xml.NewDecoder(reader)

var (
startElement xml.StartElement
currentNode *LeafNode
leafNodes []LeafNode
)

// try to decode one token to see if stream is open
_, err = decoder.Token()
if err != nil {
Expand All @@ -54,8 +43,6 @@ func XML(resp *http.Response) (URLs []*url.URL, sitemap bool, err error) {

switch tok := tok.(type) {
case xml.StartElement:
startElement = tok
currentNode = &LeafNode{Path: startElement.Name.Local}
for _, attr := range tok.Attr {
if strings.HasPrefix(attr.Value, "http") {
parsedURL, err := url.Parse(attr.Value)
Expand All @@ -64,15 +51,7 @@ func XML(resp *http.Response) (URLs []*url.URL, sitemap bool, err error) {
}
}
}
case xml.EndElement:
if currentNode != nil {
leafNodes = append(leafNodes, *currentNode)
currentNode = nil
}
case xml.CharData:
if currentNode != nil && len(strings.TrimSpace(string(tok))) > 0 {
currentNode.Value = string(tok)
}
if strings.HasPrefix(string(tok), "http") {
parsedURL, err := url.Parse(string(tok))
if err == nil {
Expand Down

0 comments on commit f1f9575

Please sign in to comment.