Permalink
Browse files

Added processing instructions, comments and cdata to dtd

  • Loading branch information...
1 parent 80c45e8 commit 8458698c4f4930ec0c6f6802de23c99bf136865f @oozcitak committed Dec 22, 2013
Showing with 40 additions and 0 deletions.
  1. +34 −0 src/XMLDocType.coffee
  2. +6 −0 test/doctype.coffee
View
34 src/XMLDocType.coffee
@@ -50,6 +50,37 @@ module.exports = class XMLDocType
return @
+ # Creates a CDATA node
+ #
+ # `value` element text without CDATA delimiters
+ cdata: (value) ->
+ XMLCData = require './XMLCData'
+ child = new XMLCData @, value
+ @children.push child
+ return @
+
+
+ # Creates a comment node
+ #
+ # `value` comment text
+ comment: (value) ->
+ XMLComment = require './XMLComment'
+ child = new XMLComment @, value
+ @children.push child
+ return @
+
+
+ # Adds a processing instruction
+ #
+ # `target` instruction target
+ # `value` instruction value
+ instruction: (target, value) ->
+ XMLProcessingInstruction = require './XMLProcessingInstruction'
+ child = new XMLProcessingInstruction @, target, value
+ @children.push child
+ return @
+
+
# Gets the root node
root: () ->
@documentObject.root()
@@ -106,5 +137,8 @@ module.exports = class XMLDocType
ele: (name, value) -> @element name, value
att: (elementName, attributeName, attributeType, defaultValueType, defaultValue) ->
@attList elementName, attributeName, attributeType, defaultValueType, defaultValue
+ dat: (value) -> @cdata value
+ com: (value) -> @comment value
+ ins: (target, value) -> @instruction target, value
up: () -> @root()
doc: () -> @document()
View
6 test/doctype.coffee
@@ -43,19 +43,25 @@ vows
topic: () ->
xmlbuilder.create('root')
.dtd('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")
+ .dat('<owner>John</owner>')
.ele('node')
.root()
.ele('node').txt('test')
'resulting XML': (topic) ->
xml = '<?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">' +
+ '<![CDATA[<owner>John</owner>]]>' +
'<!ELEMENT node (#PCDATA)>' +
']>' +
'<root><node>test</node></root>'

0 comments on commit 8458698

Please sign in to comment.