Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

And'ed expression for node selection. #74

Closed
sjames-iberis opened this issue May 20, 2022 · 0 comments
Closed

And'ed expression for node selection. #74

sjames-iberis opened this issue May 20, 2022 · 0 comments
Labels

Comments

@sjames-iberis
Copy link

Versions:

  • github.com/antchfx/xmlquery v1.3.10
  • github.com/antchfx/xpath v1.2.0

This test is failing:

func TestXPathAnd(t *testing.T) {
	body := `
		<top>
		  <child><name>Child1</name>
			 <toy>A</toy>
			 <toy>B</toy>
		  </child>
		</top>`

	root, err := xmlquery.Parse(strings.NewReader(body))
	assert.NoError(t, err)

	expr, err := xpath.Compile(`/top/child[toy[text() = "A"] and toy[text()="B"]]/name/text()`)
	assert.NoError(t, err)
	result := expr.Evaluate(xmlquery.CreateXPathNavigator(root))
	switch rt := result.(type) {
	case *xpath.NodeIterator:
		assert.True(t, rt.MoveNext()). // Fails
		fmt.Println("Value:", rt.Current().Value())
	}
}

Compare this with standard macos xpath utility:

 xpath -e '/top/child[toy[text() = "A"] and toy[text()="B"]]/name/text()'
		<top>
		  <child><name>Child1</name>
			 <toy>A</toy>
			 <toy>B</toy>
		  </child>
		</top>
Found 1 nodes in stdin:
-- NODE --
Child1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants