mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-18 20:37:14 +08:00
Added the isSelfClosing property to the Tag interface
Split of the original Tag interface into Tag and QualifiedTag to represent the two modes of using sax-js (using namespace prefixes or ignoring them). The QualifiedTag interface now describes correctly the attributes property.
This commit is contained in:
@@ -17,7 +17,9 @@ parser.onerror = function(e: Error) {
|
||||
parser.ontext = function(text: string) {
|
||||
};
|
||||
|
||||
parser.onopentag = function(tag: sax.Tag) {
|
||||
parser.onopentag = function(tag: sax.QualifiedTag) {
|
||||
for (let attr in tag.attributes)
|
||||
console.log(typeof(attr));
|
||||
};
|
||||
|
||||
parser.onattribute = function(attr: { name: string; value: string; }) {
|
||||
@@ -40,4 +42,3 @@ import fs = require("fs");
|
||||
fs.createReadStream("file.xml")
|
||||
.pipe(saxStream)
|
||||
.pipe(fs.createWriteStream("file-copy.xml"));
|
||||
|
||||
|
||||
43
sax/sax.d.ts
vendored
43
sax/sax.d.ts
vendored
@@ -16,17 +16,39 @@ declare module "sax" {
|
||||
position?: boolean;
|
||||
}
|
||||
|
||||
export interface Tag {
|
||||
name: string;
|
||||
attributes: { [key: string]: string };
|
||||
|
||||
// Available if opt.xmlns
|
||||
ns?: { [key: string]: string };
|
||||
prefix?: string;
|
||||
local?: string;
|
||||
uri?: string;
|
||||
export interface QualifiedName {
|
||||
name: string;
|
||||
prefix: string;
|
||||
local: string;
|
||||
uri: string;
|
||||
}
|
||||
|
||||
export interface Attribute extends QualifiedName {
|
||||
value: string;
|
||||
}
|
||||
|
||||
interface BaseTag {
|
||||
name: string;
|
||||
isSelfClosing: boolean;
|
||||
}
|
||||
|
||||
export interface QualifiedTag extends QualifiedName, BaseTag {
|
||||
ns: { [key: string]: string };
|
||||
attributes: { [key: string]: Attribute };
|
||||
}
|
||||
|
||||
export interface Tag extends BaseTag {
|
||||
attributes: { [key: string]: string };
|
||||
}
|
||||
|
||||
// export interface Tag extends BaseTag {
|
||||
// // If opt.xmlns available
|
||||
// ns?: { [key: string]: string };
|
||||
// // If opt.xmlns available, the attributes map value is an object type
|
||||
// attributes: { [key: string]: string | Attribute };
|
||||
// isSelfClosing: boolean;
|
||||
// }
|
||||
|
||||
export function parser(strict: boolean, opt: SAXOptions): SAXParser;
|
||||
export class SAXParser {
|
||||
constructor(strict: boolean, opt: SAXOptions);
|
||||
@@ -54,7 +76,7 @@ declare module "sax" {
|
||||
ontext(t: string): void;
|
||||
ondoctype(doctype: string): void;
|
||||
onprocessinginstruction(node: { name: string; body: string }): void;
|
||||
onopentag(tag: Tag): void;
|
||||
onopentag(tag: Tag | QualifiedTag): void;
|
||||
onclosetag(tagName: string): void;
|
||||
onattribute(attr: { name: string; value: string }): void;
|
||||
oncomment(comment: string): void;
|
||||
@@ -75,4 +97,3 @@ declare module "sax" {
|
||||
private _parser: SAXParser;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user