3 var XMLAttribute, XMLElement, XMLNode, isFunction, isObject, ref,
4 extend =
function(child, parent) {
for (var key in parent) {
if (hasProp.call(parent, key)) child[key] = parent[key]; }
function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype =
new ctor(); child.__super__ = parent.prototype;
return child; },
5 hasProp = {}.hasOwnProperty;
7 ref = require(
'./Utility'), isObject = ref.isObject, isFunction = ref.isFunction;
9 XMLNode = require(
'./XMLNode');
11 XMLAttribute = require(
'./XMLAttribute');
13 module.exports = XMLElement = (
function(superClass) {
14 extend(XMLElement, superClass);
16 function XMLElement(parent, name, attributes) {
17 XMLElement.__super__.constructor.call(
this, parent);
19 throw new Error(
"Missing element name");
21 this.name = this.stringify.eleName(name);
23 if (attributes != null) {
24 this.attribute(attributes);
26 if (parent.isDocument) {
28 this.documentObject = parent;
29 parent.rootObject =
this;
33 XMLElement.prototype.clone =
function() {
34 var att, attName, clonedSelf, ref1;
35 clonedSelf = Object.create(
this);
36 if (clonedSelf.isRoot) {
37 clonedSelf.documentObject = null;
39 clonedSelf.attributes = {};
40 ref1 = this.attributes;
41 for (attName in ref1) {
42 if (!hasProp.call(ref1, attName))
continue;
44 clonedSelf.attributes[attName] = att.clone();
46 clonedSelf.children = [];
47 this.children.forEach(
function(child) {
49 clonedChild = child.clone();
50 clonedChild.parent = clonedSelf;
51 return clonedSelf.children.push(clonedChild);
56 XMLElement.prototype.attribute =
function(name, value) {
57 var attName, attValue;
59 name = name.valueOf();
62 for (attName in name) {
63 if (!hasProp.call(name, attName))
continue;
64 attValue = name[attName];
65 this.attribute(attName, attValue);
68 if (isFunction(value)) {
69 value = value.apply();
71 if (!this.options.skipNullAttributes || (value != null)) {
72 this.attributes[name] =
new XMLAttribute(
this, name, value);
78 XMLElement.prototype.removeAttribute =
function(name) {
81 throw new Error(
"Missing attribute name");
83 name = name.valueOf();
84 if (Array.isArray(name)) {
85 for (i = 0, len = name.length; i < len; i++) {
87 delete this.attributes[attName];
90 delete this.attributes[name];
95 XMLElement.prototype.toString =
function(options) {
96 return this.options.writer.set(options).element(
this);
99 XMLElement.prototype.att =
function(name, value) {
100 return this.attribute(name, value);
103 XMLElement.prototype.a =
function(name, value) {
104 return this.attribute(name, value);