import { FileUtil } from '../common/file-util' ; /**
 * Created by martin on 10.03.2017.
 * Helper class to read XMl with a correct encoding.
 */ export class XmlReader { static DEFAULT_ENCODING = 'UTF-8' ; param path param encoding return public static readXmlFileContent ( path , encoding ? ) { if ( ! encoding ) { encoding = XmlReader . DEFAULT_ENCODING ; } let content = FileUtil . read ( path , encoding ) ; const foundEncoding = XmlReader . encodingFromXml ( content ) ; if ( foundEncoding !== encoding ) { content = FileUtil . read ( path , foundEncoding ) ; } return { content : content , encoding : foundEncoding } ; } param xmlString return private static encodingFromXml ( xmlString ) { const index = xmlString . indexOf ( 'encoding="' ) ; if ( index < 0 ) { return this . DEFAULT_ENCODING ; } const endIndex = xmlString . indexOf ( '"' , index + 10 ) ; return xmlString . substring ( index + 10 , endIndex ) ; } }