本文整理汇总了TypeScript中xml2js.Builder类的典型用法代码示例。如果您正苦于以下问题:TypeScript Builder类的具体用法?TypeScript Builder怎么用?TypeScript Builder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Builder类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
parser.parseString(xmlContents, function (err, result) {
if (err) {
tl.warning(tl.loc('ErrorWhileReadingRunSettings', err));
tl.debug("Error occured while overriding test run parameters. Continuing...");
defer.resolve(settingsFile);
return defer.promise;
}
if (result.RunSettings && result.RunSettings.TestRunParameters && result.RunSettings.TestRunParameters[0] &&
result.RunSettings.TestRunParameters[0].Parameter) {
var parametersArray = result.RunSettings.TestRunParameters[0].Parameter;
parametersArray.forEach(function (parameter) {
var key = parameter.$.name;
if (overrideParameters[key]) {
parameter.$.value = overrideParameters[key];
}
});
tl.debug("Overriding test run parameters.");
var builder = new xml2js.Builder();
var overridedRunSettings = builder.buildObject(result);
saveToFile(overridedRunSettings, runSettingsExt)
.then(function (fileName) {
defer.resolve(fileName);
})
.fail(function (err) {
tl.debug("Error occured while overriding test run parameters. Continuing...");
tl.warning(err);
defer.resolve(settingsFile);
});
}
else {
tl.debug("No test run parameters found to override.");
defer.resolve(settingsFile);
}
});
示例2: writeJsonAsXmlFile
export function writeJsonAsXmlFile(filePath: string, jsonContent: any): Q.Promise<void> {
let builder = new xml2js.Builder();
tl.debug("Writing JSON as XML file: " + filePath);
let xml = builder.buildObject(jsonContent);
xml = str(xml).replaceAll("
", "").s;
return writeFile(filePath, xml);
}
示例3: writeXmlFile
function writeXmlFile(result: any, settingsFile: string, fileExt: string, exitErrorMessage: string): Q.Promise<string> {
var defer = Q.defer<string>();
var builder = new xml2js.Builder();
var runSettingsForTestImpact = builder.buildObject(result);
saveToFile(runSettingsForTestImpact, fileExt)
.then(function (fileName) {
cleanUp(settingsFile);
defer.resolve(fileName);
return defer.promise;
})
.fail(function (err) {
tl.debug(exitErrorMessage);
tl.warning(err);
defer.resolve(settingsFile);
});
return defer.promise;
}
示例4: function
parser.parseString(xmlContents, function(err, result) {
if (err) {
tl.warning("Error occured while reading run settings file. Error : " + err);
tl.debug("Error occured while setting run in parallel. Continuing...");
defer.resolve(settingsFile);
return defer.promise;
}
if (result.RunSettings === undefined) {
tl.warning("Failed to set run in parallel. Invalid run settings file.");
defer.resolve(settingsFile);
return defer.promise;
}
if (!result.RunSettings) {
result.RunSettings = { RunConfiguration: { MaxCpuCount: 0 } };
}
else if (!result.RunSettings.RunConfiguration || !result.RunSettings.RunConfiguration[0]) {
result.RunSettings.RunConfiguration = { MaxCpuCount: 0 };
}
else {
var runConfigArray = result.RunSettings.RunConfiguration[0];
runConfigArray.MaxCpuCount = 0;
}
var builder = new xml2js.Builder();
var runSettingsForParallel = builder.buildObject(result);
saveToFile(runSettingsForParallel)
.then(function(fileName) {
cleanUp(settingsFile);
defer.resolve(fileName);
return defer.promise;
})
.fail(function(err) {
tl.debug("Error occured while setting run in parallel. Continuing...");
tl.warning(err);
defer.resolve(settingsFile);
});
});
示例5: function
_.defer( () => {
try {
// 1 Copy the public properties and _name to a destination object for serialization.
var destObj = {};
_.each( _.keys( viewData) , function(key: string) {
//
if ( key === '_name' ) {
destObj['name'] = viewData[key];
resourceName = viewData[key];
}
else if ( key.indexOf('_') === 0 )
return;
else {
//console.log('['+key+'] is '+viewData[key] );
destObj[key] = viewData[key];
}
});
// 2 - build the embodiment serializing the data as a Buffer
// log.info('Serializing "%s"',JSON.stringify(destObj));
var dataString = '';
switch(mimeType) {
case 'application/xml':
case 'text/xml':
var builder = new xml2js.Builder({ rootName: resourceName, renderOpts : { 'pretty': false }, headless: true });
dataString = builder.buildObject( destObj );
break;
default:
dataString = JSON.stringify( destObj );
break;
}
// log.info('Delivering: "%s"',dataString);
var e = new relaxjs.Embodiment( mimeType, 200, new Buffer( dataString,'utf-8' ) );
later.resolve( e );
}
catch( err ) {
log.error(err);
later.reject( new relaxjs.RxError('JSON Serialization error: '+err ) )
}
});
示例6: build
build(rootObj): string {
return this.builder.buildObject(rootObj);
}
示例7: saveXML
export function saveXML(xmlobj:{}, path:string):Promise<string> {
var contents = builder.buildObject(xmlobj);
return writeFile(path, contents).thenReturn(path);
}