xml-parser v1.2.1

This commit is contained in:
mfrantz
2015-09-17 12:18:46 -07:00
parent 5f48028783
commit a8f2b8a2a1
2 changed files with 53 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
/// <reference path="../node/node.d.ts"/>
/// <reference path="xml-parser.d.ts"/>
import assert = require('assert');
import parse = require('xml-parser');
var doc: parse.Document = parse(
'<?xml version="1.0" encoding="utf-8"?>' +
'<mydoc><child a="1">foo</child><child/></mydoc>');
var declaration: parse.Declaration = doc.declaration;
assert.equal(declaration.attributes['version'], '1.0');
assert.equal(declaration.attributes['encoding'], 'utf-8');
var root: parse.Node = doc.root;
assert.equal(root.name, 'mydoc');
var children: parse.Node[] = root.children;
assert.equal(children.length, 2);
var child1: parse.Node = children[0];
assert.equal(child1.name, 'child');
assert.equal(child1.attributes['a'], '1');
assert.equal(child1.content, 'foo');
+33
View File
@@ -0,0 +1,33 @@
// Type definitions for xml-parser 1.2.1
// Project: https://github.com/segmentio/xml-parser
// Definitions by: Matt Frantz <https://github.com/mhfrantz/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module 'xml-parser' {
function parse(xml: string): parse.Document;
module parse {
export interface Document {
declaration: Declaration;
root: Node;
}
export interface Declaration {
attributes: Attributes;
}
export interface Node {
name: string;
attributes: Attributes;
children: Node[];
content?: string;
}
export interface Attributes {
[name: string]: string;
}
}
export = parse;
}