honghaoz / Ji

Ji (戟) is an XML/HTML parser for Swift
MIT License
824 stars 64 forks source link

xPath fails if there's xmlns #42

Open kschroeer opened 7 years ago

kschroeer commented 7 years ago

Evaluating XPath strings fails if one of the elements is defined with XML namespace. Most of the frameworks offer a method to register namespaces but I found no way for Ji. So I guess many of the common XML/HTML files can't be queried by your xPath function.

honghaoz commented 7 years ago

Sorry for my late reply. Yeah, that's a problem for parsing XML. Ji was initially created for parsing html, that's why it's not having this functionality. I'd like to add registering namespaces to Ji, if you could help, PR is welcomed! Thx!

stephenfung98 commented 5 years ago
let jiDoc = Ji(htmlURL: URL(string: "https://www.ups.com/track?loc=en_US&tracknum=" + trackingNumber + "&requester=WT/trackdetails")!)

let titleNode = jiDoc?.xPath("//*[@id=\"stApp_progressTableContent\"]/div[2]/table")?.first

titleNode is returning nil, is it because it is not using the namespace? Is there a workaround for this?

Edit: My problem was not rendering the JS and has nothing to do with namespace.