Difference between revisions of "Xml"

From HaskellWiki
Jump to navigation Jump to search
(Created page with "Text.XML.Light Read the few https://github.com/GaloisInc/xml/tree/master/tests test cases Types: Content, Element, CData, Attr are all instances of typeclass Node A No...")
 
(formatting)
Line 1: Line 1:
 
Text.XML.Light
 
Text.XML.Light
   
Read the few [[https://github.com/GaloisInc/xml/tree/master/tests test cases]]
 
   
 
Types:
 
Types:
Line 9: Line 8:
   
 
Useful notes: Content has constructors for Elem and Text. CData can be of kind CDataText. The type QName (qualified name) denotes a name with its qualifying namespace attached to it.
 
Useful notes: Content has constructors for Elem and Text. CData can be of kind CDataText. The type QName (qualified name) denotes a name with its qualifying namespace attached to it.
  +
  +
  +
   
 
Snippets of essentials:
 
Snippets of essentials:
  +
  +
 
Read the few [[https://github.com/GaloisInc/xml/tree/master/tests test cases]]
  +
   
 
Constructing
 
Constructing
   
 
let n = blank_name{qName = "td"}
 
let n = blank_name{qName = "td"}
  +
 
let n2 = unqual "td"
 
let n2 = unqual "td"
   
Line 24: Line 31:
   
 
unode "td" ()
 
unode "td" ()
  +
 
unode "td" $ Attr (unqual "width") "10"
 
unode "td" $ Attr (unqual "width") "10"
  +
 
unode "td" $ "some data"
 
unode "td" $ "some data"
  +
 
unode "tr" [Elem $ unode "td" "some data", Text $ blank_cdata{cdData = "free text"}]
 
unode "tr" [Elem $ unode "td" "some data", Text $ blank_cdata{cdData = "free text"}]
  +
   
   
Line 44: Line 55:
   
 
ppContent $ head $ parseXML "<car><color>black</color></car>"
 
ppContent $ head $ parseXML "<car><color>black</color></car>"
  +
   
   

Revision as of 01:44, 20 September 2013

Text.XML.Light


Types: Content, Element, CData, Attr are all instances of typeclass Node

A Node instance is anything which has some convention for generating an Element out of it.

Useful notes: Content has constructors for Elem and Text. CData can be of kind CDataText. The type QName (qualified name) denotes a name with its qualifying namespace attached to it.



Snippets of essentials:


Read the few [test cases]


Constructing

let n = blank_name{qName = "td"}

let n2 = unqual "td"

let d = blank_cdata{cdData = "some data here"}

blank_element {elName = n, elContent = [Text d]}

using node qn _, generally expands to node qn ([attrs], [content]), where it lifts any child data provided into a content list and ensures any attribute provided is lifted into an attribute list. unode just makes a name out of an unqualified name before calling node.

unode "td" ()

unode "td" $ Attr (unqual "width") "10"

unode "td" $ "some data"

unode "tr" [Elem $ unode "td" "some data", Text $ blank_cdata{cdData = "free text"}]


Input

parseXMLDoc "some data here"

parseXML "<car><color>red</color></car><car><color>orange</color></car>"



Output

showContent $ head $ parseXML "<car><color>black</color></car>"

ppContent $ head $ parseXML "<car><color>black</color></car>"


Searching

findChildren blank_name{qName="td"} $ fromJust $ parseXMLDoc "child1inside<skip></skip>child2" filterChildren (\e -> (qName $ elName e) == "skip") $ fromJust $ parseXMLDoc "child1inside<skip></skip>child2" findAttr (blank_name{qName = "width"}) $ fromJust $ parseXMLDoc "child1inside<skip></skip>child2"