From 07f40fab1952d9bd8bb1461b81832fe6d95baa74 Mon Sep 17 00:00:00 2001 From: tkqubo Date: Tue, 5 Jan 2016 10:22:44 +0900 Subject: [PATCH] add xmldom --- xmldom/xmldom-tests.ts | 36 ++++++++++++++++++++++++++++++++++++ xmldom/xmldom.d.ts | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 xmldom/xmldom-tests.ts create mode 100644 xmldom/xmldom.d.ts diff --git a/xmldom/xmldom-tests.ts b/xmldom/xmldom-tests.ts new file mode 100644 index 000000000..2cb3ae544 --- /dev/null +++ b/xmldom/xmldom-tests.ts @@ -0,0 +1,36 @@ +/// + +import * as xmldom from 'xmldom'; + +var doc = new xmldom.DOMParser().parseFromString( + '\n'+ + '\ttest\n'+ + '\t\n'+ + '\t\n'+ + '' + ,'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)} +}); + diff --git a/xmldom/xmldom.d.ts b/xmldom/xmldom.d.ts new file mode 100644 index 000000000..2a51cec1d --- /dev/null +++ b/xmldom/xmldom.d.ts @@ -0,0 +1,38 @@ +// Type definitions for xmldom 0.1.16 +// Project: https://github.com/jindw/xmldom.git +// Definitions by: Qubo +// 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; +} +