# Test_Xml

Provides unit tests and examples for the <Xml> lens.

Summary

Test_Xml | Provides unit tests and examples for the <Xml> lens.
knode | A simple flag function
Utilities lens |
Comments |
Xml.comment | Comments get mapped into “#comment” nodes.
Xml.comment | This syntax is not understood.
Prolog and declarations |
Xml.prolog | The XML prolog tag is mapped in a “#declaration” node, which contains an “#attribute” node with various attributes of the tag.
Xml.decl_def_item | !ELEMENT declaration tags are mapped in “!ELEMENT” nodes.
Xml.decl_def_item | !ENTITY declaration tags are mapped in “!ENTITY” nodes.
Xml.doctype | !DOCTYPE tags are mapped in “!DOCTYPE” nodes.
Xml.doctype | This is an example of a !DOCTYPE tag with !ELEMENT children tags.
Attributes |
att_def1 |
att_def2 |
att_def3 |
Xml.att_list_def |
Xml.att_list_def |
Xml.att_list_def |
Xml.notation_def |
cdata1 |
Xml.cdata |
attr1 |
attr2 |
Xml.attributes |
Xml.attributes |
Xml.attributes |
empty |
empty1 |
empty2 |
empty3 |
empty4 |
Xml.empty_element |
Xml.empty_element |
Xml.empty_element |
Xml.empty_element | The attribute node must be the first child of the element
Xml.content |
Full lens |
Xml.lns |
Xml.lns |
Xml.lns |
input1 |
Xml.doc | Test input1 with Xml.doc
Xml.doc | Modify input1 with Xml.doc
ul1 |

### knode

> let knode (r:regexp) = [ key r ]

A simple flag function

#### Parameters

r:regexp | the pattern for the flag

### Utilities lens

### Comments

### Xml.comment

> test Xml.comment get "<!-- declarations for <head> & <body> -->" = { "#comment" = " declarations for <head> & <body> " }

Comments get mapped into “#comment” nodes.

### Xml.comment

> test Xml.comment get "<!-- B+, B, or B--->" = *

This syntax is not understood.

### Prolog and declarations

### Xml.prolog

> test Xml.prolog get "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" = { "#declaration" { "#attribute" { "version" = "1.0" } { "encoding" = "UTF-8" } } }

The XML prolog tag is mapped in a “#declaration” node, which contains an “#attribute” node with various attributes of the tag.

### Xml.decl_def_item

> test Xml.decl_def_item get "<!ELEMENT greeting (#PCDATA)>" = { "!ELEMENT" = "greeting" { "#decl" = "(#PCDATA)" } }

!ELEMENT declaration tags are mapped in “!ELEMENT” nodes. The associated declaration attribute is mapped in a “#decl” subnode.

### Xml.decl_def_item

> test Xml.decl_def_item get "<!ENTITY da \"&#xD;&#xA;\">" = { "!ENTITY" = "da" { "#decl" = "&#xD;&#xA;" } }

!ENTITY declaration tags are mapped in “!ENTITY” nodes. The associated declaration attribute is mapped in a “#decl” subnode.

### Xml.doctype

> test Xml.doctype get "<!DOCTYPE greeting:foo SYSTEM \"hello.dtd\">" = { "!DOCTYPE" = "greeting:foo" { "SYSTEM" = "hello.dtd" } }

!DOCTYPE tags are mapped in “!DOCTYPE” nodes. The associated system attribute is mapped in a “SYSTEM” subnode.

### Xml.doctype

> test Xml.doctype get "<!DOCTYPE foo [ <!ELEMENT bar (#PCDATA)> <!ELEMENT baz (bar)* > ]>" = { "!DOCTYPE" = "foo" { "!ELEMENT" = "bar" { "#decl" = "(#PCDATA)" } } { "!ELEMENT" = "baz" { "#decl" = "(bar)*" } } }

This is an example of a !DOCTYPE tag with !ELEMENT children tags.

### Attributes

### att_def1

> let att_def1 = "<!ATTLIST termdef id ID #REQUIRED name CDATA #IMPLIED>"

### att_def2

> let att_def2 = "<!ATTLIST list type (bullets|ordered|glossary) \"ordered\">"

### att_def3

> let att_def3 = "<!ATTLIST form method CDATA #FIXED \"POST\">"

### Xml.att_list_def

> test Xml.att_list_def get att_def1 = { "!ATTLIST" = "termdef" { "1" { "#name" = "id" } { "#type" = "ID" } { "#REQUIRED" } } { "2" { "#name" = "name" } { "#type" = "CDATA" } { "#IMPLIED" } } }

