Comments (6)
@mildred , Sorry for the late reply .
I don't think this is a problem. /foo/bar@attr
expression means searchs bar element that have a attr name
.
The package Expr
have two methods: Seelct
and Evaluate
. if you want matches attr="b"
, you can consider Evaluate
method. #4 (comment)
expr, err := xpath.Compile("//img/@src")
val := expr.Evaluate(nav)
switch typ := val.(type) {
case *xpath.NodeIterator:
for typ.MoveNext() {
fmt.Println(typ.Current().Value()) // output @src value
}
}
from xpath.
Thank you, but the test I made here uses Evaluate and not Select, but the result is not the attribute node but the element. Am I missing something?
from xpath.
The /foo/bar@attr
change to /foo/bar/@attr
, I think expression /foo/bar@attr
and /foo/bar/@attr
is different results.
expr, _ := xpath.Compile("//foo/bar/@attr")
iter := expr.Evaluate(xmlquery.CreateXPathNavigator(doc))
switch typ := iter.(type) {
case *xpath.NodeIterator:
for typ.MoveNext() {
fmt.Printf("%v:%s\n", typ.Current().NodeType(), typ.Current().LocalName())
}
}
from xpath.
Good to know. Then the question is which behaviour confirms with the XPath W3C recommendation. Do you have a goal to follow the recommendation closely or not?
When looking through the recommendation, the only occurence of node/@attr
is for ../@attr
. It seems for non parent elements, they use elem@attr
directly.
from xpath.
I'm test foo/bar@attr
expression on xpath-tester, got parse error:
Unable to parse any XML input. Unexpected token "@" beyond end of expression
This error also occurs on .NET when using XML library.
So the elem@attr
looks is not correct syntax. xpath package should be return error when parsing this expression, but it not.
from xpath.
You are completely right, and I apologize for the issue that is not an issue. I tested this expression somewhere and I assumed that because it worked there, it was valid XPath.
from xpath.
Related Issues (20)
- `Compile` didn't report error in predicate HOT 1
- `normalize-space()` should be equal to `normalize-space(.)`
- Discussion: Provide `NodeNavigator` interface to get native data HOT 12
- The multiple filter query with `last()` function HOT 1
- How to use this in rust HOT 1
- string comparison size error HOT 1
- How get the xpath of selected html elem? HOT 1
- How to concatenate json values? HOT 2
- Thank you HOT 1
- stateful interface is cumbersome when performing multiple xpath queries on one document HOT 1
- The multiple filter query with last() and concat() function HOT 3
- How to "zip" two lists together? HOT 1
- Can you give some examples of usage of node axes? ex:getting the matching values of previous sibling and next sibling HOT 1
- why is panic used instead of returning errors? HOT 10
- /descendant::span[1] should not be equivalent to //span[1] HOT 1
- [CHANGES] remove the duplicate element when the query node-set has duplicate element
- xpath `lower-case()` function
- Converting an empty node set to a number should return NaN HOT 1
- memory leak or endless loop in v1.3.0 HOT 5
- Is it possible to create an xpath expression with non-Latin letters? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xpath.