Ji icon indicating copy to clipboard operation
Ji copied to clipboard

xPath fails if there's xmlns

Open kschroeer opened this issue 8 years ago • 2 comments

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.

kschroeer avatar Feb 13 '17 06:02 kschroeer

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!

honghaoz avatar Mar 18 '17 15:03 honghaoz

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.

stephenfung98 avatar Jan 18 '19 03:01 stephenfung98