Provides unit tests and examples for the <Xml> lens.
Test_Xml | Provides unit tests and examples for the <Xml> lens. |
knode | A simple flag function |
Utilities lens | |
Comments | |
Xml. | Comments get mapped into “#comment” nodes. |
Xml. | This syntax is not understood. |
Prolog and declarations | |
Xml. | The XML prolog tag is mapped in a “#declaration” node, which contains an “#attribute” node with various attributes of the tag. |
Xml. | !ELEMENT declaration tags are mapped in “!ELEMENT” nodes. |
Xml. | !ENTITY declaration tags are mapped in “!ENTITY” nodes. |
Xml. | !DOCTYPE tags are mapped in “!DOCTYPE” nodes. |
Xml. | This is an example of a !DOCTYPE tag with !ELEMENT children tags. |
Attributes | |
att_def1 | |
att_def2 | |
att_def3 | |
Xml. | |
Xml. | |
Xml. | |
Xml. | |
cdata1 | |
Xml. | |
attr1 | |
attr2 | |
Xml. | |
Xml. | |
Xml. | |
empty | |
empty1 | |
empty2 | |
empty3 | |
empty4 | |
Xml. | |
Xml. | |
Xml. | |
Xml. | The attribute node must be the first child of the element |
Xml. | |
Full lens | |
Xml.lns | |
Xml.lns | |
Xml.lns | |
input1 | |
Xml.doc | Test input1 with Xml.doc |
Xml.doc | Modify input1 with Xml.doc |
ul1 |
test Xml.lns get "<?xml version=\"1.0\"?> <!DOCTYPE catalog PUBLIC \"-//OASIS//DTD XML Catalogs V1.0//EN\" \"file:///usr/share/xml/schema/xml-core/catalog.dtd\"> <doc/>" = { "#declaration" { "#attribute" { "version" = "1.0" } } } { "!DOCTYPE" = "catalog" { "PUBLIC" { "#literal" = "-//OASIS//DTD XML Catalogs V1.0//EN" } { "#literal" = "file:///usr/share/xml/schema/xml-core/catalog.dtd" } } } { "doc" = "#empty" }
let input1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <html>\r <head> <title>Wiki</title> </head> <body> <h1>Augeas</h1> <p class=\"main\">Augeas is now able to parse XML files!</p> <ul> <li>Translate from XML to a tree syntax</li> <li>Translate from the tree back to XML</li> <!-- this is some comment --> <li>this</li> </ul> </body> </html> "
test Xml.doc get input1 = { "#declaration" { "#attribute" { "version" = "1.0" } { "encoding" = "UTF-8" } } } { "html" { "#text" = "\r\n " } { "head" { "#text" = "\n " } { "title" { "#text" = "Wiki" } } { "#text" = " " } } { "#text" = " " } { "body" { "#text" = " " } { "h1" { "#text" = "Augeas" } } { "#text" = " " } { "p" { "#attribute" { "class" = "main" } } { "#text" = "Augeas is now able to parse XML files!" } } { "#text" = " " } { "ul" { "#text" = "\n " } { "li" { "#text" = "Translate from XML to a tree syntax" } } { "#text" = " " } { "li" { "#text" = "Translate from the tree back to XML" } } { "#text" = " " } { "#comment" = " this is some comment " } { "#text" = " " } { "li" { "#text" = "this" } } { "#text" = " " } } { "#text" = " " } } }
let ul1 = " <ul> <li>test1</li> <li>test2</li> <li>test3</li> <li>test4</li> </ul> " test Xml.doc get ul1 = { "ul" { "#text" = " " } { "li" { "#text" = "test1" } } { "#text" = " " } { "li" { "#text" = "test2" } } { "#text" = " " } { "li" { "#text" = "test3" } } { "#text" = " " } { "li" { "#text" = "test4" } } }
A simple flag function
let knode (r:regexp) = [ key r ]
Comments get mapped into “#comment” nodes.
test Xml.comment get "<!-- declarations for <head> & <body> -->" = { "#comment" = " declarations for <head> & <body> " }
The XML prolog tag is mapped in a “#declaration” node, which contains an “#attribute” node with various attributes of the tag.
test Xml.prolog get "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" = { "#declaration" { "#attribute" { "version" = "1.0" } { "encoding" = "UTF-8" } } }
!ELEMENT declaration tags are mapped in “!ELEMENT” nodes.
test Xml.decl_def_item get "<!ELEMENT greeting (#PCDATA)>" = { "!ELEMENT" = "greeting" { "#decl" = "(#PCDATA)" } }
!DOCTYPE tags are mapped in “!DOCTYPE” nodes.
test Xml.doctype get "<!DOCTYPE greeting:foo SYSTEM \"hello.dtd\">" = { "!DOCTYPE" = "greeting:foo" { "SYSTEM" = "hello.dtd" } }
let att_def1 = "<!ATTLIST termdef id ID #REQUIRED name CDATA #IMPLIED>"
let att_def2 = "<!ATTLIST list type (bullets|ordered|glossary) \"ordered\">"
let att_def3 = "<!ATTLIST form method CDATA #FIXED \"POST\">"
test Xml.att_list_def get att_def1 = { "!ATTLIST" = "termdef" { "1" { "#name" = "id" } { "#type" = "ID" } { "#REQUIRED" } } { "2" { "#name" = "name" } { "#type" = "CDATA" } { "#IMPLIED" } } }
test Xml.notation_def get "<!NOTATION not3 SYSTEM \"\">" = { "!NOTATION" = "not3" { "SYSTEM" = "" } }
let cdata1 = "<![CDATA[testing]]>"
test Xml.cdata get cdata1 = { "#CDATA" = "testing" }
let attr1 = " attr1=\"value1\" attr2=\"value2\""
let attr2 = " attr2=\"foo\""
test Xml.attributes get attr1 = { "#attribute" { "attr1" = "value1" } { "attr2" = "value2" } }
let empty1 = "<a/>"
let empty2 = "<a foo=\"bar\"/>"
let empty3 = "<a foo=\"bar\"></a>\n"
let empty4 = "<a foo=\"bar\" far=\"baz\"/>"
test Xml.empty_element get empty1 = { "a" = "#empty" }
test Xml.content put "<a><b/></a>" after clear "/a/b" = "<a><b></b>\n</a>"
test Xml.lns put "<a></a >" after set "/a/#text[1]" "foo"; set "/a/#text[2]" "bar" = "<a>foobar</a >"
let input1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <html>\r <head> <title>Wiki</title> </head> <body> <h1>Augeas</h1> <p class=\"main\">Augeas is now able to parse XML files!</p> <ul> <li>Translate from XML to a tree syntax</li> <li>Translate from the tree back to XML</li> <!-- this is some comment --> <li>this</li> </ul> </body> </html> "
Test input1 with Xml.doc
test Xml.doc get input1 = { "#declaration" { "#attribute" { "version" = "1.0" } { "encoding" = "UTF-8" } } } { "html" { "#text" = "\r\n " } { "head" { "#text" = "\n " } { "title" { "#text" = "Wiki" } } { "#text" = " " } } { "#text" = " " } { "body" { "#text" = " " } { "h1" { "#text" = "Augeas" } } { "#text" = " " } { "p" { "#attribute" { "class" = "main" } } { "#text" = "Augeas is now able to parse XML files!" } } { "#text" = " " } { "ul" { "#text" = "\n " } { "li" { "#text" = "Translate from XML to a tree syntax" } } { "#text" = " " } { "li" { "#text" = "Translate from the tree back to XML" } } { "#text" = " " } { "#comment" = " this is some comment " } { "#text" = " " } { "li" { "#text" = "this" } } { "#text" = " " } } { "#text" = " " } } }
let ul1 = " <ul> <li>test1</li> <li>test2</li> <li>test3</li> <li>test4</li> </ul> " test Xml.doc get ul1 = { "ul" { "#text" = " " } { "li" { "#text" = "test1" } } { "#text" = " " } { "li" { "#text" = "test2" } } { "#text" = " " } { "li" { "#text" = "test3" } } { "#text" = " " } { "li" { "#text" = "test4" } } }