1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
suite 'Creating XML using begin() callbacks:', ->
test 'Indentation', ->
result = ''
data = (chunk, level) ->
result += new Array(level).join('----') + chunk + '\n'
end = () ->
# remove trailing newline
result = result.slice(0, -1)
doc(data, end)
.dec()
.dtd('root', 'hello.dtd')
.ins('pub_border', 'thin')
.ele('img', 'EMPTY')
.com('Image attributes follow')
.att('img', 'height', 'CDATA', '#REQUIRED')
.att('img', 'visible', '(yes|no)', '#DEFAULT', "yes")
.not('fs', { sysID: 'http://my.fs.com/reader' })
.not('fs-nt', { pubID: 'FS Network Reader 1.0' })
.not('fs-nt', { pubID: 'FS Network Reader 1.0', sysID: 'http://my.fs.com/reader' })
.att('img', 'src', 'NOTATION (fs|fs-nt)', '#REQUIRED')
.dat('<owner>John</owner>')
.ele('node')
.ent('ent', 'my val')
.ent('ent', { sysID: 'http://www.myspec.com/ent' })
.ent('ent', { pubID: '-//MY//SPEC ENT//EN', sysID: 'http://www.myspec.com/ent' })
.ent('ent', { sysID: 'http://www.myspec.com/ent', nData: 'entprg' })
.ent('ent', { pubID: '-//MY//SPEC ENT//EN', sysID: 'http://www.myspec.com/ent', nData: 'entprg' })
.pent('ent', 'my val')
.pent('ent', { sysID: 'http://www.myspec.com/ent' })
.pent('ent', { pubID: '-//MY//SPEC ENT//EN', sysID: 'http://www.myspec.com/ent' })
.ele('nodearr', ['a', 'b'])
.up()
.ele('root')
.ele('xmlbuilder', {'for': 'node-js' })
.com('CoffeeScript is awesome.')
.nod('repo', {'type': 'git'}, 'git://github.com/oozcitak/xmlbuilder-js.git').up()
.nod('repo', 'git://github.com/oozcitak/xmlbuilder-js.git', {'type': 'git'}).up()
.up()
.ele('cdata')
.att('att', 'val')
.dat('<test att="val">this is a test</test>\nSecond line')
.txt('text node')
.ins('target', 'value')
.up()
.ele('raw')
.raw('&<>&')
.up()
.ele('atttest', { 'att': 'val' }, 'text')
.end()
eq(
result
"""
<?xml version="1.0"?>
<!DOCTYPE root SYSTEM "hello.dtd" [
----<?pub_border thin?>
----<!ELEMENT img EMPTY>
----<!-- Image attributes follow -->
----<!ATTLIST img height CDATA #REQUIRED>
----<!ATTLIST img visible (yes|no) "yes">
----<!NOTATION fs SYSTEM "http://my.fs.com/reader">
----<!NOTATION fs-nt PUBLIC "FS Network Reader 1.0">
----<!NOTATION fs-nt PUBLIC "FS Network Reader 1.0" "http://my.fs.com/reader">
----<!ATTLIST img src NOTATION (fs|fs-nt) #REQUIRED>
----<![CDATA[<owner>John</owner>]]>
----<!ELEMENT node (#PCDATA)>
----<!ENTITY ent "my val">
----<!ENTITY ent SYSTEM "http://www.myspec.com/ent">
----<!ENTITY ent PUBLIC "-//MY//SPEC ENT//EN" "http://www.myspec.com/ent">
----<!ENTITY ent SYSTEM "http://www.myspec.com/ent" NDATA entprg>
----<!ENTITY ent PUBLIC "-//MY//SPEC ENT//EN" "http://www.myspec.com/ent" NDATA entprg>
----<!ENTITY % ent "my val">
----<!ENTITY % ent SYSTEM "http://www.myspec.com/ent">
----<!ENTITY % ent PUBLIC "-//MY//SPEC ENT//EN" "http://www.myspec.com/ent">
----<!ELEMENT nodearr (a,b)>
]>
<root>
----<xmlbuilder for="node-js">
--------<!-- CoffeeScript is awesome. -->
--------<repo type="git">
------------git://github.com/oozcitak/xmlbuilder-js.git
--------</repo>
--------<repo type="git">
------------git://github.com/oozcitak/xmlbuilder-js.git
--------</repo>
----</xmlbuilder>
----<cdata att="val">
--------<![CDATA[<test att="val">this is a test</test>\nSecond line]]>
--------text node
--------<?target value?>
----</cdata>
----<raw>
--------&<>&
----</raw>
----<atttest att="val">
--------text
----</atttest>
</root>
"""
)
|