[Pkg-javascript-commits] [ltx] 236/469: documentation

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:03:07 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository ltx.

commit 282ec12c09cd4cbfb47a35b3bfda8bf324ff63fc
Author: Astro <astro at spaceboyz.net>
Date:   Fri Mar 23 22:01:31 2012 +0100

    documentation
---
 README.markdown | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)

diff --git a/README.markdown b/README.markdown
index b4ac945..2886ec1 100644
--- a/README.markdown
+++ b/README.markdown
@@ -2,11 +2,45 @@
 
 * *Element:* any XML Element
 * Text nodes are Strings
+* Runs on node.js and browserify
+
+
+## Parsing
+
+### DOM
+
+Parse a little document at once:
+
+    el = ltx.parse("<document/>")
+
+Push parser:
+
+	p = new ltx.Parser();
+	p.on('tree', function(tree) {
+		proceed(null, tree);
+	});
+	p.on('error', function(error) {
+		proceed(error);
+	});
+
+### SAX
+
+ltx implements multiple SAX backends:
+
+* *node-expat*: libexpat binding
+* *ltx*: fast native-JavaScript parser without error handling
+* *saxjs*: native-JavaScript parser
+
+If present, they are available through
+`ltx.availableSaxParsers`. Mostly, you'll want to do:
+
+    parser = new ltx.bestSaxParser();
+
+Refer to `lib/parse.js` for the interface.
 
 
 ## Element traversal
 
-* `Element(name, attrs?)`: constructor
 * `is(name, xmlns?)`: check
 * `getName()`: name without ns prefix
 * `getNS()`: element's xmlns, respects prefixes and searches upwards
@@ -31,6 +65,7 @@
 
 ## Modifying XML Elements
 
+* `new Element(name, attrs?)`: constructor
 * `remove(child)`: remove child by reference
 * `remove(name, xmlns)`: remove child by tag name and xmlns
 * `attr(attrName, value?)`: modify or get an attribute's value
@@ -39,7 +74,14 @@
 
 ## Building XML Elements
 
-This resembles strophejs a bit.
+    el = new ltx.Element('root').
+		c('children');
+	el.c('child', { age: 5 }).t('Hello').up()
+	  .c('child', { age: 7 }).t('Hello').up()
+	  .c('child', { age: 99 }).t('Hello').up()
+	console.log("Serialized document:", el.root().toString());
+
+This resembles Strophejs a bit.
 
 strophejs' XML Builder is very convenient for producing XMPP
 stanzas. node-xmpp includes it in a much more primitive way: the

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git



More information about the Pkg-javascript-commits mailing list