### Xml.att_list_def

> test Xml.att_list_def get att_def2 = { "!ATTLIST" = "list" { "1" { "#name" = "type" } { "#type" = "(bullets|ordered|glossary)" } { "#FIXED" = "ordered" } } }

### Xml.att_list_def

> test Xml.att_list_def get att_def3 = { "!ATTLIST" = "form" { "1" { "#name" = "method" } { "#type" = "CDATA" } { "#FIXED" = "POST" } } }

### Xml.notation_def

> test Xml.notation_def get "<!NOTATION not3 SYSTEM \"\">" = { "!NOTATION" = "not3" { "SYSTEM" = "" } }

### cdata1

> let cdata1 = "<![CDATA[testing]]>"

### Xml.cdata

> test Xml.cdata get cdata1 = { "#CDATA" = "testing" }

### attr1

> let attr1 = " attr1=\"value1\" attr2=\"value2\""

### attr2

> let attr2 = " attr2=\"foo\""

### Xml.attributes

> test Xml.attributes get attr1 = { "#attribute" { "attr1" = "value1" } { "attr2" = "value2" } }

### Xml.attributes

> test Xml.attributes get " refs=\"A1\nA2 A3\"" = { "#attribute" { "refs" = "A1\nA2 A3" } }

### Xml.attributes

> test Xml.attributes put attr1 after rm "/#attribute[1]"; set "/#attribute/attr2" "foo" = attr2

### empty

### empty1

> let empty1 = "<a/>"

### empty2

> let empty2 = "<a foo=\"bar\"/>"

### empty3

> let empty3 = "<a foo=\"bar\"></a>\n"

### empty4

> let empty4 = "<a foo=\"bar\" far=\"baz\"/>"

### Xml.empty_element

> test Xml.empty_element get empty1 = { "a" = "#empty" }

### Xml.empty_element

> test Xml.empty_element get empty2 = { "a" = "#empty" { "#attribute" { "foo" = "bar"} } }

### Xml.empty_element

> test Xml.empty_element put empty1 after set "/a/#attribute/foo" "bar" = empty2

### Xml.empty_element

> test Xml.empty_element put empty1 after set "/a/#attribute/foo" "bar"; set "/a/#attribute/far" "baz" = empty4

The attribute node must be the first child of the element

### Xml.content

> test Xml.content put "<a><b/></a>" after clear "/a/b" = "<a><b></b>\n</a>"

### Full lens

### Xml.lns

> test Xml.lns put "<a></a >" after set "/a/#text[1]" "foo"; set "/a/#text[2]" "bar" = "<a>foobar</a >"

### Xml.lns

> 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" }

### Xml.lns

> test Xml.lns get "<oor:component-data xmlns:oor=\"http://openoffice.org/2001/registry\"/> " = { "oor:component-data" = "#empty" { "#attribute" { "xmlns:oor" = "http://openoffice.org/2001/registry" } } }

### input1

> 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> "

### 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" = " " } } }

Test input1 with Xml.doc

### Xml.doc

> test Xml.doc put input1 after rm "/html/body" = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <html>\r <head> <title>Wiki</title> </head> </html> "

Modify input1 with Xml.doc

### ul1

> 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" } } }

> let knode (r:regexp) = [ key r ]

A simple flag function

> test Xml.comment get "<!-- declarations for <head> & <body> -->" = { "#comment" = " declarations for <head> & <body> " }

Comments get mapped into “#comment” nodes.

> test Xml.prolog get "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" = { "#declaration" { "#attribute" { "version" = "1.0" } { "encoding" = "UTF-8" } } }

The XML prolog tag is mapped in a “#declaration” node, which contains an “#attribute” node with various attributes of the tag.

> test Xml.decl_def_item get "<!ELEMENT greeting (#PCDATA)>" = { "!ELEMENT" = "greeting" { "#decl" = "(#PCDATA)" } }

!ELEMENT declaration tags are mapped in “!ELEMENT” nodes.

> test Xml.doctype get "<!DOCTYPE greeting:foo SYSTEM \"hello.dtd\">" = { "!DOCTYPE" = "greeting:foo" { "SYSTEM" = "hello.dtd" } }

!DOCTYPE tags are mapped in “!DOCTYPE” nodes.

> 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 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" = " " } } }

Test input1 with Xml.doc

> 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" } } }

Close