本文整理匯總了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;
}