当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript DOMParser.parseFromString方法代码示例

本文整理汇总了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)))
}
开发者ID:wux5,项目名称:raml-js-parser-2,代码行数:7,代码来源:xmlutil.ts

示例2: XPathTransformer

export function XPathTransformer(resp) {
    let doc = dom.parseFromString(resp.rawBody);
    return Q.resolve().then(() => {
        return (path) => {
            return xpath.select(path, doc);
        };
    });
}
开发者ID:njenan,项目名称:turbulence,代码行数:8,代码来源:XPathTransformer.ts

示例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 };
		})
开发者ID:taimur38,项目名称:toombot,代码行数:8,代码来源:wolfram.ts

示例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;
}
开发者ID:lshain,项目名称:vscode-php-debug,代码行数:6,代码来源:dbgp.ts

示例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;
         }
     }
 }
开发者ID:ullychan,项目名称:vscode-php-debug,代码行数:69,代码来源:dbgp.ts

示例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');
 }
开发者ID:chasidic,项目名称:scraper,代码行数:5,代码来源:Scraper.ts


注:本文中的xmldom.DOMParser.parseFromString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。