Created
October 26, 2011 18:23
-
-
Save dherman/1317251 to your computer and use it in GitHub Desktop.
sax cdata events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sax = require("sax"); | |
var fs = require("fs"); | |
function getCdata(path, cb) { | |
var results = []; | |
var stream = fs.createReadStream(path); | |
var saxStream = sax.createStream(false, { lowercasetags: true }); | |
var cdata; | |
saxStream.on("opencdata", function() { | |
console.log("OPEN CDATA"); | |
cdata = ""; | |
}); | |
saxStream.on("cdata", function(text) { | |
console.log("CDATA"); | |
cdata += text; | |
}); | |
saxStream.on("closecdata", function() { | |
console.log("CLOSE CDATA"); | |
results.push(cdata); | |
}); | |
saxStream.on("error", function(err) { | |
cb(err, null); | |
}); | |
saxStream.on("end", function() { | |
cb(null, results); | |
}); | |
stream.pipe(saxStream); | |
} | |
getCdata("./saxtest.xml", function(err, results) { | |
if (err) | |
console.log("ERROR: " + err); | |
else | |
console.log("RESULTS: " + results); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<overlay id="foo" | |
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> | |
<script type="application/x-javascript"><![CDATA[ | |
var x = "hello world"; | |
function say(x) { | |
alert(x); | |
} | |
say(x); | |
]]></script> | |
</overlay> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment