Update xml.js

This commit is contained in:
Namhyeon Go 2023-01-05 05:37:13 +09:00 committed by GitHub
parent 0ab224b987
commit b3facdcaae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,12 +3,13 @@
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
var FILE = require("lib/file"); var FILE = require("lib/file");
var adTypeText = 2;
var adTypeBinary = 1;
var StreamConvert = function(data) { var StreamConvert = function(data) {
this.data = data; this.data = data;
this.toBinary = function() { this.toBinary = function() {
var adTypeText = 2;
var adTypeBinary = 1;
var BinaryStream = CreateObject("ADODB.Stream"); var BinaryStream = CreateObject("ADODB.Stream");
BinaryStream.Type = adTypeText; BinaryStream.Type = adTypeText;
BinaryStream.CharSet = "utf-8"; BinaryStream.CharSet = "utf-8";
@ -21,8 +22,6 @@ var StreamConvert = function(data) {
}; };
this.toString = function() { this.toString = function() {
var adTypeText = 2;
var adTypeBinary = 1;
var BinaryStream = CreateObject("ADODB.Stream"); var BinaryStream = CreateObject("ADODB.Stream");
BinaryStream.Type = adTypeBinary; BinaryStream.Type = adTypeBinary;
BinaryStream.Open(); BinaryStream.Open();
@ -32,7 +31,6 @@ var StreamConvert = function(data) {
BinaryStream.CharSet = "utf-8"; BinaryStream.CharSet = "utf-8";
return BinaryStream.ReadText(); return BinaryStream.ReadText();
}; };
}; };
var XMLObject = function(dom) { var XMLObject = function(dom) {
@ -122,11 +120,7 @@ var XMLObject = function(dom) {
var node = dom.createElement("XMLNode"); var node = dom.createElement("XMLNode");
node.dataType = type; node.dataType = type;
if (type.indexOf("bin.") == 0) {
node.nodeTypedValue = (new StreamConvert(value)).toBinary(); node.nodeTypedValue = (new StreamConvert(value)).toBinary();
} else {
node.nodeTypedValue = value;
}
return node.text; return node.text;
} catch (e) { } catch (e) {
@ -140,27 +134,36 @@ var XMLObject = function(dom) {
var node = dom.createElement("XMLNode"); var node = dom.createElement("XMLNode");
node.dataType = type; node.dataType = type;
if (type.indexOf("bin.") == 0) {
node.text = (new StreamConvert(value)).toString();
} else {
node.text = value; node.text = value;
}
return node.nodeTypedValue; return (new StreamConvert(node.nodeTypedValue)).toString();
} catch (e) { } catch (e) {
console.error("XMLObject->decode():", e.message); console.error("XMLObject->decode():", e.message);
} }
}; };
}; };
exports.create = function() { function create() {
return (new XMLObject()); return new XMLObject();
}; }
exports.load = function(s) { function load(s) {
return (new XMLObject()).load(s); return create().load(s);
}; }
exports.VERSIONINFO = "XML interface (xml.js) version 0.2"; function encode(value, type) {
return create().encode(value, type);
}
function decode(value, type) {
return create().decode(value, type);
}
exports.create = create;
exports.load = load;
exports.encode = encode;
exports.decode = decode;
exports.VERSIONINFO = "XML interface (xml.js) version 0.2.2";
exports.global = global; exports.global = global;
exports.require = global.require; exports.require = global.require;