Skip to content

Commit 876ecf4

Browse files
committed
fixes #2
1 parent 14835df commit 876ecf4

File tree

10 files changed

+21
-17
lines changed

10 files changed

+21
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.iml

README.markdown

100644100755
File mode changed.

jquery.xml2json.iml

Lines changed: 0 additions & 11 deletions
This file was deleted.

js/xml2json.js

100644100755
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
(function(){
77
jQuery.extend({
88

9-
/**
9+
/**w
1010
* Converts an xml response object from a $.ajax() call to a JSON object.
1111
*
1212
* @param xml
@@ -21,7 +21,7 @@
2121
child = child == null ? {} : child;
2222

2323
if(result.hasOwnProperty(node.nodeName)) {
24-
// For repeating elements, cast the node to array
24+
// For repeating elements, cast/promote the node to array
2525
if(!(result[node.nodeName] instanceof Array)){
2626
var tmp = result[node.nodeName];
2727
result[node.nodeName] = [];
@@ -37,13 +37,13 @@
3737
result[node.nodeName]['@attributes'] = {};
3838
for(var j in node.attributes) {
3939
var attribute = node.attributes.item(j);
40-
result[node.nodeName]['@attributes'][attribute.nodeName] = attribute.nodeValue;
40+
child['@attributes'][attribute.nodeName] = attribute.nodeValue;
4141
}
4242
}
4343

4444
// Add element value
4545
if(node.childElementCount == 0 && node.textContent != null && node.textContent != "") {
46-
result[node.nodeName].value = node.textContent.trim();
46+
child.value = node.textContent.trim();
4747
}
4848
}
4949
}
File renamed without changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<test library="jquery.xml2json" version="0.1">
2+
<multiples>One</multiples>
23
<lorem sticky="true">Lorem ipsum... </lorem>
34
<cdata><![CDATA[Some cdata block...]]></cdata>
5+
<multiples>Two</multiples>
6+
<multiples>Three</multiples>
47
</test>

index.html renamed to tests/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
<link rel="stylesheet" type="text/css" href="css/qunit.css"/>
77

88
<script type="text/javascript" src="js/jquery-1.7.1.js"></script>
9-
<script type="text/javascript" src="js/xml2json.js"></script>
9+
<script type="text/javascript" src="../js/xml2json.js"></script>
1010
<script type="text/javascript" src="js/qunit.js"></script>
1111

12-
<script type="text/javascript" src="js/index.js"></script>
12+
<script type="text/javascript" src="js/tests.js"></script>
1313
</head>
1414
<body>
1515
<h1 id="qunit-header">jquery.xml2json Test Suite</h1>
File renamed without changes.
File renamed without changes.

js/index.js renamed to tests/js/tests.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ asyncTest("xml2json", function(){
2525
},
2626
value: 'Lorem ipsum...'
2727
},
28+
"multiples": [
29+
{
30+
value: 'One'
31+
},
32+
{
33+
value: 'Two'
34+
},
35+
{
36+
value: 'Three'
37+
}
38+
],
2839
cdata: {
2940
value: 'Some cdata block...'
3041
}

0 commit comments

Comments
 (0)