cezheng / Fuzi

A fast & lightweight XML & HTML parser in Swift with XPath & CSS support
MIT License
1.06k stars 151 forks source link

Is xpath lookup from root node, not from current node? #103

Open iDevPro opened 4 years ago

iDevPro commented 4 years ago

Description:

For example, I looked for 20 nodes with a certain class. After, I iterate result for look inside for one item with selected class (I know there is one object with this class). I checked count, it returned 20 not 1.

Environment

How to reproduce:

let nodes = root.xpath(searchForNodes)
print(nodes.count) // return 20, expected 20
nodes.forEach({
    let subNodes = $0.xpath(searchForOneSubNode)
    print(subNodes.count) // return 20, expected 1. repeated for all node
})
cezheng commented 4 years ago

Could you please provide repro code that can execute rather than pseudo-code? Thanks

cezheng commented 4 years ago

Also, please use the latest Fuzi version 3.1.1. Version 1.0.1 is a few years old already, I don't expect it to work with Xcode 11.

iDevPro commented 4 years ago
Снимок экрана 2019-12-27 в 10 16 36

There is I found 20 books per page, enumerate it and parse book by book. When I tried to get the book author by the XPath template, I got an object with 20 subnodes.

P.s.: Also, I found a memory consumption problem but this is another story... (maybe that is Xcode instruments bug)

P.s.p.s.:

cat Fuzi.podspec 
Pod::Spec.new do |s|
  s.name         = "Fuzi"
  s.version      = "3.1.1"
  s.license      = "MIT"

git branch
* master

git pull
Already up to date.
cezheng commented 4 years ago

I mean would you mind providing executable source code that I can use run and debug rather than just a screenshot of a code snippet? I don't even know what XML you are parsing and what xpath query you used.

iDevPro commented 4 years ago

I did send an email for you with link to example-project

iDevPro commented 4 years ago
Снимок экрана 2020-04-06 в 12 25 55

Hello, did you try my code ?)