Last active
August 29, 2015 14:04
-
-
Save Pie001/3dd321ce30c2a1efdeac to your computer and use it in GitHub Desktop.
XML Parse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// XMLパーシング用 | |
function fnc_Xmlparse(xml) { | |
var arrayList = new Array(); | |
var nodecount = $(xml).find('content').length; | |
var nodename = $(xml).find('content').children(); | |
var childcount = $(xml).find('content').children().size(); | |
var nodeLen = childcount / nodecount; | |
var j = 0; | |
$(xml).find("content").each(function() { | |
var obj = {}; | |
for (var i = 0; i < nodeLen; i++) { | |
obj[nodename[i].tagName] = $(this).find(nodename[i].tagName).text() | |
} | |
arrayList[j] = obj; | |
j++; | |
}); | |
return arrayList; | |
} | |
// XML条件付きパーシング用(条件は1つのみ) | |
// xml : たxmlデータ | |
// filter : 条件を付ける項目名 | |
// param : 条件値 | |
// ex) fnc_XmlFilterParse(xmlObj, "flag", "2"); | |
function fnc_XmlFilterParse(xml, filter, param) { | |
var arrayList = new Array(); | |
var nodecount = $(xml).find('content').length; | |
var nodename = $(xml).find('content').children(); | |
var childcount = $(xml).find('content').children().size(); | |
var nodeLen = childcount / nodecount; | |
var j = 0; | |
$(xml).find("content").each(function() { | |
var obj = {}; | |
if ($(this).find(filter).text() == param) { | |
for (var i = 0; i < nodeLen; i++) { | |
obj[nodename[i].tagName] = $(this).find(nodename[i].tagName).text() | |
} | |
arrayList[j] = obj; | |
j++; | |
} | |
}); | |
return arrayList; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<item> | |
<content> | |
<title>title1</title> | |
<desc>desc2</desc> | |
<flag>1</flag> | |
</content> | |
<content> | |
<title>title2</title> | |
<desc>desc2</desc> | |
<flag>2</flag> | |
</content> | |
</item> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment