'use strict';
let DOMParser = require('xmldom').DOMParser;
export class XmlTreeService {
static getXmlTreeHtml(xml: string): string {
let xdoc: Document = new DOMParser().parseFromString(xml, 'text/xml');
let html: string =
`
XML Tree View
`;
html += ``;
html += XmlTreeService._processXmlNode(xdoc.lastChild);
html += ``;
html +=
`
`;
return html;
}
private static _processXmlNode(node: Node): string {
let html: string = '';
if (node.childNodes) {
html += `
`;
}
if (node.attributes) {
for (let i = 0; i < node.attributes.length; i++) {
html += `
`;
}
if (node.childNodes) {
for (let i = 0; i < node.childNodes.length; i++) {
html += XmlTreeService._processXmlNode(node.childNodes.item(i));
}
html += `