add xmldom

This commit is contained in:
tkqubo
2016-01-05 10:22:44 +09:00
parent bdaf2f0eb1
commit 07f40fab19
2 changed files with 74 additions and 0 deletions
+36
View File
@@ -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)}
});
+38
View File
@@ -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;
}