本文整理汇总了TypeScript中xmldom.DOMParser.parseFromString方法的典型用法代码示例。如果您正苦于以下问题:TypeScript DOMParser.parseFromString方法的具体用法?TypeScript DOMParser.parseFromString怎么用?TypeScript DOMParser.parseFromString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xmldom.DOMParser
的用法示例。
在下文中一共展示了DOMParser.parseFromString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: parseXML
export function parseXML(value:string){
var v=new DomParser.DOMParser(parserOptions);
if (!value || value.trim().indexOf("<<") == 0) return null;
var parsed=v.parseFromString(value);
return cleanupJson(cleanupText(xmlToJson(parsed)))
}
示例2: XPathTransformer
export function XPathTransformer(resp) {
let doc = dom.parseFromString(resp.rawBody);
return Q.resolve().then(() => {
return (path) => {
return xpath.select(path, doc);
};
});
}
示例3:
.then(res => {
const xml = parser.parseFromString(res.data);
const pods = xpath.select('//pod[contains(@title, "Result")]/subpod/plaintext', xml)
if(pods.length == 0)
return false;
return { text: pods[0].firstChild.data, send: true };
})
示例4: parseResponse
function parseResponse(response: Buffer): XMLDocument {
const xml = iconv.decode(response, ENCODING);
const parser = new DOMParser();
const document = parser.parseFromString(xml, 'application/xml');
return document;
}
示例5: _handleDataChunk
private _handleDataChunk(data: Buffer) {
// Anatomy of packets: [data length] [NULL] [xml] [NULL]
// are we waiting for the data length or for the response?
if (this._parsingState === ParsingState.DataLength) {
// does data contain a NULL byte?
const nullByteIndex = data.indexOf(0);
if (nullByteIndex !== -1) {
// YES -> we received the data length and are ready to receive the response
this._dataLength = parseInt(iconv.decode(data.slice(0, nullByteIndex), ENCODING));
// reset buffered chunks
this._chunks = [];
this._chunksDataLength = 0;
// switch to response parsing state
this._parsingState = ParsingState.Response;
// if data contains more info (except the NULL byte)
if (data.length > nullByteIndex + 1) {
// handle the rest of the packet as part of the response
const rest = data.slice(nullByteIndex + 1);
this._handleDataChunk(rest);
}
} else {
// NO -> this is only part of the data length. We wait for the next data event
this._chunks.push(data);
this._chunksDataLength += data.length;
}
} else if (this._parsingState === ParsingState.Response) {
// does the new data together with the buffered data add up to the data length?
if (this._chunksDataLength + data.length >= this._dataLength) {
// YES -> we received the whole response
// append the last piece of the response
const lastResponsePiece = data.slice(0, this._dataLength - this._chunksDataLength);
this._chunks.push(lastResponsePiece);
this._chunksDataLength += data.length;
const response = Buffer.concat(this._chunks, this._chunksDataLength);
// call response handler
const xml = iconv.decode(response, ENCODING);
const parser = new DOMParser({
errorHandler: {
warning: warning => {
// ignore
},
error: error => {
this.emit('error', error);
},
fatalError: error => {
this.emit('error', error);
}
}
});
const document = parser.parseFromString(xml, 'application/xml');
this.handleResponse(document);
// reset buffer
this._chunks = [];
this._chunksDataLength = 0;
// switch to data length parsing state
this._parsingState = ParsingState.DataLength;
// if data contains more info (except the NULL byte)
if (data.length > lastResponsePiece.length + 1) {
// handle the rest of the packet (after the NULL byte) as data length
const rest = data.slice(lastResponsePiece.length + 1);
this._handleDataChunk(rest);
}
} else {
// NO -> this is not the whole response yet. We buffer it and wait for the next data event.
this._chunks.push(data);
this._chunksDataLength += data.length;
}
}
}
示例6: loadDOM
async loadDOM(uri: string, options: Options = {}) {
const body = await this.load(uri);
const parser = new DOMParser(options);
return parser.parseFromString(body, 'text/xml');
}