You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by an...@apache.org on 2016/05/31 06:46:36 UTC
[22/51] [partial] cordova-windows git commit: CB-11334 Reorganize
node_modules back to hierarchy tree
http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/4c0c81a1/node_modules/elementtree/node_modules/sax/examples/example.js
----------------------------------------------------------------------
diff --git a/node_modules/elementtree/node_modules/sax/examples/example.js b/node_modules/elementtree/node_modules/sax/examples/example.js
new file mode 100644
index 0000000..e7f81e6
--- /dev/null
+++ b/node_modules/elementtree/node_modules/sax/examples/example.js
@@ -0,0 +1,41 @@
+
+var fs = require("fs"),
+ sys = require("sys"),
+ path = require("path"),
+ xml = fs.cat(path.join(__dirname, "test.xml")),
+ sax = require("../lib/sax"),
+ strict = sax.parser(true),
+ loose = sax.parser(false, {trim:true}),
+ inspector = function (ev) { return function (data) {
+ // sys.error("");
+ // sys.error(ev+": "+sys.inspect(data));
+ // for (var i in data) sys.error(i+ " "+sys.inspect(data[i]));
+ // sys.error(this.line+":"+this.column);
+ }};
+
+xml.addCallback(function (xml) {
+ // strict.write(xml);
+
+ sax.EVENTS.forEach(function (ev) {
+ loose["on"+ev] = inspector(ev);
+ });
+ loose.onend = function () {
+ // sys.error("end");
+ // sys.error(sys.inspect(loose));
+ };
+
+ // do this one char at a time to verify that it works.
+ // (function () {
+ // if (xml) {
+ // loose.write(xml.substr(0,1000));
+ // xml = xml.substr(1000);
+ // process.nextTick(arguments.callee);
+ // } else loose.close();
+ // })();
+
+ for (var i = 0; i < 1000; i ++) {
+ loose.write(xml);
+ loose.close();
+ }
+
+});
http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/4c0c81a1/node_modules/elementtree/node_modules/sax/examples/get-products.js
----------------------------------------------------------------------
diff --git a/node_modules/elementtree/node_modules/sax/examples/get-products.js b/node_modules/elementtree/node_modules/sax/examples/get-products.js
new file mode 100644
index 0000000..9e8d74a
--- /dev/null
+++ b/node_modules/elementtree/node_modules/sax/examples/get-products.js
@@ -0,0 +1,58 @@
+// pull out /GeneralSearchResponse/categories/category/items/product tags
+// the rest we don't care about.
+
+var sax = require("../lib/sax.js")
+var fs = require("fs")
+var path = require("path")
+var xmlFile = path.resolve(__dirname, "shopping.xml")
+var util = require("util")
+var http = require("http")
+
+fs.readFile(xmlFile, function (er, d) {
+ http.createServer(function (req, res) {
+ if (er) throw er
+ var xmlstr = d.toString("utf8")
+
+ var parser = sax.parser(true)
+ var products = []
+ var product = null
+ var currentTag = null
+
+ parser.onclosetag = function (tagName) {
+ if (tagName === "product") {
+ products.push(product)
+ currentTag = product = null
+ return
+ }
+ if (currentTag && currentTag.parent) {
+ var p = currentTag.parent
+ delete currentTag.parent
+ currentTag = p
+ }
+ }
+
+ parser.onopentag = function (tag) {
+ if (tag.name !== "product" && !product) return
+ if (tag.name === "product") {
+ product = tag
+ }
+ tag.parent = currentTag
+ tag.children = []
+ tag.parent && tag.parent.children.push(tag)
+ currentTag = tag
+ }
+
+ parser.ontext = function (text) {
+ if (currentTag) currentTag.children.push(text)
+ }
+
+ parser.onend = function () {
+ var out = util.inspect(products, false, 3, true)
+ res.writeHead(200, {"content-type":"application/json"})
+ res.end("{\"ok\":true}")
+ // res.end(JSON.stringify(products))
+ }
+
+ parser.write(xmlstr).end()
+ }).listen(1337)
+})
http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/4c0c81a1/node_modules/elementtree/node_modules/sax/examples/hello-world.js
----------------------------------------------------------------------
diff --git a/node_modules/elementtree/node_modules/sax/examples/hello-world.js b/node_modules/elementtree/node_modules/sax/examples/hello-world.js
new file mode 100644
index 0000000..cbfa518
--- /dev/null
+++ b/node_modules/elementtree/node_modules/sax/examples/hello-world.js
@@ -0,0 +1,4 @@
+require("http").createServer(function (req, res) {
+ res.writeHead(200, {"content-type":"application/json"})
+ res.end(JSON.stringify({ok: true}))
+}).listen(1337)
http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/4c0c81a1/node_modules/elementtree/node_modules/sax/examples/not-pretty.xml
----------------------------------------------------------------------
diff --git a/node_modules/elementtree/node_modules/sax/examples/not-pretty.xml b/node_modules/elementtree/node_modules/sax/examples/not-pretty.xml
new file mode 100644
index 0000000..9592852
--- /dev/null
+++ b/node_modules/elementtree/node_modules/sax/examples/not-pretty.xml
@@ -0,0 +1,8 @@
+<root>
+ something<else> blerm <slurm
+
+
+ attrib =
+ "blorg" ></else><!-- COMMENT!
+
+--><![CDATA[processing...]]> <selfclosing tag="blr>""/> a bit down here</root>
http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/4c0c81a1/node_modules/elementtree/node_modules/sax/examples/pretty-print.js
----------------------------------------------------------------------
diff --git a/node_modules/elementtree/node_modules/sax/examples/pretty-print.js b/node_modules/elementtree/node_modules/sax/examples/pretty-print.js
new file mode 100644
index 0000000..cd6aca9
--- /dev/null
+++ b/node_modules/elementtree/node_modules/sax/examples/pretty-print.js
@@ -0,0 +1,74 @@
+var sax = require("../lib/sax")
+ , printer = sax.createStream(false, {lowercasetags:true, trim:true})
+ , fs = require("fs")
+
+function entity (str) {
+ return str.replace('"', '"')
+}
+
+printer.tabstop = 2
+printer.level = 0
+printer.indent = function () {
+ print("\n")
+ for (var i = this.level; i > 0; i --) {
+ for (var j = this.tabstop; j > 0; j --) {
+ print(" ")
+ }
+ }
+}
+printer.on("opentag", function (tag) {
+ this.indent()
+ this.level ++
+ print("<"+tag.name)
+ for (var i in tag.attributes) {
+ print(" "+i+"=\""+entity(tag.attributes[i])+"\"")
+ }
+ print(">")
+})
+
+printer.on("text", ontext)
+printer.on("doctype", ontext)
+function ontext (text) {
+ this.indent()
+ print(text)
+}
+
+printer.on("closetag", function (tag) {
+ this.level --
+ this.indent()
+ print("</"+tag+">")
+})
+
+printer.on("cdata", function (data) {
+ this.indent()
+ print("<![CDATA["+data+"]]>")
+})
+
+printer.on("comment", function (comment) {
+ this.indent()
+ print("<!--"+comment+"-->")
+})
+
+printer.on("error", function (error) {
+ console.error(error)
+ throw error
+})
+
+if (!process.argv[2]) {
+ throw new Error("Please provide an xml file to prettify\n"+
+ "TODO: read from stdin or take a file")
+}
+var xmlfile = require("path").join(process.cwd(), process.argv[2])
+var fstr = fs.createReadStream(xmlfile, { encoding: "utf8" })
+
+function print (c) {
+ if (!process.stdout.write(c)) {
+ fstr.pause()
+ }
+}
+
+process.stdout.on("drain", function () {
+ fstr.resume()
+})
+
+fstr.pipe(printer)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org