Re: [Haskell] HaXml
On 9 Nov 2012, at 23:04, Michael Mossey wrote: Couldn't match expected type Text.XML.HaXml.Types.QName with actual type String. Poking around, I found this webpage describing an issue with a change to HaXml that happened after version 1.20.2: http://stackoverflow.com/questions/7501037/how-to-make-haxml-and-drift-work-with-ghc-7-0-3 This web page suggests that I need to install HaXml-1.20.2 to use it with the current version of the DtdToHaskell utility. For the record (and future web searches), this issue with HaXml (DtdToHaskell generating non-compilable code) was fixed in version 1.23 onwards, from around April 2012. Regards, Malcolm ___ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
[Haskell] HaXml
I'm fairly beginnerish. I'm trying to use HaXml with MusicXML. I got a hold of the MusicXML DTD and ran DtdToHaskell. It generated a file which I then attempted to import to a test program. I got a few compiler errors about duplicate definitions and ambiguous definitions. It seemed pretty clear that these resulted from names in the DTD clashing with each other or with existing names, and I just tweaked some of those. Those compile errors went away. However, I have a new set of compiler errors. I'm getting a similar error hundreds of times, namely Couldn't match expected type Text.XML.HaXml.Types.QName with actual type String. Poking around, I found this webpage describing an issue with a change to HaXml that happened after version 1.20.2: http://stackoverflow.com/questions/7501037/how-to-make-haxml-and-drift-work-with-ghc-7-0-3 This web page suggests that I need to install HaXml-1.20.2 to use it with the current version of the DtdToHaskell utility. Note that I already have the latest version of HaXml installed, so I would need to replace it with an older version. I tried running cabal install HaXml-1.20.2 but got Ambiguous model name 'Prelude': it was found in multiple packages: base haskel98-2.0.0.1 This sounds like something fundamental about the Haskell packages but I don't know enough to know what to do. Mike ___ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
Re: [Haskell] HaXml
On Fri, Nov 9, 2012 at 6:04 PM, Michael Mossey m...@alumni.caltech.eduwrote: but got Ambiguous model name 'Prelude': it was found in multiple packages: base haskel98-2.0.0.1 This sounds like something fundamental about the Haskell packages but I don't know enough to know what to do. Modern GHC can't mix haskell98-style flat module names like Char or IO with the current Haskell standard's hierarchical libraries. The first step to fixing this is to remove the haskell98 dependency from the cabal file; the next is to track down and replace any imported modules that are found to be missing: for example, Char is now Data.Char and IO is split over a number of modules in the System.IO hierarchy. You can use Hoogle or Hayoo (Haskell-specific search engines) to find the module that provides a given function. -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix/linux, openafs, kerberos, infrastructure http://sinenomine.net ___ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
[Haskell] HaXml ANYContent
Hi, I have some problems with the ANYContent type in HaXml. Currently (1.13) ANYContent is defined as data ANYContent = ANYContent which means I cannot store anything in there. I need two things: 1) Parse a file where some elements have ANY content, but be able to use the content. 2) Create a data structure and fill the ANYContent field and be able to write that to an XML file. I suggest the following sollution: newtype Unparsed = Unparsed String data ANYContent = forall a . XmlContent a = Either UnParsed (ANYContent a) If an XML file is parsed we don't know the type yet. Therefore we put everything in Unparsed field. Later on one can use a Parser on that explicitly. It would also make the roundtrip XML-Haskell -XML more stable. Cheers, Georg -- Georg Martius, Tel: (+49 34297) 89434 --- http://www.flexman.homeip.net - pgpJAjmgegubt.pgp Description: PGP signature ___ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
Re: [Haskell] HaXml
Dominic, I use (an extended version of) the CFilter framework to perform namespace, xml:lang and xml:base processing in my revised version of HaXml. Maybe my code [1] might provide some clues for you? Look for function 'applyNamespaces'. The function 'buildNamespaces' illustrates my extension to the CFilter framework, which allows an XML document to be transformed into a new document type containing additional information about the XML elements. 'processNamespaces' actually applies the transformations, using function 'docReplaceContent' which is defined in [2]. Maybe this module has the clues you're after? #g -- [1] http://www.ninebynine.org/Software/HaskellUtils/HaXml-1.12/src/Text/XML/HaXml/Namespace.hs [2] http://www.ninebynine.org/Software/HaskellUtils/HaXml-1.12/src/Text/XML/HaXml/Traverse.hs At 15:33 27/11/04 +, Dominic Steinitz wrote: I'd be grateful for some help on using HaXml. 1. I can parse a String into a Document but it's not clear how you operate on it as the combinators all operate on Content. The only function I could find that operated on a Document was document in Pretty. 2. I can construct a CFilter but it's not clear how you operate on it. How do I calculate the number of components of an Element? What I would like to do is accept vname (with 3 elements) and reject iname (with 4 elements). I'd also like to check that the characters in givenName, initial and familyName are in a given range (for example upper case or between ' ' and '~'). Thanks, Dominic. import Text.XML.HaXml import Text.XML.HaXml.Pretty xmlName = NamegivenNameJohn/givenName ++ initialP/initial ++ familyNameSmith/familyName ++ /Name d = document $ xmlParse tmp xmlName gn = mkElemAttr givenName [] [literal John] i = mkElemAttr initial [] [literal P] fn = mkElemAttr familyName [] [literal Smith] validName = mkElemAttr Name [] [gn,i,fn] invalidName = mkElemAttr Name [] [gn,i,i,fn] vname = processXmlWith validName iname = processXmlWith invalidName *Main d Name givenName John/givenName initial P/initial familyName Smith/familyName/Name *Main *Main vname ?xml version='1.0'? Name givenName John/givenName initial P/initial familyName Smith/familyName/Name *Main ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell Graham Klyne For email: http://www.ninebynine.org/#Contact ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
[Haskell] HaXml
I'd be grateful for some help on using HaXml. 1. I can parse a String into a Document but it's not clear how you operate on it as the combinators all operate on Content. The only function I could find that operated on a Document was document in Pretty. 2. I can construct a CFilter but it's not clear how you operate on it. How do I calculate the number of components of an Element? What I would like to do is accept vname (with 3 elements) and reject iname (with 4 elements). I'd also like to check that the characters in givenName, initial and familyName are in a given range (for example upper case or between ' ' and '~'). Thanks, Dominic. import Text.XML.HaXml import Text.XML.HaXml.Pretty xmlName = NamegivenNameJohn/givenName ++ initialP/initial ++ familyNameSmith/familyName ++ /Name d = document $ xmlParse tmp xmlName gn = mkElemAttr givenName [] [literal John] i = mkElemAttr initial [] [literal P] fn = mkElemAttr familyName [] [literal Smith] validName = mkElemAttr Name [] [gn,i,fn] invalidName = mkElemAttr Name [] [gn,i,i,fn] vname = processXmlWith validName iname = processXmlWith invalidName *Main d Name givenName John/givenName initial P/initial familyName Smith/familyName/Name *Main *Main vname ?xml version='1.0'? Name givenName John/givenName initial P/initial familyName Smith/familyName/Name *Main ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
Re: [Haskell] HaXML incorrect interpretation of XML spec!
S. Alexander Jacobson [EMAIL PROTECTED] writes: I modified the Prolog type to be data Prolog = Prolog (Maybe XMLDecl) [Misc] (Maybe DocTypeDecl) [Misc] and then modified the Prolog parser Thanks for spotting this bug and providing a fix. I also note that the XML spec allows misc* to follow the document top-level element: document ::= prolog element Misc* and this too is incorrect in HaXml. There may well be other occurrences of the same omission. Given that this fix was so very easy and given that the parser was already spec consistent, I now have to assume that there was good reason for the Prolog to be spec inconsistent, but I don't know what it is... I originally assumed that Misc's were unimportant and could be discarded, like comments are discarded by a compiler. I failed to notice that PI's should be passed through to the application. Implementation question: Why is there so much replicated code in HaXML/Html (parse.hs and pretty.hs) The HTML parser does some correction of mal-formed input, which is not otherwise permitted by the XML spec. Likewise, the HTML pretty-printer makes some wild and unjustified assumptions about the way that humans like to format their documents, whereas the XML pp is more strictly-conforming. Once XHTML becomes common, the HTML parser/pp will be obsolete. Regards, Malcolm ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
Re: [Haskell] HaXML incorrect interpretation of XML spec!
Looking at the before-and-after versions of HaXml code that I have modified [1] (with the primary goal of adding namespace support, but also numerous other changes), it seems that the parser always allowed PIs to appear before and after the DTD, but did not store them in the resulting data structure. (That is still the situation with my code.) Here's the original code for the prolog parser that I have: [[ prolog :: XParser Prolog prolog = do x - maybe xmldecl many misc dtd - maybe doctypedecl many misc return (Prolog x dtd) ]] It's clear from this that the PIs (and comments) are parsed and discarded, so your change to capture these in the prolog makes sense. #g -- [1] http://www.ninebynine.org/Software/HaskellUtils/HaXml-1.12/ (My modified version.) At 00:44 28/10/04 -0400, S. Alexander Jacobson wrote: I modified the Prolog type to be data Prolog = Prolog (Maybe XMLDecl) [Misc] (Maybe DocTypeDecl) [Misc] and then modified the Prolog parser (which actually was correct) to actually use the misc values in constucting the Prolog. I replace the prolog function in pretty.hs with prolog (Prolog x m1 dtd m2) = maybe xmldecl x $$ vcat (map misc m1) $$ maybe doctypedecl dtd $$ vcat (map misc m2) and did a few more similar things in Haskell2XML and XML2Haskell (about a 5 min operation) and it all seems to work properly. Implementation question: Why is there so much replicated code in HaXML/Html (parse.hs and pretty.hs) Given that this fix was so very easy and given that the parser was already spec consistent, I now have to assume that there was good reason for the Prolog to be spec inconsistent, but I don't know what it is... Thoughts? -Alex- On Wed, 27 Oct 2004, S. Alexander Jacobson wrote: The XML spec defines the prolog(1) as follows: [22]prolog ::= XMLDecl? Misc* (doctypedecl Misc*)? In other words you can have Misc before AND after the doctype declaration! HaXml defines the prolog(2) as: data Prolog = Prolog (Maybe XMLDecl) (Maybe DocTypeDecl) HaXml therefore does not allow PIs before the beginning of the top level element. This is a problem in practice for people who want to use e.g. XML-Stylesheets(3) where if one is using XSL to produce HTML it is necessary to put the stylesheet declaration BEFORE the root element (if the root element is not HTML). e.g. ?xml version=1.0? ?xml:stylesheet type=text/xsl href=style.xsl? foo id=57 category=2/ Is there some way to puta PI before the root element in combinators? -Alex- (1) http://www.w3.org/TR/REC-xml/#sec-prolog-dtd (2) http://www.cs.york.ac.uk/fp/HaXml/HaXml/Text.XML.HaXml.Types.html#Prolog (3) http://www.w3.org/TR/xml-stylesheet/ __ S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell __ S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell Graham Klyne For email: http://www.ninebynine.org/#Contact ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
[Haskell] HaXML incorrect interpretation of XML spec!
The XML spec defines the prolog(1) as follows: [22] prolog ::= XMLDecl? Misc* (doctypedecl Misc*)? In other words you can have Misc before AND after the doctype declaration! HaXml defines the prolog(2) as: data Prolog = Prolog (Maybe XMLDecl) (Maybe DocTypeDecl) HaXml therefore does not allow PIs before the beginning of the top level element. This is a problem in practice for people who want to use e.g. XML-Stylesheets(3) where if one is using XSL to produce HTML it is necessary to put the stylesheet declaration BEFORE the root element (if the root element is not HTML). e.g. ?xml version=1.0? ?xml:stylesheet type=text/xsl href=style.xsl? foo id=57 category=2/ Is there some way to puta PI before the root element in combinators? -Alex- (1) http://www.w3.org/TR/REC-xml/#sec-prolog-dtd (2) http://www.cs.york.ac.uk/fp/HaXml/HaXml/Text.XML.HaXml.Types.html#Prolog (3) http://www.w3.org/TR/xml-stylesheet/ __ S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
Re: [Haskell] HaXml and XML Schema
On Mar 10, 2004, at 8:56 AM, [EMAIL PROTECTED] wrote: Example (readers familiar with the problem may skip this): salutationDear Mr.nameRobert Smith/name./salutation This structure is represented by the XML Schema xsd:element name=salutation xsd:complexType mixed=true xsd:sequence xsd:element name=name type=xsd:string/ /xsd:sequence /xsd:complexType /xsd:element How would you represent this in Haskell? A first idea may be to store the enclosing strings: data Salutation = Salutation String Name String This approach is not scaling well. E.g., there may be multiple names in the text... No, according to the content model, there must be exactly one occurrence of name in the content of salutation: not zero, and not more than one. To allow zero or more you need to add minOccurs and/or maxOccurs attributes. This is one of the ways that mixed content in XML Schema differs from that in DTD's, and is treated in the references Johan posted. So, on the contrary, your first declaration: data Salutation = Salutation String Name String is a better translation of this schema (fragment), than your second attempt: data Salutation' = Salutation' [Either Char Name] Regards, Frank ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
Re: [Haskell] HaXml and XML Schema
Hello, thank you for the references. Looks promising. I will read it carefully. A nice solution I really like was found by Alastair Reid. He proposed to me (hope it is ok to cite this) the declaration: data Salutation = [Either Char Name] We think it will not scale well, too, however, it is elegant due to its simplicity. Bye and thx, Steffen ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
Re: [Haskell] HaXml and XML Schema
I have started thinking about an extension of HaXml to better support XML Schema, i.e., to generate appropriate types (like DtdToHaskell) automatically (cf. Castor for Java). However, it is not obvious to me how to model mixed content (character data appears alongside subelements, i.e., it is not confined to the deepest subelement). We have worked on a XML Schema Haskell data binding, see Frank Atanassow, Dave Clarke, and Johan Jeuring. Scripting XML with Generic Haskell. In Proceedings of the 7th Brazilian Symposium on Programming Languages, SBLP 2003, 2003. and for just the data binding Frank Atanassow, Dave Clarke, and Johan Jeuring. UUXML: A Type-Preserving XML Schema Haskell Data Binding. Both are available from my homepage: http://www.cs.uu.nl/~johanj/publications/publications.html The modelling of ,ixed content is rather intricate, I'm afraid. -- Johan ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
[Haskell] HaXml and XML Schema
Hello, I have started thinking about an extension of HaXml to better support XML Schema, i.e., to generate appropriate types (like DtdToHaskell) automatically (cf. Castor for Java). However, it is not obvious to me how to model mixed content (character data appears alongside subelements, i.e., it is not confined to the deepest subelement). Example (readers familiar with the problem may skip this): salutationDear Mr.nameRobert Smith/name./salutation This structure is represented by the XML Schema xsd:element name=salutation xsd:complexType mixed=true xsd:sequence xsd:element name=name type=xsd:string/ /xsd:sequence /xsd:complexType /xsd:element How would you represent this in Haskell? A first idea may be to store the enclosing strings: data Salutation = Salutation String Name String This approach is not scaling well. E.g., there may be multiple names in the text... Do you have other ideas? Thank you and Happy Haskelling, Steffen ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell