clear out clearVariables! In comes toXml
This commit is contained in:
@ -5,9 +5,5 @@ export abstract class BaseXmlComponent {
|
||||
this.rootKey = rootKey;
|
||||
}
|
||||
|
||||
public abstract replaceKey(): void;
|
||||
|
||||
public clearVariables(): void {
|
||||
// Do Nothing
|
||||
}
|
||||
public abstract toXml(): object;
|
||||
}
|
||||
|
@ -16,15 +16,18 @@ export abstract class XmlAttributeComponent extends BaseXmlComponent {
|
||||
}
|
||||
}
|
||||
|
||||
public replaceKey(): void {
|
||||
if (this.root !== undefined) {
|
||||
public toXml(): object {
|
||||
const attrs = {};
|
||||
if (this.root != undefined) {
|
||||
_.forOwn(this.root, (value, key) => {
|
||||
const newKey = this.xmlKeys[key];
|
||||
this.root[newKey] = value;
|
||||
delete this.root[key];
|
||||
if (value != undefined) {
|
||||
const newKey = this.xmlKeys[key];
|
||||
attrs[newKey] = value;
|
||||
}
|
||||
});
|
||||
this[this.rootKey] = this.root;
|
||||
delete this.root;
|
||||
}
|
||||
const ret = {};
|
||||
ret[this.rootKey] = attrs;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import * as _ from "lodash";
|
||||
import { BaseXmlComponent } from "./base";
|
||||
export { BaseXmlComponent };
|
||||
|
||||
export abstract class XmlComponent extends BaseXmlComponent {
|
||||
protected root: Array<BaseXmlComponent | string>;
|
||||
@ -9,17 +10,15 @@ export abstract class XmlComponent extends BaseXmlComponent {
|
||||
this.root = new Array<BaseXmlComponent>();
|
||||
}
|
||||
|
||||
public replaceKey(): void {
|
||||
// console.log(this.rootKey);
|
||||
// console.log(this.root);
|
||||
if (this.root !== undefined) {
|
||||
this.root.forEach((root) => {
|
||||
if (root && root instanceof BaseXmlComponent) {
|
||||
root.replaceKey();
|
||||
}
|
||||
});
|
||||
this[this.rootKey] = this.root;
|
||||
delete this.root;
|
||||
public toXml(): object {
|
||||
const ret = this.root.map((comp) => {
|
||||
if (comp instanceof BaseXmlComponent) {
|
||||
return comp.toXml();
|
||||
}
|
||||
return comp
|
||||
}).filter((comp) => comp); // Exclude null, undefined, and empty strings
|
||||
return {
|
||||
[this.rootKey]: ret,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user