8000 And'ed expression for node selection. · Issue #74 · antchfx/xpath · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
And'ed expression for node selection. #74
Closed
@sjames-iberis

Description

@sjames-iberis

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0