antchfx / xmlquery

xmlquery is Golang XPath package for XML query.

Home Page:https://github.com/antchfx/xpath

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request: export "level" attribute of Node

kcmvp opened this issue · comments

commented

First thank you very much to build such great tool. I am using it in my project.
right now I need the 'level' attribute of Node, I would like to raise a PR for this change.
Would you mind approve this PR?

`
type Node struct {
Parent, FirstChild, LastChild, PrevSibling, NextSibling *Node

Type         NodeType
Data         string
Prefix       string
NamespaceURI string
Attr         []xml.Attr

level int // node level in the tree

}
`

Hello,level is designed only for Node to calculate parent and child, I don't see a reason to use it by externally package, it doesn't make any sense .

Can you give scenarios of use?

commented

my case is something like below:
1: given an attribute of a xml node
2: find the node and process the node itself、children、 parent and indirectly-parent(any node which level is high than the current node). this process is recursive which stop condition is level ==1, that's why I need the value(read only) of this attribute.

You have an alternative method to get level of node without expose this field. for example.

topnode: =node.Parent
level:=0
for node:=topnode.FirstChild; node!=nil; node=node.NextSibling {
level++
fmt.Println(node+":"+level)
}
commented

You have an alternative method to get level of node without expose this field. for example.

topnode: =node.Parent
level:=0
for node:=topnode.FirstChild; node!=nil; node=node.NextSibling {
level++
fmt.Println(node+":"+level)
}

I am wondering the value is there already, why not to expose it as readonly? otherwise everyone need this value have to implement this.
meanwhile for my case find a node by a given attribute, I can not tell its level easily. (my case xml node can nest). so I wish this value can be exposed as readonly