mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-08 20:56:04 +00:00
Update xml.js
This commit is contained in:
parent
0ab224b987
commit
b3facdcaae
49
lib/xml.js
49
lib/xml.js
|
@ -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 = value;
|
||||||
node.text = (new StreamConvert(value)).toString();
|
|
||||||
} else {
|
|
||||||
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;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user