Answer the question
In order to leave comments, you need to log in
How to properly build a tree structure (Golang) and how to work with it?
There are a lot of examples on the Internet about building binary trees and working with them, but I could not find a clear explanation of working with non-binary trees, perhaps because there is not much difference. But I don't fully understand how it works.
I need to implement a search tree for a certain category in a YML file, depending on the selected level, if level 0 is a site, level 1 is a category level without parents, level 2 is all categories whose parent is the one who is at the top of the 1st level.
YML structure
type Yml struct {
XMLName xml.Name `xml:"yml_catalog"`
Date string `xml:"date,attr"`
Shop []Shop `xml:"shop"`
}
type Shop struct {
Name string `xml:"name"`
Company string `xml:"company"`
URL string `xml:"url"`
Categories []Category `xml:"categories>category"`
Offers []Offer `xml:"offers>offer"`
}
type Category struct {
ID int `xml:"id,attr"`
ParentID int `xml:"parentId,attr"`
Category string `xml:",chardata"`
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question