Open fgateuil opened 1 year ago
Missing to consider attribute nodes prefix and Namespace URL.
You can use the below code to find a parent node node
and then iterate over all its attribute values.
node, _ := xmlquery.Query(root, "//node[@xlink:href]")
for _, attr := range node.Attr {
fmt.Println("NamespaceURI:", attr.NamespaceURI)
fmt.Println("Prefix:", attr.Name.Space)
fmt.Println("Data:", attr.Name.Local)
}
Missing to consider attribute nodes prefix and Namespace URL.
You can use the below code to find a parent node
node
and then iterate over all its attribute values.node, _ := xmlquery.Query(root, "//node[@xlink:href]") for _, attr := range node.Attr { fmt.Println("NamespaceURI:", attr.NamespaceURI) fmt.Println("Prefix:", attr.Name.Space) fmt.Println("Data:", attr.Name.Local) }
Well, why not but if I'm doing so, I must first parse the xpath "//node[@xlink:href]"
to extract the namespace (xlink
) and prefix (href
), and then loop over all the attributes to find the ones that match. It's not really efficient.
Anyway, thanks for your help @zhengchun: much appreciated.
Hi,
I'm trying to find attribute values within a XML document but the returned data seems erroneous.
Description
When I query an XML to get a specific node attribute with namespace (for instance
//@xlink:href
), the returnedxmlquery.Node
is missing the prefix and namespace URI.Steps to reproduce
Expected result
Actual result
Solution proposal
In
github.com/antchfx/xmlquery/query.go#getCurrentNode
:Additional information
If it appears that I just misused the library, what is the correct way to do please ? My main use case is as follows:
@xlink:href
attributes in the document;