summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorscoder <none@none>2008-01-28 15:44:37 +0100
committerscoder <none@none>2008-01-28 15:44:37 +0100
commit86be0645413e29f554bf9a35097234851d1fb403 (patch)
treea51d73dd79fc2fe2f04fe7eaf1229a609609f5b2
parentd9dbd6d7b3c3f37bd20213ae4e9c98f5fbb7c71a (diff)
downloadpython-lxml-86be0645413e29f554bf9a35097234851d1fb403.tar.gz
[svn r3223] r3357@delle: sbehnel | 2008-01-28 15:44:16 +0100
doc cleanup --HG-- branch : trunk
-rw-r--r--doc/objectify.txt26
-rw-r--r--doc/validation.txt4
2 files changed, 18 insertions, 12 deletions
diff --git a/doc/objectify.txt b/doc/objectify.txt
index 5c0c83c4..7d290235 100644
--- a/doc/objectify.txt
+++ b/doc/objectify.txt
@@ -362,18 +362,18 @@ or for names that have a special meaning in lxml.objectify::
Asserting a Schema
==================
-When dealing with XML documents from different sources, it can often
-be interesting to assure that they follow a common schema. In
-lxml.objectify, this directly translates to enforcing a specific
-object tree, i.e. expected object attributes are ensured to be there
-and to have the expected type. This can easily be achieved through
-XML Schema validation at parse time. Also see the `documentation on
-validation`_ on this topic.
+When dealing with XML documents from different sources, you will often
+require them to follow a common schema. In lxml.objectify, this
+directly translates to enforcing a specific object tree, i.e. expected
+object attributes are ensured to be there and to have the expected
+type. This can easily be achieved through XML Schema validation at
+parse time. Also see the `documentation on validation`_ on this
+topic.
.. _`documentation on validation`: validation.html
First of all, we need a parser that knows our schema, so let's say we
-parse the schema from a file (or filename or file-like object)::
+parse the schema from a file-like object (or file or filename)::
>>> from StringIO import StringIO
>>> f = StringIO('''\
@@ -388,12 +388,14 @@ parse the schema from a file (or filename or file-like object)::
... ''')
>>> schema = etree.XMLSchema(file=f)
-When creating the validating parser, we must make sure it returns
-objectify trees. This is best done with the ``makeparser()``
+When creating the validating parser, we must make sure it `returns
+objectify trees`_. This is best done with the ``makeparser()``
function::
>>> parser = objectify.makeparser(schema = schema)
+.. _`returns objectify trees`: #advance-element-class-lookup
+
Now we can use it to parse a valid document::
>>> xml = "<a><b>test</b></a>"
@@ -409,8 +411,8 @@ Or an invalid document::
Traceback (most recent call last):
XMLSyntaxError: Element 'c': This element is not expected.
-Note that the same works for parse-time DTD validation, except that it
-does not support any data types by design.
+Note that the same works for parse-time DTD validation, except that
+DTDs do not support any data types by design.
ObjectPath
diff --git a/doc/validation.txt b/doc/validation.txt
index ffc19ef8..3f07f2b7 100644
--- a/doc/validation.txt
+++ b/doc/validation.txt
@@ -75,6 +75,10 @@ will raise an exception::
Traceback (most recent call last):
XMLSyntaxError: Element 'a': 'not int' is not a valid value of the atomic type 'xs:integer'.
+If you want the parser to succeed regardless of the outcome of the
+validation, you should use a non validating parser and run the
+validation separately after parsing the document.
+
DTD
---