etree
etree copied to clipboard
Feature request - the GetPath function must return the full path with the index
Now the GetPath function for all VHost elements will return the same path - /VHosts/VHost
Document:
<VHosts>
<VHost>
<Name>host_1</Name>
<TimeRunning>64679.885</TimeRunning>
<Connections>
<ConnectionsLimit>0</ConnectionsLimit>
<ConnectionsCurrent>0</ConnectionsCurrent>
<ConnectionsTotal>0</ConnectionsTotal>
<ConnectionsTotalAccepted>0</ConnectionsTotalAccepted>
<ConnectionsTotalRejected>0</ConnectionsTotalRejected>
</Connections>
<MessagesInBytesRate>0.0</MessagesInBytesRate>
<MessagesOutBytesRate>0.0</MessagesOutBytesRate>
</VHost>
<VHost>
<Name>host_2</Name>
<TimeRunning>67777.885</TimeRunning>
<Connections>
<ConnectionsLimit>2</ConnectionsLimit>
<ConnectionsCurrent>2</ConnectionsCurrent>
<ConnectionsTotal>2</ConnectionsTotal>
<ConnectionsTotalAccepted>2</ConnectionsTotalAccepted>
<ConnectionsTotalRejected>2</ConnectionsTotalRejected>
</Connections>
<MessagesInBytesRate>2.2</MessagesInBytesRate>
<MessagesOutBytesRate>2.2</MessagesOutBytesRate>
</VHost>
</VHosts>
Request - the ability to get the path of an element in an array with the index:
/VHosts/VHost[1]
/VHosts/VHost[2]
This is not the best quality code, but I managed to do it like this:
npath := ""
for seg := e; seg != nil; seg = seg.Parent() {
if seg.Tag != "" {
index := ""
z := seg.Parent().FindElements(seg.Tag)
if len(z) > 1 {
for i, x := range z {
if x.Index() == seg.Index() {
index = fmt.Sprintf("[%v]", strconv.Itoa(i + 1))
}
}
}
npath = fmt.Sprintf("%v%v/%v", seg.Tag, index, npath)
}
}
return fmt.Sprintf("/%v", npath)