import { Injectable } from '@nestjs/common' ; import * as xml2js from 'xml2js' ; /**
 * XML 工具
 */ @ Injectable ( ) export class XmlUtil { param obj convertObjToXml ( obj ) { return new xml2js . Builder ( { rootName : 'xml' , cdata : true } ) . buildObject ( obj ) ; } param xml async parseObjFromXml < T > ( xml ) { return new Promise < T > ( ( resolve , reject ) => { xml2js . parseString ( xml , { explicitRoot : false , explicitArray : false } , ( error , result ) => { if ( error ) { reject ( error ) ; } resolve ( result ) ; } ) ; } ) ; } }