xmlquery icon indicating copy to clipboard operation
xmlquery copied to clipboard

Feature request: export "level" attribute of Node

Open kcmvp opened this issue 3 years ago • 4 comments

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

} `

kcmvp avatar May 20 '21 03:05 kcmvp

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?

zhengchun avatar Jun 03 '21 04:06 zhengchun

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.

kcmvp avatar Jun 08 '21 03:06 kcmvp

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)
}

zhengchun avatar Jun 09 '21 15:06 zhengchun

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

kcmvp avatar Jun 10 '21 02:06 kcmvp

#65

zhengchun avatar Apr 03 '24 03:04 zhengchun