Personal tools

Xml

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
(formatting)
(More markup; removed link to blog article; added section heading "Introduction")
 
(One intermediate revision by one user not shown)
Line 1: Line 1:
Text.XML.Light
+
{{Stub}}
  
 +
== Introduction ==
 +
 +
 +
== Packages ==
 +
 +
[https://hackage.haskell.org/package/xml Packages on Hackage in the category XML]
 +
 +
=== xml ===
 +
 +
Module name: Text.XML.Light
  
 
Types:  
 
Types:  
Content, Element, CData, Attr are all instances of typeclass Node
+
<hask>Content, Element, CData, Attr</hask> are all instances of <hask>typeclass Node</hask>
  
 
A Node instance is anything which has some convention for generating an Element out of it.
 
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.  
+
Useful notes: <hask>Content</hask> has constructors for <hask>Elem</hask> and <hask>Text</hask>. <hask>CData</hask> can be of kind <hask>CDataText</hask>. The type <hask>QName</hask> (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]]
 
Read the few [[https://github.com/GaloisInc/xml/tree/master/tests test cases]]
Line 20: Line 27:
 
Constructing
 
Constructing
  
 +
<haskell>
 
let n = blank_name{qName = "td"}
 
let n = blank_name{qName = "td"}
 
 
let n2 = unqual "td"
 
let n2 = unqual "td"
 
 
let d = blank_cdata{cdData = "some data here"}
 
let d = blank_cdata{cdData = "some data here"}
 
 
blank_element {elName = n, elContent = [Text d]}
 
blank_element {elName = n, elContent = [Text d]}
 +
</haskell>
  
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.
+
using node <hask>qn _</hask>, generally expands to node <hask>qn ([attrs], [content])</hask>, where it lifts any child data provided into a content list and ensures any attribute provided is lifted into an attribute list. <hask>unode</hask> just makes a name out of an unqualified name before calling node.
  
 +
<haskell>
 
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"}]
 
+
</haskell>
  
  
 
Input
 
Input
  
 +
<haskell>
 
parseXMLDoc "<tr><td>some data here</td></tr>"
 
parseXMLDoc "<tr><td>some data here</td></tr>"
 
 
parseXML "<car><color>red</color></car><car><color>orange</color></car>"
 
parseXML "<car><color>red</color></car><car><color>orange</color></car>"
 
+
</haskell>
 
+
 
+
  
  
 
Output  
 
Output  
  
 +
<haskell>
 
showContent $ head $ parseXML "<car><color>black</color></car>"
 
showContent $ head $ parseXML "<car><color>black</color></car>"
 
 
ppContent $ head $ parseXML "<car><color>black</color></car>"
 
ppContent $ head $ parseXML "<car><color>black</color></car>"
 
+
</haskell>
  
  
 
Searching
 
Searching
 
+
<haskell>
 
findChildren blank_name{qName="td"}  $ fromJust $ parseXMLDoc "<tr><td>child1<td>inside</td></td><skip></skip><td>child2</td></tr>"
 
findChildren blank_name{qName="td"}  $ fromJust $ parseXMLDoc "<tr><td>child1<td>inside</td></td><skip></skip><td>child2</td></tr>"
 
 
filterChildren (\e -> (qName $ elName e) == "skip")  $ fromJust $ parseXMLDoc "<tr><td>child1<td>inside</td></td><skip></skip><td>child2</td></tr>"
 
filterChildren (\e -> (qName $ elName e) == "skip")  $ fromJust $ parseXMLDoc "<tr><td>child1<td>inside</td></td><skip></skip><td>child2</td></tr>"
 
 
findAttr (blank_name{qName = "width"}) $ fromJust $ parseXMLDoc "<tr width=10><td>child1<td>inside</td></td><skip></skip><td>child2</td></tr>"
 
findAttr (blank_name{qName = "width"}) $ fromJust $ parseXMLDoc "<tr width=10><td>child1<td>inside</td></td><skip></skip><td>child2</td></tr>"
 +
</haskell>
 +
 +
 +
== Blog articles ==
 +
 +
* []
 +
 +
 +
[[Category:Packages]]

Latest revision as of 08:14, 20 February 2014

This article is a stub. You can help by expanding it.

Contents

[edit] 1 Introduction

[edit] 2 Packages

Packages on Hackage in the category XML

[edit] 2.1 xml

Module name: 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 "<tr><td>some data here</td></tr>"
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 "<tr><td>child1<td>inside</td></td><skip></skip><td>child2</td></tr>"
filterChildren (\e -> (qName $ elName e) == "skip")  $ fromJust $ parseXMLDoc "<tr><td>child1<td>inside</td></td><skip></skip><td>child2</td></tr>"
findAttr (blank_name{qName = "width"}) $ fromJust $ parseXMLDoc "<tr width=10><td>child1<td>inside</td></td><skip></skip><td>child2</td></tr>"


[edit] 3 Blog articles

  • []