diff --git a/doc/DOM.html b/doc/DOM.html index 7c74dc0e..e78e9c59 100644 --- a/doc/DOM.html +++ b/doc/DOM.html @@ -3,11 +3,11 @@
python/tests
directory. Here are some excepts from those
tests:
This is a basic test of the file interface and DOM navigation:
-import libxml2
+import libxml2
doc = libxml2.parseFile("tst.xml")
if doc.name != "tst.xml":
@@ -141,7 +142,7 @@ child = root.children
if child.name != "foo":
print "child.name failed"
sys.exit(1)
-doc.freeDoc()
+doc.freeDoc()
The Python module is called libxml2, parseFile is the equivalent of xmlParseFile (most of the bindings are automatically generated, and the xml prefix is removed and the casing convention are kept). All node seen at the @@ -174,7 +175,7 @@ collected.
This test check the validation interfaces and redirection of error messages:
-import libxml2
+import libxml2
#desactivate error messages from the validation
def noerr(ctx, str):
@@ -189,7 +190,7 @@ doc = ctxt.doc()
valid = ctxt.isValid()
doc.freeDoc()
if valid != 0:
- print "validity chec failed"
+ print "validity chec failed"
The first thing to notice is the call to registerErrorHandler(), it defines a new error handler global to the library. It is used to avoid seeing the error messages when trying to validate the invalid document.
@@ -203,13 +204,13 @@ best to get a complete view of what methods are supported is to look at the libxml2.py module containing all the wrappers.This test show how to activate the push parser interface:
-import libxml2
+import libxml2
ctxt = libxml2.createPushParser(None, "<foo", 4, "test.xml")
ctxt.parseChunk("/>", 2, 1)
doc = ctxt.doc()
-doc.freeDoc()
+doc.freeDoc()
The context is created with a speciall call based on the xmlCreatePushParser() from the C library. The first argument is an optional SAX callback object, then the initial set of data, the lenght and the name of @@ -220,7 +221,7 @@ setting the thrird argument terminate to 1.
this test show the use of the event based parsing interfaces. In this case the parser does not build a document, but provides callback information as the parser makes progresses analyzing the data being provided:
-import libxml2
+import libxml2
log = ""
class callback:
@@ -267,7 +268,7 @@ ctxt.parseChunk(chunk, len(chunk), 1)
reference = "startDocument:startElement foo {'url': 'tst'}:characters: bar:endElement foo:endDocument:"
if log != reference:
print "Error got: %s" % log
- print "Exprected: %s" % reference
+ print "Exprected: %s" % reference
The key object in that test is the handler, it provides a number of entry points which can be called by the parser as it makes progresses to indicate the information set obtained. The full set of callback is larger than what @@ -280,7 +281,7 @@ single character call even though the string "bar" is passed to the pa from 2 different call to parseChunk()
This is a basic test of XPath warppers support
-import libxml2
+import libxml2
doc = libxml2.parseFile("tst.xml")
ctxt = doc.xpathNewContext()
@@ -292,7 +293,7 @@ if res[0].name != "doc" or res[1].name != "foo":
print "xpath query: wrong node set value"
sys.exit(1)
doc.freeDoc()
-ctxt.xpathFreeContext()
+ctxt.xpathFreeContext()
This test parses a file, then create an XPath context to evaluate XPath expression on it. The xpathEval() method execute an XPath query and returns the result mapped in a Python way. String and numbers are natively converted, @@ -303,7 +304,7 @@ the document must be freed after the result of the query is used.
This test shows how to extend the XPath engine with functions written in python:
-import libxml2
+import libxml2
def foo(ctx, x):
return x + 1
@@ -315,13 +316,13 @@ res = ctxt.xpathEval("foo(1)")
if res != 2:
print "xpath extension failure"
doc.freeDoc()
-ctxt.xpathFreeContext()
+ctxt.xpathFreeContext()
Note how the extension function is registered with the context (but that part is not yet finalized, ths may change slightly in the future).
This test is similar to the previousone but shows how the extension function can access the XPath evaluation context:
-def foo(ctx, x):
+def foo(ctx, x):
global called
#
@@ -330,23 +331,23 @@ function can access the XPath evaluation context:
pctxt = libxml2.xpathParserContext(_obj=ctx)
ctxt = pctxt.context()
called = ctxt.function()
- return x + 1
+ return x + 1
All the interfaces around the XPath parser(or rather evaluation) context are not finalized, but it should be sufficient to do contextual work at the evaluation point.
last but not least, all tests starts with the following prologue:
-#memory debug specific
+#memory debug specific
libxml2.debugMemory(1)
-
+
and ends with the following epilogue:
-#memory debug specific
+#memory debug specific
libxml2.cleanupParser()
if libxml2.debugMemory(1) == 0:
print "OK"
else:
print "Memory leak %d bytes" % (libxml2.debugMemory(1))
- libxml2.dumpMemory()
+ libxml2.dumpMemory()
Those activate the memory debugging interface of libxml2 where all
alloacted block in the library are tracked. The prologue then cleans up the
library state and checks that all allocated memory has been freed. If not it
diff --git a/doc/site.xsl b/doc/site.xsl
index 24495c6f..2591cf51 100644
--- a/doc/site.xsl
+++ b/doc/site.xsl
@@ -213,11 +213,11 @@
-->