mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
add xmldom
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
/// <reference path="xmldom.d.ts" />
|
||||
|
||||
import * as xmldom from 'xmldom';
|
||||
|
||||
var doc = new xmldom.DOMParser().parseFromString(
|
||||
'<xml xmlns="a" xmlns:c="./lite">\n'+
|
||||
'\t<child>test</child>\n'+
|
||||
'\t<child></child>\n'+
|
||||
'\t<child/>\n'+
|
||||
'</xml>'
|
||||
,'text/xml');
|
||||
doc.documentElement.setAttribute('x','y');
|
||||
doc.documentElement.setAttributeNS('./lite','c:x','y2');
|
||||
var nsAttr = doc.documentElement.getAttributeNS('./lite','x');
|
||||
console.info(nsAttr);
|
||||
console.info(doc);
|
||||
|
||||
function callback(w: any) {
|
||||
|
||||
}
|
||||
|
||||
//errorHandler is supported
|
||||
new xmldom.DOMParser({
|
||||
/**
|
||||
* locator is always need for error position info
|
||||
*/
|
||||
locator:{},
|
||||
/**
|
||||
* you can override the errorHandler for xml parser
|
||||
* @link http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html
|
||||
*/
|
||||
errorHandler:{warning:function(w: any){console.warn(w)},error:callback,fatalError:callback}
|
||||
//only callback model
|
||||
//errorHandler:function(level,msg){console.log(level,msg)}
|
||||
});
|
||||
|
||||
Vendored
+38
@@ -0,0 +1,38 @@
|
||||
// Type definitions for xmldom 0.1.16
|
||||
// Project: https://github.com/jindw/xmldom.git
|
||||
// Definitions by: Qubo <https://github.com/tkqubo>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module "xmldom" {
|
||||
namespace xmldom {
|
||||
var DOMParser: DOMParserStatic;
|
||||
|
||||
interface DOMParserStatic {
|
||||
new(): DOMParser;
|
||||
new(options: Options): DOMParser;
|
||||
}
|
||||
|
||||
interface DOMParser {
|
||||
parseFromString(xmlsource: string, mimeType?: string): Document;
|
||||
serializeToString(node: Node): string;
|
||||
}
|
||||
|
||||
interface Options {
|
||||
locator?: any;
|
||||
errorHandler?: ErrorHandlerFunction|ErrorHandlerObject;
|
||||
}
|
||||
|
||||
interface ErrorHandlerFunction {
|
||||
(level: string, msg: any): any;
|
||||
}
|
||||
|
||||
interface ErrorHandlerObject {
|
||||
warning?: (msg: any) => any;
|
||||
error?: (msg: any) => any;
|
||||
fatalError?: (msg: any) => any;
|
||||
}
|
||||
}
|
||||
|
||||
export = xmldom;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user