本文整理汇总了TypeScript中x2js.xml2js函数的典型用法代码示例。如果您正苦于以下问题:TypeScript xml2js函数的具体用法?TypeScript xml2js怎么用?TypeScript xml2js使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xml2js函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: return
let extractValid = (res: Response | any) => {
let text = res && res instanceof Response && res.text();
let match = text && text.length > 0 && text.match(/<valid>.*<\/valid>/);
if (match) {
let resultJSON = this.x2js.xml2js(match[0]);
return (
resultJSON && resultJSON['valid'] && resultJSON['valid'] === 'yes'
);
} else return false;
};
示例2: isXML
public isXML(xml: string): boolean {
try {
const parser = new X2JS();
const xmlDoc = parser.xml2js(xml); // is valid XML
return xmlDoc != null;
} catch (err) {
// was not XML
return false;
}
}
示例3: tryXMLParse
public tryXMLParse(xml: string): any {
try {
const parser = new X2JS();
const xmlDoc = parser.xml2js(xml); // is valid XML
return xmlDoc;
} catch (err) {
// Do nothing
}
return null;
}
示例4: parseResponse
private parseResponse(res: Response) {
console.log("response", res);
let contentType = res.headers.get("Content-Type");
if (contentType.indexOf("application/json") > -1) {
return res.json();
} else if (
contentType.indexOf("application/xml") > -1 ||
contentType.indexOf("text/xml") > -1) {
var x2js = new X2JS();
var text = res.text();
var jsonObj: any = x2js.xml2js<any>(text);
jsonObj = jsonObj[Object.keys(jsonObj)[0]];
return jsonObj;
}
throw new Error("Unsupported response content type - " + contentType);
}
示例5: parseXmlToJson
private parseXmlToJson(xml):any{
//var xml = response.text();
var x2js = new X2JS();
var json = x2js.xml2js(xml);
return json;
}