Interface Attribute renamed to QualifiedAttribute for consistency

Added type tests
This commit is contained in:
Marco
2016-02-25 21:24:28 +01:00
parent 2671c57724
commit df7f9a5265
2 changed files with 87 additions and 42 deletions
+85 -40
View File
@@ -1,44 +1,89 @@
/// <reference path="../node/node.d.ts" />
/// <reference path="./sax.d.ts" />
import sax = require("sax");
var opts: sax.SAXOptions = {
lowercase: true,
normalize: true,
xmlns: true,
position: true
};
var parser = sax.parser(/*strict=*/true, opts);
parser.onerror = function(e: Error) {
};
parser.ontext = function(text: string) {
};
parser.onopentag = function(tag: sax.QualifiedTag) {
for (let attr in tag.attributes)
console.log(typeof(attr));
};
parser.onattribute = function(attr: { name: string; value: string; }) {
};
parser.onend = function() {
};
parser.write("<xml>Hello, <who name=\"world\">world</who>!</xml>").close();
var saxStream = sax.createStream(/*strict=*/true, opts);
saxStream.on("error", function(e: Error) {
this._parser.error = null;
this._parser.resume();
});
import fs = require("fs");
fs.createReadStream("file.xml")
.pipe(saxStream)
.pipe(fs.createWriteStream("file-copy.xml"));
(function xmlnsTests() {
let opts: sax.SAXOptions = {
lowercase: true,
normalize: true,
xmlns: true,
position: true
};
let parser = sax.parser(/*strict=*/true, opts);
parser.onerror = function(e: Error) {
};
parser.ontext = function(text: string) {
};
parser.onopentag = function(tag: sax.QualifiedTag) {
let prefix: string = tag.prefix;
let local: string = tag.local;
let uri: string = tag.uri;
let name: string = tag.name;
let isSelfClosing: boolean = tag.isSelfClosing;
let attr: sax.QualifiedAttribute = tag.attributes["name"];
if (attr) {
let attrPrefix: string = attr.prefix;
let attrLocal: string = attr.local;
let attrUri: string = attr.uri;
let attrName: string = attr.name;
let attrValue: string = attr.value;
}
};
parser.onattribute = function(attr: { name: string; value: string; }) {
};
parser.onend = function() {
};
parser.write("<xml>Hello, <who name=\"world\">world</who>!</xml>").close();
let saxStream = sax.createStream(/*strict=*/true, opts);
saxStream.on("error", function(e: Error) {
this._parser.error = null;
this._parser.resume();
});
fs.createReadStream("file.xml")
.pipe(saxStream)
.pipe(fs.createWriteStream("file-copy.xml"));
})();
(function noXmlnsTests() {
let opts: sax.SAXOptions = {
lowercase: true,
normalize: true,
xmlns: false,
position: true
};
let parser = sax.parser(/*strict=*/true, opts);
parser.onerror = function(e: Error) {
};
parser.ontext = function(text: string) {
};
parser.onopentag = function(tag: sax.Tag) {
let name: string = tag.name;
let isSelfClosing: boolean = tag.isSelfClosing;
let attrValue: string = tag.attributes["name"];
};
parser.onattribute = function(attr: { name: string; value: string; }) {
};
parser.onend = function() {
};
parser.write("<xml>Hello, <who name=\"world\">world</who>!</xml>").close();
})();
+2 -2
View File
@@ -23,7 +23,7 @@ declare module "sax" {
uri: string;
}
export interface Attribute extends QualifiedName {
export interface QualifiedAttribute extends QualifiedName {
value: string;
}
@@ -35,7 +35,7 @@ declare module "sax" {
// Interface used when the xmlns option is set
export interface QualifiedTag extends QualifiedName, BaseTag {
ns: { [key: string]: string };
attributes: { [key: string]: Attribute };
attributes: { [key: string]: QualifiedAttribute };
}
export interface Tag extends BaseTag {