Permalink
Browse files

definitions and testes to Libxmljs #257

  • Loading branch information...
1 parent c90a036 commit 62b8e1d633bfc32754efa5941ad35c23114f0364 @Diullei Diullei committed Feb 18, 2013
Showing with 161 additions and 0 deletions.
  1. +1 −0 README.md
  2. +49 −0 libxmljs/libxmljs-tests.ts
  3. +111 −0 libxmljs/libxmljs.d.ts
View
@@ -99,6 +99,7 @@ List of Definitions
* [ko.editables](http://romanych.github.com/ko.editables/) (by [Oisin Grehan](https://github.com/oising))
* [KoLite](https://github.com/CodeSeven/kolite) (by [Boris Yankov](https://github.com/borisyankov))
* [Leaflet](https://github.com/Leaflet/Leaflet) (by [Vladimir](https://github.com/rgripper))
+* [Libxmljs](https://github.com/polotek/libxmljs) (by [François de Campredon](https://github.com/fdecampredon))
* [linq.js](http://linqjs.codeplex.com/) (by [Marcin Najder](https://github.com/marcinnajder))
* [Marked](https://github.com/chjj/marked) (by [William Orr](https://github.com/worr))
* [Modernizr](http://modernizr.com/) (by [Boris Yankov](https://github.com/borisyankov))
View
@@ -0,0 +1,49 @@
+/// <reference path="..\node\node.d.ts" />
+/// <reference path="libxmljs.d.ts" />
+
+var libxmljs = require("libxmljs");
+var xml = '<?xml version="1.0" encoding="UTF-8"?>' +
+ '<root>' +
+ '<child foo="bar">' +
+ '<grandchild baz="fizbuzz">grandchild content</grandchild>' +
+ '</child>' +
+ '<sibling>with content!</sibling>' +
+ '</root>';
+
+var xmlDoc = libxmljs.parseXmlString(xml);
+
+// xpath queries
+var gchild = xmlDoc.get('//grandchild');
+
+console.log(gchild.text()); // prints "grandchild content"
+
+var children = xmlDoc.root().childNodes();
+var child = children[0];
+
+console.log(child.attr('foo').value()); // prints "bar"
+
+var parser = new libxmljs.SaxParser();
+
+parser.on('startDocument', null);
+parser.on('startElement', null);
+
+var parser2 = new libxmljs.SaxPushParser();
+
+// connect any callbacks here
+parser2
+ .on('startDocument', null)
+ .on('startElement', null)
+
+var xmlChunk: any;
+
+while(xmlChunk) {
+ parser2.push(xmlChunk);
+}
+
+var doc = new libxmljs.Document();
+ doc.node('root')
+ .node('child').attr({foo: 'bar'})
+ .node('grandchild', 'grandchild content').attr({baz: 'fizbuzz'})
+ .parent()
+ .parent()
+ .node('sibling', 'with content!');
View
@@ -0,0 +1,111 @@
+// Type definitions for Libxmljs
+// Project: https://github.com/polotek/libxmljs
+// Definitions by: François de Campredon <https://github.com/fdecampredon>
+// Definitions: https://github.com/borisyankov/DefinitelyTyped
+
+declare module "libxmljs" {
+ export function parseXmlString(source:string):XMLDocument;
+ export function parseHtmlString(source:string):HTMLDocument;
+
+
+ export class XMLDocument {
+ constructor(version:number, encoding:string);
+ child(idx:number):Element;
+ childNodes():Element[];
+ errors():SyntaxError[];
+ encoding():string;
+ encoding(enc:string):void;
+ find(xpath:string):Element[];
+ get(xpath:string):Element;
+ node(name:string, content:string):Element;
+ root():Element;
+ toString():string;
+ version():Number;
+ }
+
+ export class HTMLDocument extends XMLDocument {
+
+ }
+
+
+ export class Element {
+ constructor(doc:XMLDocument, name:string, content?:string);
+ name():string;
+ name(newName:string):void;
+ text():string;
+ attr(name:string):string;
+ attr(attr:Attribute);
+ attr(attrObject:{[key:string]:string;}):void;
+ attrs():Attribute[];
+ parent():Element;
+ doc():XMLDocument;
+ child(idx:number):Element;
+ childNodes():Element[];
+ addChild(child:Element);
+ nextSibling():Element;
+ nextElement():Element;
+ addNextSibling(siblingNode:Element):Element;
+ prevSibling():Element;
+ prevElement():Element;
+ addPrevSibling(siblingNode:Element);
+ find(xpath:string):Element[];
+ find(xpath:string, ns_uri:string):Element[];
+ get(xpath:string, ns_uri:string):Element;
+ find(xpath:string, namespaces:{[key:string]:string;}):Element[];
+ get(xpath, ns_uri:{[key:string]:string;}):Element;
+ defineNamespace(href:string):Namespace;
+ defineNamespace(prefix:string, href:string):Namespace;
+ namespace():Namespace;
+ namespace(ns:Namespace):void;
+ namespace(href:string):void;
+ namespace(prefix:string, href:string):void;
+ remove():void;
+ path():string;
+ type():string;
+ }
+
+
+ export class Attribute {
+ constructor(node:Element, name:string, value:string);
+ constructor(node:Element, name:string, value:string, ns:Namespace);
+ name():string;
+ namespace():Namespace;
+ namespace(ns:Namespace):Namespace;
+ nextSibling():Attribute;
+ node():Element;
+ prevSibling():Attribute;
+ remove():void;
+ value():string;
+ }
+
+ export class Namespace {
+ constructor(node:Element, prefix:string, href:string);
+ href():string;
+ prefix():string;
+ }
+
+ export class SaxParser {
+ parseString(source:string):bool;
+ addListener(event: string, listener: Function);
+ on(event: string, listener: Function): any;
+ once(event: string, listener: Function): void;
+ removeListener(event: string, listener: Function): void;
+ removeAllListener(event: string): void;
+ setMaxListeners(n: number): void;
+ listeners(event: string): { Function; }[];
+ emit(event: string, arg1?: any, arg2?: any): void;
+ }
+
+
+ export class SaxPushParser {
+ push(source:string):bool;
+ addListener(event: string, listener: Function);
+ on(event: string, listener: Function): any;
+ once(event: string, listener: Function): void;
+ removeListener(event: string, listener: Function): void;
+ removeAllListener(event: string): void;
+ setMaxListeners(n: number): void;
+ listeners(event: string): { Function; }[];
+ emit(event: string, arg1?: any, arg2?: any): void;
+ }
+}

0 comments on commit 62b8e1d

Please sign in to comment.