<commit_before>/* This work is licensed under Creative Commons GNU LGPL License.

 License: http://creativecommons.org/licenses/LGPL/2.1/
 Version: 0.9
 Author:  <NAME>/2006
 See:     http://goessner.net/download/prj/jsonxml/
 */
define(function() {

	return {
		read: function(xml, clean) {
			var X = {
				at: ( clean ? "" : "@"),

				toObj: function(xml) {
					var o = {};
					if (xml.nodeType == 1) {// element node
						if (xml.attributes.length) {// element with attributes
							for (var i = 0; i < xml.attributes.length; i++) {
								var name = xml.attributes[i].nodeName;
								var value = xml.attributes[i].nodeValue;
								var is_ns = name.lastIndexOf("xmlns:", 0) === 0;
								if (!(clean && is_ns)) {// Hide xmlns attributes
									o[X.at + name] = (value || "").toString();
								}
							}
						}
						if (xml.firstChild) {// element has child nodes
							var textChild = 0, cdataChild = 0, hasElementChild = false;
							for (var n = xml.firstChild; n; n = n.nextSibling) {
								if (n.nodeType == 1) {
									hasElementChild = true;
								} else if (n.nodeType == 3 && n.nodeValue.match(/[^ \f\n\r\t\v]/)) {
									textChild++;
									// non-whitespace text
								} else if (n.nodeType == 4) {
									cdataChild++;
									// cdata section node
								}
							}
							if (hasElementChild) {
								if (textChild < 2 && cdataChild < 2) {
									// structured element with evtl.
									// a single text or/and cdata node
									X.removeWhite(xml);
									for (var n = xml.firstChild; n; n = n.nextSibling) {
										if (n.nodeType == 3) {// text node
											o["#text"] = X.escape(n.nodeValue);
										} else if (n.nodeType == 4) {// cdata node
											o["#cdata"] = X.escape(n.nodeValue);
										} else if (o[n.nodeName]) {
											// multiple occurence of element
											if (o[n.nodeName] instanceof Array) {
												o[n.nodeName][o[n.nodeName].length] = X.toObj(n);
											} else {
												o[n.nodeName] = [o[n.nodeName], X.toObj(n)];
											}
										} else {// first occurence of element
											o[n.nodeName] = X.toObj(n);
										}
									}
								} else {// mixed content
									if (!xml.attributes.length) {
										o = X.escape(X.innerXml(xml));
									} else {
										o["#text"] = X.escape(X.innerXml(xml));
									}
								}
							} else if (textChild) {// pure text
								if (!xml.attributes.length) {
									o = X.escape(X.innerXml(xml));
								} else {
									o["#text"] = X.escape(X.innerXml(xml));
								}
							} else if (cdataChild) {// cdata
								if (cdataChild > 1) {
									o = X.escape(X.innerXml(xml));
								} else {
									for (var n = xml.firstChild; n; n = n.nextSibling) {
										o["#cdata"] = X.escape(n.nodeValue);
									}
								}
							}
						}
						if (!xml.attributes.length && !xml.firstChild) {
							o = null;
						}
					} else if (xml.nodeType == 9) {// document.node
						o = X.toObj(xml.documentElement);
					} else if (xml.nodeType == 8) {
						return xml.data;
						// A comment
					} else {
						// TODO better error handling
						alert("unhandled node type: " + xml.nodeType);
					}

					return o;
				},

				innerXml: function(node) {
					var s = "";
					if ("innerHTML" in node) {
						s = node.innerHTML;
					} else {
						var asXml = function(n) {
							var s = "";
							if (n.nodeType == 1) {
								s += "<" + n.nodeName;
								for (var i = 0; i < n.attributes.length; i++) {
									var name = n.attributes[i].nodeName;
									var value = n.attributes[i].nodeValue || "";
									s += " " + name + "=\"" + value.toString() + "\"";
								}
								if (n.firstChild) {
									s += ">";
									for (var c = n.firstChild; c; c = c.nextSibling) {
										s += asXml(c);
									}
									s += "</" + n.nodeName + ">";
								} else {
									s += "/>";
								}
							} else if (n.nodeType == 3) {
								s += n.nodeValue;
							} else if (n.nodeType == 4) {
								s += "<![CDATA[" + n.nodeValue + "]]>";<commit_msg>Use Attr interface to get attribute names and values (former code was deprecated)<commit_after>/* This work is licensed under Creative Commons GNU LGPL License.

 License: http://creativecommons.org/licenses/LGPL/2.1/
 Version: 0.9
 Author:  <NAME>/2006
 See:     http://goessner.net/download/prj/jsonxml/
 */
define(function() {

	return {
		read: function(xml, clean) {
			var X = {
				at: ( clean ? "" : "@"),

				toObj: function(xml) {
					var o = {};
					if (xml.nodeType == 1) {// element node
						if (xml.attributes.length) {// element with attributes
							for (var i = 0; i < xml.attributes.length; i++) {
								var name = xml.attributes[i].name;
								var value = xml.attributes[i].value;
								var is_ns = name.lastIndexOf("xmlns:", 0) === 0;
								if (!(clean && is_ns)) {// Hide xmlns attributes
									o[X.at + name] = (value || "").toString();
								}
							}
						}
						if (xml.firstChild) {// element has child nodes
							var textChild = 0, cdataChild = 0, hasElementChild = false;
							for (var n = xml.firstChild; n; n = n.nextSibling) {
								if (n.nodeType == 1) {
									hasElementChild = true;
								} else if (n.nodeType == 3 && n.nodeValue.match(/[^ \f\n\r\t\v]/)) {
									textChild++;
									// non-whitespace text
								} else if (n.nodeType == 4) {
									cdataChild++;
									// cdata section node
								}
							}
							if (hasElementChild) {
								if (textChild < 2 && cdataChild < 2) {
									// structured element with evtl.
									// a single text or/and cdata node
									X.removeWhite(xml);
									for (var n = xml.firstChild; n; n = n.nextSibling) {
										if (n.nodeType == 3) {// text node
											o["#text"] = X.escape(n.nodeValue);
										} else if (n.nodeType == 4) {// cdata node
											o["#cdata"] = X.escape(n.nodeValue);
										} else if (o[n.nodeName]) {
											// multiple occurence of element
											if (o[n.nodeName] instanceof Array) {
												o[n.nodeName][o[n.nodeName].length] = X.toObj(n);
											} else {
												o[n.nodeName] = [o[n.nodeName], X.toObj(n)];
											}
										} else {// first occurence of element
											o[n.nodeName] = X.toObj(n);
										}
									}
								} else {// mixed content
									if (!xml.attributes.length) {
										o = X.escape(X.innerXml(xml));
									} else {
										o["#text"] = X.escape(X.innerXml(xml));
									}
								}
							} else if (textChild) {// pure text
								if (!xml.attributes.length) {
									o = X.escape(X.innerXml(xml));
								} else {
									o["#text"] = X.escape(X.innerXml(xml));
								}
							} else if (cdataChild) {// cdata
								if (cdataChild > 1) {
									o = X.escape(X.innerXml(xml));
								} else {
									for (var n = xml.firstChild; n; n = n.nextSibling) {
										o["#cdata"] = X.escape(n.nodeValue);
									}
								}
							}
						}
						if (!xml.attributes.length && !xml.firstChild) {
							o = null;
						}
					} else if (xml.nodeType == 9) {// document.node
						o = X.toObj(xml.documentElement);
					} else if (xml.nodeType == 8) {
						return xml.data;
						// A comment
					} else {
						// TODO better error handling
						alert("unhandled node type: " + xml.nodeType);
					}

					return o;
				},

				innerXml: function(node) {
					var s = "";
					if ("innerHTML" in node) {
						s = node.innerHTML;
					} else {
						var asXml = function(n) {
							var s = "";
							if (n.nodeType == 1) {
								s += "<" + n.nodeName;
								for (var i = 0; i < n.attributes.length; i++) {
									var name = n.attributes[i].name;
									var value = n.attributes[i].value || "";
									s += " " + name + "=\"" + value.toString() + "\"";
								}
								if (n.firstChild) {
									s += ">";
									for (var c = n.firstChild; c; c = c.nextSibling) {
										s += asXml(c);
									}
									s += "</" + n.nodeName + ">";
								} else {
									s += "/>";
								}
							} else if (n.nodeType == 3) {
								s += n.nodeValue;
							} else if (n.nodeType == 4) {
								s += "<![CDATA[" + n.nodeValue + "]]>";
{'fraction_non_alphanumeric': 0.1677671802396674, 'fraction_numerical': 0.006847640009782343, 'mean_word_length': 1.5923930269413629, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 58}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2828318', 'n_tokens_mistral': 4327, 'n_tokens_neox': 2732, 'n_words': 640}