'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 += `
    1. `; } if (node.attributes) { for (let i = 0; i < node.attributes.length; i++) { html += `
    2. ${node.attributes.item(i).localName} = '${node.attributes.item(i).value}'
    3. `; } } if (!node.childNodes && node.textContent) { html += `
    4. ${node.textContent}
    5. `; } if (node.childNodes) { for (let i = 0; i < node.childNodes.length; i++) { html += XmlTreeService._processXmlNode(node.childNodes.item(i)); } html += `
  • `; } return html; } }