mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-29 00:51:29 +08:00
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.
45 lines
943 B
TypeScript
45 lines
943 B
TypeScript
/// <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"));
|