Hurray, this is been solved. The author of the HXT library has addressed the GitHub issue added a new parser xreadDoc
in this commit. I've fixed the rdf4h library version 1.2.2 and up, using this new parser in this commit, so XML/RDF documents (with spec and encoding headings) can now be parsed with the XmlParser
.
Note the new arrow composition in testFailure
, as (xreadDoc >>> isElem)
.
module HXTProblem where
import Text.XML.HXT.Core
data GParseState = GParseState { stateGenId :: Int } deriving(Show)
-- this document has an XML specification included
xmlDoc1 :: String
xmlDoc1 = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" ++
"<shiporder orderid=\"889923\" " ++
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " ++
"xsi:noNamespaceSchemaLocation=\"shiporder.xsd\">" ++
"<orderperson>John Smith</orderperson>" ++
"<shipto>" ++
"<name>Ola Nordmann</name>" ++
"</shipto>" ++
"</shiporder>"
-- this document does not include the XML specification
xmlDoc2 :: String
xmlDoc2 = "<shiporder orderid=\"889923\" " ++
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " ++
"xsi:noNamespaceSchemaLocation=\"shiporder.xsd\">" ++
"<orderperson>John Smith</orderperson>" ++
"<shipto>" ++
"<name>Ola Nordmann</name>" ++
"</shipto>" ++
"</shiporder>"
initState :: GParseState
initState = GParseState { stateGenId = 0 }
-- | Works
testSuccess :: (GParseState,[XmlTree])
testSuccess = runSLA xread initState xmlDoc2
-- | Does also now work!
testFailure :: (GParseState,[XmlTree])
testFailure = runSLA (xreadDoc >>> isElem) initState xmlDoc1
testEquality :: Bool
testEquality =
let (_,x) = testSuccess
(_,y) = testFailure
in x == y