Skip to content

Commit a8f2b8a

Browse files
author
mfrantz
committed
xml-parser v1.2.1
1 parent 5f48028 commit a8f2b8a

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

xml-parser/xml-parser-tests.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// <reference path="../node/node.d.ts"/>
2+
/// <reference path="xml-parser.d.ts"/>
3+
4+
import assert = require('assert');
5+
import parse = require('xml-parser');
6+
7+
var doc: parse.Document = parse(
8+
'<?xml version="1.0" encoding="utf-8"?>' +
9+
'<mydoc><child a="1">foo</child><child/></mydoc>');
10+
var declaration: parse.Declaration = doc.declaration;
11+
assert.equal(declaration.attributes['version'], '1.0');
12+
assert.equal(declaration.attributes['encoding'], 'utf-8');
13+
var root: parse.Node = doc.root;
14+
assert.equal(root.name, 'mydoc');
15+
var children: parse.Node[] = root.children;
16+
assert.equal(children.length, 2);
17+
var child1: parse.Node = children[0];
18+
assert.equal(child1.name, 'child');
19+
assert.equal(child1.attributes['a'], '1');
20+
assert.equal(child1.content, 'foo');

xml-parser/xml-parser.d.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Type definitions for xml-parser 1.2.1
2+
// Project: https://github.com/segmentio/xml-parser
3+
// Definitions by: Matt Frantz <https://github.com/mhfrantz/>
4+
// Definitions: https://github.com/borisyankov/DefinitelyTyped
5+
6+
declare module 'xml-parser' {
7+
8+
function parse(xml: string): parse.Document;
9+
10+
module parse {
11+
export interface Document {
12+
declaration: Declaration;
13+
root: Node;
14+
}
15+
16+
export interface Declaration {
17+
attributes: Attributes;
18+
}
19+
20+
export interface Node {
21+
name: string;
22+
attributes: Attributes;
23+
children: Node[];
24+
content?: string;
25+
}
26+
27+
export interface Attributes {
28+
[name: string]: string;
29+
}
30+
}
31+
32+
export = parse;
33+
}

0 commit comments

Comments
 (0)