/**
 * IXmlAttribute is just the standard Attr
 */ export type IXmlAttribute = Attr ; /**
 * Just a wrapper for an XML Element object.
 * It facilitates handling of XML elements by OSMD
 */ export class IXmlElement { public name : string ; public value : string ; public hasAttributes : boolean = false ; public firstAttribute : IXmlAttribute ; public hasElements : boolean ; private attrs : IXmlAttribute [ ] ; private elem : Element ; param elem constructor ( elem ) { if ( ! elem ) { throw new Error ( "IXmlElement: expected Element, got undefined" ) ; } this . elem = elem ; this . name = elem . nodeName . toLowerCase ( ) ; if ( elem . hasAttributes ( ) ) { this . hasAttributes = true ; this . firstAttribute = elem . attributes [ 0 ] ; } this . hasElements = elem . hasChildNodes ( ) ; if ( elem . childNodes . length === 1 && elem . childNodes [ 0 ] . nodeType === Node . TEXT_NODE ) { this . value = elem . childNodes [ 0 ] . nodeValue ; } else { this . value = "" ; } } param attributeName returns { Attr } public attribute ( attributeName ) { return this . elem . attributes . getNamedItem ( attributeName ) ; } returns { IXmlAttribute [ ] } public attributes ( ) { if ( ! this . attrs ) { const attributes = this . elem . attributes ; const attrs = [ ] ; for ( let i = 0 ; i < attributes . length ; i += 1 ) { attrs . push ( attributes [ i ] ) ; } this . attrs = attrs ; } return this . attrs ; } param elementName returns { IXmlElement } public element ( elementName ) { const nodes = this . elem . childNodes ; for ( let i = 0 , length = nodes . length ; i < length ; i += 1 ) { const node = nodes [ i ] ; if ( node . nodeType === Node . ELEMENT_NODE && node . nodeName . toLowerCase ( ) === elementName ) { return new IXmlElement ( node as Element ) ; } } } param nodeName returns { IXmlElement [ ] } public elements ( nodeName ? ) { const nodes = this . elem . childNodes ; const ret = [ ] ; const nameUnset = ! nodeName ; if ( ! nameUnset ) { nodeName = nodeName . toLowerCase ( ) ; } for ( let i = 0 ; i < nodes . length ; i += 1 ) { const node = nodes [ i ] ; if ( node . nodeType === Node . ELEMENT_NODE && ( nameUnset || node . nodeName . toLowerCase ( ) === nodeName ) ) { ret . push ( new IXmlElement ( node as Element ) ) ; } } return ret ; } }