mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-07 09:49:07 +00:00
xml-parser v1.2.1
This commit is contained in:
@@ -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');
|
||||
Vendored
+33
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user