本文整理汇总了TypeScript中xml2js.parseString函数的典型用法代码示例。如果您正苦于以下问题:TypeScript parseString函数的具体用法?TypeScript parseString怎么用?TypeScript parseString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parseString函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Promise
return new Promise((resolve) => {
let SqliteSyncObject = {
SyncId: data[0].SyncId,
TableName: data[0].TableName,
Records: [],
QueryInsert: data[0].QueryInsert,
QueryUpdate: data[0].QueryUpdate,
QueryDelete: data[0].QueryDelete,
TriggerInsert: data[0].TriggerInsert,
TriggerUpdate: data[0].TriggerUpdate,
TriggerDelete: data[0].TriggerDelete,
TriggerInsertDrop: data[0].TriggerInsertDrop,
TriggerUpdateDrop: data[0].TriggerUpdateDrop,
TriggerDeleteDrop: data[0].TriggerDeleteDrop,
}
xml2js.parseString(data[0].Records, function (err, result) {
if(result && result.records){
for(let i = 0; i < result.records.r.length; i++){
let record = {
Action: result.records.r[i].$.a,
Columns: []
};
for(let ii = 0; ii < result.records.r[i].c.length; ii++){
record.Columns.push(result.records.r[i].c[ii]);
}
SqliteSyncObject.Records.push(record);
}
resolve(SqliteSyncObject);
}
else{
resolve(SqliteSyncObject);
}
});
})
示例2: handleError
fs.readFile(inputFilePath, (err, data) => {
handleError(err);
xml2js.parseString(data.toString(), (err, result) => {
handleError(err);
writeFile(outputFilePath, xmlObjectToString(result));
});
});
示例3: containsParamFile
export async function containsParamFile(webAppPackage: string ) {
var msDeployPath = await getMSDeployFullPath();
var msDeployCheckParamFileCmdArgs = "-verb:getParameters -source:package=\"" + webAppPackage + "\"";
var msDeployParamFile = tl.getVariable('System.DefaultWorkingDirectory') + '\\' + 'msDeployParam.bat';
var parameterFile = tl.getVariable('System.DefaultWorkingDirectory') + '\\' + 'parameter.xml';
var silentCommand = '@echo off \n';
var msDeployCommand = '"' + msDeployPath + '" ' + msDeployCheckParamFileCmdArgs + " > \"" + parameterFile + "\"";
var batchCommand = silentCommand + msDeployCommand;
tl.writeFile(msDeployParamFile, batchCommand);
tl._writeLine(tl.loc("Runningcommand", msDeployCommand));
var taskResult = tl.execSync("cmd", ['/C', msDeployParamFile], { failOnStdErr: true, silent: true });
var paramContentXML = fs.readFileSync(parameterFile);
var isParamFilePresent = false;
await parseString(paramContentXML, (error, result) => {
if(error) {
throw new Error(error);
}
if(result['output']['parameters'][0] ) {
isParamFilePresent = true;
}
});
tl.debug(tl.loc("Isparameterfilepresentinwebpackage0", isParamFilePresent));
return isParamFilePresent;
}
示例4: convertXml2js
export function convertXml2js(content: string): JsonObject|null {
let retResult: JsonObject = null;
xml2js.parseString(content, (err, result) => {
retResult = result;
});
return retResult;
}
示例5: request
request(this.options, function (error:any, response:any,body:any) {
xml2js.parseString(body, function (err:any, result:any) {
var backData = that._parse(result);
if(callback){
callback(backData);
}
});
});
示例6: httpGet
return httpGet('http://live.bilibili.com/api/playurl', {cid: videoId}).then((xml:string)=> {
let downloadUrl = null;
parseString(xml, function (err, result) {
if (!err && Object.keys(result)) {
downloadUrl = result.video.durl[0].url[0]
}
});
return downloadUrl;
}
示例7: parseString
const translated = await new Promise<string>((resolve, reject) => {
parseString(body, (err, result) => {
if (err) { reject(err) }
console.log(body + '\nâ parsing XML to JS object');
console.log(result);
console.log('\n');
resolve(result.string._);
});
});
示例8: Promise
return new Promise((resolve, reject) => {
xml2js.parseString(xml, options || defaultParseOptions, (err, data) => {
if (err) {
callback && callback(err);
return reject(err);
}
callback && callback(null, data);
resolve(data);
});
});
示例9: parseXML
function parseXML(content: string) {
let xml: Object;
xml2js.parseString(content, { async: false },(err, result) => {
if (err) {
throw err;
}
xml = result;
});
return xml;
}
示例10: resolve
/**
*
*/
public resolve(response: CasparCGSocketResponse): Object {
let parseNumbers = function (str: any) {
if (!isNaN(str)) {
str = str % 1 === 0 ? parseInt(str, 10) : parseFloat(str)
}
return str
}
let parseBooleans = function (str: any) {
if (str === true || str.toString().toLowerCase() === 'true') {
return true
} else if (str === false || str.toString().toLowerCase() === 'false') {
return false
}
return str
}
let parseLowerCase = function (str: any) {
return str.toString().toLowerCase()
}
let returnFalse: Error | undefined
let returnData: Object | undefined
xmlParser(
response.items[0].replace('\n', ''),
{ explicitRoot: false, async: false, trim: true, explicitArray: false, mergeAttrs: true, attrValueProcessors: [parseNumbers], valueProcessors: [parseNumbers, parseBooleans], tagNameProcessors: [parseLowerCase], attrNameProcessors: [parseLowerCase] },
(error, result) => {
returnFalse = error
returnData = result
})
return returnFalse ? {} : returnData || {}
}