Init doesn't fail for invalid XML
djbe opened this issue · comments
Description:
- Expected behaviour:
Reading a broken XML throws an error. - Actual behaviour:
Fuzi recovers and parses the XML partially (up to the error).
Environment
- Package Manager: CocoaPods
- Fuzi version: 1.0.1
- Xcode version: 8.3.2
How to reproduce:
While unit testing our library, we want to catch that our parser fails on invalid documents. Instead, the broken file gets partially parsed, because Fuzi sets the option to ignore errors (XML_PARSE_NOERROR): https://github.com/cezheng/Fuzi/blob/master/Sources/Document.swift#L112
As the initializers are failable, as a user we'd expect it to fail for invalid documents. Now, I can understand that not all users might want this, but could it be made available as an option? For example, modify the initialisers to accept an extra options
parameter, by default set to
Int32(XML_PARSE_NOWARNING.rawValue | XML_PARSE_NOERROR.rawValue | XML_PARSE_RECOVER.rawValue)
Even better would be to provide a swift OptionSet that maps to the libxml values.
Example faulty XML:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<>
<color name="ArticleTitle">#33fe66</color>
</resources>
I think I'm fine with adding an option for parsing. I'll be happy to review any PRs.