maiha / hq.cr

a simple wrapper for crystal-xml
MIT License
7 stars 1 forks source link

Using with XML #2

Open inancgumus opened 7 years ago

inancgumus commented 7 years ago

I believe this is probably because of underlying LibXML library which is used by Crystal; Not because of hq.cr. However, I want to write it here first, maybe you have some ideas about this.

First Try (not working)

nodes = Hq.parse("<?xml version=\"1.0\"?><chapter>Test</chapter>")
puts nodes.xpath("/chapter").text

# Not Found: `/chapter' (Hq::NotFound)
# 0x10abb32d5: *CallStack::unwind:Array(Pointer(Void)) at ??
# 0x10abb3271: *CallStack#initialize:Array(Pointer(Void)) at ??
# 0x10abb3248: *CallStack::new:CallStack at ??
# 0x10abb2561: *raise<Exception+>:NoReturn at ??
# 0x10abe043d: *Failure(String)@Failure(T)#get:NoReturn at ??
# 0x10abdfad1: *Hq::Node#text:String at ??
# 0x10abac536: __crystal_main at ??
# 0x10abb1f78: main at ??

Second Try (working)

nodes = Hq.parse("<?xml version=\"1.0\"?><html>Test</html>")
puts nodes.xpath("/html").text # --> Test

So, whenever non-html tag is given in a xml, it throws an error. This is not occurring when I directly use Crystal::Xml.