Skip to content

Commit 704ef38

Browse files
committed
Added processing instructions to JS object conversion
1 parent 8b5c179 commit 704ef38

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

src/XMLNode.coffee

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ module.exports = class XMLNode
4646
@attribute(attKey.substr(@stringify.convertAttKey.length), attVal)
4747
delete name[attKey]
4848

49+
# assign processing instructions and remove from this object
50+
for own piKey, piVal of name
51+
if @stringify.convertPIKey and piKey.indexOf(@stringify.convertPIKey) == 0
52+
@instruction(piKey.substr(@stringify.convertPIKey.length), piVal)
53+
delete name[piKey]
54+
4955
# insert children
5056
for own key, val of name
5157

src/XMLStringifier.coffee

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ module.exports = class XMLStringifier
5959

6060
# strings to match while converting from JS objects
6161
convertAttKey: '@'
62+
convertPIKey: '!'
6263
convertTextKey: '#text'
6364
convertCDataKey: '#cdata'
6465
convertCommentKey: '#comment'

test/object.coffee

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ vows
6060
person:
6161
name: "John"
6262
'@age': 35
63+
'!pi': 'mypi'
6364
'#comment': 'Good guy'
6465
'#cdata': 'well formed!'
6566
unescaped:
@@ -83,6 +84,7 @@ vows
8384
'resulting XML': (topic) ->
8485
xml = '<root>' +
8586
'<ele>simple element</ele>' +
87+
'<?pi mypi?>' +
8688
'<person age="35">' +
8789
'<name>John</name>' +
8890
'<!-- Good guy -->' +

0 commit comments

Comments
 (0)