[z3-checkins] r5116 - in z3/zopexml: . branch tag trunk trunk/element trunk/element/tests trunk/interfaces trunk/interfaces/dom trunk/tests

philikon at codespeak.net philikon at codespeak.net
Wed Jun 16 16:54:16 MEST 2004


Author: philikon
Date: Wed Jun 16 16:54:15 2004
New Revision: 5116

Added:
   z3/zopexml/
   z3/zopexml/branch/
   z3/zopexml/tag/
   z3/zopexml/trunk/
   z3/zopexml/trunk/__init__.py
   z3/zopexml/trunk/browser.py
   z3/zopexml/trunk/configure.zcml
   z3/zopexml/trunk/element/
   z3/zopexml/trunk/element/__init__.py
   z3/zopexml/trunk/element/configure.zcml
   z3/zopexml/trunk/element/persisttree.py
   z3/zopexml/trunk/element/tests/
   z3/zopexml/trunk/element/tests/__init__.py
   z3/zopexml/trunk/element/tests/test_xmldocument.py
   z3/zopexml/trunk/element/xmldocument.py
   z3/zopexml/trunk/field.py
   z3/zopexml/trunk/interfaces/
   z3/zopexml/trunk/interfaces/__init__.py
   z3/zopexml/trunk/interfaces/dom/
   z3/zopexml/trunk/interfaces/dom/__init__.py
   z3/zopexml/trunk/interfaces/dom/core.py
   z3/zopexml/trunk/interfaces/dom/loadsave.py
   z3/zopexml/trunk/interfaces/dom/printer.py
   z3/zopexml/trunk/interfaces/dom/traversal.py
   z3/zopexml/trunk/interfaces/dom/xmlextended.py
   z3/zopexml/trunk/interfaces/field.py
   z3/zopexml/trunk/interfaces/source.py
   z3/zopexml/trunk/interfaces/statistics.py
   z3/zopexml/trunk/interfaces/xmldocument.py
   z3/zopexml/trunk/statistics.pt
   z3/zopexml/trunk/statistics.py
   z3/zopexml/trunk/tests/
   z3/zopexml/trunk/tests/__init__.py
   z3/zopexml/trunk/tests/test_field.py
   z3/zopexml/trunk/tests/test_statistics.py
   z3/zopexml/trunk/tests/test_xmldocument.py
   z3/zopexml/trunk/xmldocument.py
Log:
Added 'zopexml' package. This is the XML machinery invented by Martijn
Faassen and Philipp von Weitershausen at the Louvain-La-Neuve sprint
in April 2003. It was formerly resting at http://cvs.infrae.com/z3.


Added: z3/zopexml/trunk/__init__.py
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/__init__.py	Wed Jun 16 16:54:15 2004
@@ -0,0 +1 @@
+# this is a package

Added: z3/zopexml/trunk/browser.py
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/browser.py	Wed Jun 16 16:54:15 2004
@@ -0,0 +1,37 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""XML-Document Views
+
+$Id: browser.py,v 1.2 2003/12/07 12:20:44 faassen Exp $
+"""
+from zope.app.publisher.browser import BrowserView
+from zopexml import statistics
+
+class XMLDocumentView:
+
+    def show(self):
+        """Show the XML text"""
+        request = self.request
+        request.response.setHeader('Content-Type', 'text/xml')
+        return self.context.source
+
+class StatisticsView(BrowserView):
+    def __init__(self, context, request):
+        super(BrowserView, self).__init__(context, request)
+        stats = statistics.parse(context.source)
+        self.elements = stats.getElementCountMap()
+        self.attributes = stats.getAttributeCountMap()
+        self.max_depth = stats.getMaxDepth()
+        self.max_children = stats.getMaxChildren()
+        self.character_count = stats.getCharacterCount()

Added: z3/zopexml/trunk/configure.zcml
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/configure.zcml	Wed Jun 16 16:54:15 2004
@@ -0,0 +1,77 @@
+<configure
+    xmlns='http://namespaces.zope.org/zope'
+    xmlns:browser='http://namespaces.zope.org/browser'
+    xmlns:fssync='http://namespaces.zope.org/fssync'
+    i18n_domain='zopexml'
+    >
+
+<!-- XML document -->
+
+<content class=".xmldocument.XMLDocument">
+  <factory
+    id="XMLDocument"
+    permission="zope.ManageContent"
+    title="XML Document"
+    description="A simple XML Document" />
+  
+  <require
+    permission="zope.View"
+    attributes="source" />
+  
+  <require
+    permission="zope.ManageContent"
+    set_attributes="source" />
+  
+  <implements
+    interface="zope.app.interfaces.annotation.IAttributeAnnotatable" />
+  
+</content>
+
+<fssync:adapter
+  class=".xmldocument.XMLDocument"
+  factory=".xmldocument.XMLDocumentAdapter"
+  />
+
+<browser:menuItem
+  menu="add_content"
+  for="zope.app.interfaces.container.IAdding"
+  title="XML Document" action="XMLDocument"
+  description="An object storing XML text." 
+  permission="zope.ManageContent"
+  />
+
+<!-- XML Document View Directives -->
+
+<browser:page
+  name="index.html"
+  for="zopexml.interfaces.xmldocument.IXMLDocument"
+  class=".browser.XMLDocumentView"
+  attribute="show"
+  permission="zope.View" />
+
+<browser:editform
+  schema="zopexml.interfaces.xmldocument.IXMLDocument"
+  name="edit.html"
+  menu="zmi_views"
+  label="Edit an XML document"
+  permission="zope.ManageContent" />
+
+<browser:page
+  for="zopexml.interfaces.source.IXMLText"
+  class=".browser.StatisticsView"
+  permission="zope.View"
+  name="statistics.html"
+  template="statistics.pt"
+  menu="zmi_views"
+  title="Statistics"
+  />
+
+<!-- XXX we don't have an icon for this yet
+     <icon name="zmi_icon"
+     for="zope.app.content.xmldocument.IXMLDocument" file="xml.gif" />
+-->
+
+<!-- comment this out if you don't want ElementTree document -->
+<include package=".element" />
+
+</configure>

Added: z3/zopexml/trunk/element/__init__.py
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/element/__init__.py	Wed Jun 16 16:54:15 2004
@@ -0,0 +1 @@
+# this is a package

Added: z3/zopexml/trunk/element/configure.zcml
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/element/configure.zcml	Wed Jun 16 16:54:15 2004
@@ -0,0 +1,45 @@
+<configure
+    xmlns='http://namespaces.zope.org/zope'
+    xmlns:browser='http://namespaces.zope.org/browser'
+    xmlns:fssync='http://namespaces.zope.org/fssync'
+    i18n_domain='zopexml'
+    >
+
+<content class=".xmldocument.ElementTreeDocument">
+  <factory
+    id="ElementTreeDocument"
+    permission="zope.ManageContent"
+    title="Element Tree XML Document"
+    description="ElementTree based XML Document" />
+  
+  <require
+    permission="zope.View"
+    attributes="source" />
+  
+  <require
+    permission="zope.ManageContent"
+    set_attributes="source" />
+  
+  <require
+    permission="zope.ManageContent"
+    attributes="tree" />
+
+  <implements
+    interface="zope.app.interfaces.annotation.IAttributeAnnotatable" />
+  
+</content>
+
+<fssync:adapter
+  class=".xmldocument.ElementTreeDocument"
+  factory="zopexml.xmldocument.XMLDocumentAdapter"
+  />
+
+<browser:menuItem
+  menu="add_content"
+  for="zope.app.interfaces.container.IAdding"
+  title="Element Tree XML Document" action="ElementTreeDocument"
+  description="An object storing XML text as an Element Tree." 
+  permission="zope.ManageContent"
+  />
+
+</configure>

Added: z3/zopexml/trunk/element/persisttree.py
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/element/persisttree.py	Wed Jun 16 16:54:15 2004
@@ -0,0 +1,73 @@
+from elementtree import ElementTree as et
+from persistence import Persistent
+ei = et._ElementInterface
+
+# XXX a hack to make persisttree API consistent with ElementTree module
+from elementtree.ElementTree import *
+
+#for name in et.__all__:
+#    exec "from elementtree.ElementTree import %s" % name
+
+class _ElementInterface(Persistent, et._ElementInterface):
+    def __init__(self, tag, attrib):
+        # XXX can't use super here?
+        et._ElementInterface.__init__(self, tag, attrib)
+
+    def __setitem__(self, index, element):
+        super(_ElementInterface, self).__setitem__(index, element)
+        self._p_changed = True
+    
+    def __delitem__(self, index):
+        super(_ElementInterface, self).__getitem__(index)
+        self._p_changed = True
+
+    def __setslice__(self, start, stop, elements):
+        super(_ElementInterface, self).__setslice(start, stop, elements)
+        self._p_changed = True
+
+    def __delslice__(self, start, stop):
+        super(_ElementInterface, self).__delslice__(start, stop)
+        self._p_changed = True
+
+    def makeelement(self, tag, attrib):
+        return Element(tag, attrib)
+    
+    def append(self, element):
+        super(_ElementInterface, self).append(element)
+        self._p_changed = True
+
+    def insert(self, index, element):
+        super(_ElementInterface, self).insert(index, element)
+        self._p_changed = True
+
+    def remove(self, element):
+        super(_ElementInterface, self).remove(element)
+        self._p_changed = True
+
+    def clear(self):
+        super(_ElementInterface, self).clear()
+        self._p_changed = True
+
+    def set(self, key, value):
+        super(_ElementInterface, self).set()
+        self._p_changed = True
+
+def Element(tag, attrib={}, **extra):
+    attrib = attrib.copy()
+    attrib.update(extra)
+    return _ElementInterface(tag, attrib)
+
+def SubElement(parent, tag, attrib={}, **extra):
+    attrib = attrib.copy()
+    attrib.update(extra)
+    element = Element(tag, attrib)
+    parent.append(element)
+
+class TreeBuilder(et.TreeBuilder):
+    def __init__(self):
+        super(TreeBuilder, self).__init__(_ElementInterface)
+    
+class XMLTreeBuilder(et.XMLTreeBuilder):
+    def __init__(self, html=0):
+        super(XMLTreeBuilder, self).__init__(html, target=TreeBuilder())
+

Added: z3/zopexml/trunk/element/tests/__init__.py
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/element/tests/__init__.py	Wed Jun 16 16:54:15 2004
@@ -0,0 +1 @@
+# this is a package

Added: z3/zopexml/trunk/element/tests/test_xmldocument.py
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/element/tests/test_xmldocument.py	Wed Jun 16 16:54:15 2004
@@ -0,0 +1,35 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+ElementTreeDocument.
+
+$Id: test_xmldocument.py,v 1.1 2003/12/07 11:44:40 faassen Exp $
+"""
+
+import unittest
+from zopexml.tests.test_xmldocument import XMLDocumentTests
+from zopexml.element.xmldocument import ElementTreeDocument
+from zopexml.element.persisttree import Element
+
+class ElementTreeTests(XMLDocumentTests):
+    def factory(self, *args, **kw):
+        return ElementTreeDocument(*args, **kw)
+
+    def test_treemanip(self):
+        doc = self.factory()
+        doc.tree.append(Element('foo'))
+        self.assertEquals('<doc><foo /></doc>', doc.source)
+        
+def test_suite():
+    return unittest.makeSuite(ElementTreeTests)

Added: z3/zopexml/trunk/element/xmldocument.py
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/element/xmldocument.py	Wed Jun 16 16:54:15 2004
@@ -0,0 +1,26 @@
+from StringIO import StringIO
+from persistence import Persistent
+from zope.interface import implements
+from zopexml.interfaces.xmldocument import IElementTreeDocument
+from zopexml.element import persisttree
+
+class ElementTreeDocument(Persistent):
+    implements(IElementTreeDocument)
+
+    # note the space after 'doc' to please ElementTree serialization
+    def __init__(self, source='<doc />'):
+        self.source = source
+
+    def _setSource(self, value):
+        self._tree = persisttree.parse(StringIO(value)).getroot()
+
+    def _getSource(self):
+        return persisttree.tostring(self._tree)
+
+    def _getTree(self):
+        return self._tree
+
+    source = property(_getSource, _setSource)
+
+    tree = property(_getTree)
+    

Added: z3/zopexml/trunk/field.py
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/field.py	Wed Jun 16 16:54:15 2004
@@ -0,0 +1,39 @@
+##############################################################################
+#
+# Copyright (c) 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+$Id: field.py,v 1.1.1.1 2003/12/06 15:02:19 faassen Exp $
+"""
+from zopexml.interfaces.field import IXML
+from zope.schema.interfaces import ValidationError
+from zope.schema import Bytes
+from zope.schema.fieldproperty import FieldProperty
+from xml.parsers.expat import ParserCreate, ExpatError
+from zope.interface import implements
+
+NotWellFormedXML = u"NotWellFormedXML"
+
+class XML(Bytes):
+    implements(IXML)
+
+    check_wellformedness = FieldProperty(IXML['check_wellformedness'])
+
+    def _validate(self, value):
+        super(XML, self)._validate(value)
+        if not self.check_wellformedness:
+            return
+        parser = ParserCreate()
+        try:
+            parser.Parse(value, True)
+        except ExpatError, e:
+            raise ValidationError(NotWellFormedXML)

Added: z3/zopexml/trunk/interfaces/__init__.py
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/interfaces/__init__.py	Wed Jun 16 16:54:15 2004
@@ -0,0 +1 @@
+# this is a package

Added: z3/zopexml/trunk/interfaces/dom/__init__.py
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/interfaces/dom/__init__.py	Wed Jun 16 16:54:15 2004
@@ -0,0 +1 @@
+# this is a package 

Added: z3/zopexml/trunk/interfaces/dom/core.py
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/interfaces/dom/core.py	Wed Jun 16 16:54:15 2004
@@ -0,0 +1,899 @@
+##############################################################################
+#
+# Copyright (c) 2003 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+DOM core interfaces
+
+See the W3C DOM Level 3 specification for detailled documentation:
+http://www.w3.org/TR/DOM-Level-3-Core/core.html
+
+$Id: core.py,v 1.1 2004/02/09 00:49:31 philikon Exp $
+"""
+
+from zope.interface import Interface
+from zope.schema import Field, Int, Bool, Text, TextLine, URI, List
+from zopexml.interfaces.source import IXMLSource
+
+class ILength(Interface):
+
+    length = Int(
+        title=u"Length",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+class IDOMStringList(ILength):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+    # introduced in DOM Level 3
+
+    def contains(str):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def item(index):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+class INameList(ILength):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+    # introduced in DOM Level 3
+
+    def contains(str):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def containsNS(namespace, name):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def getName(index):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def getNamespaceURI(index):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+class IDOMImplementationList(ILength):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+    # introduced in DOM Level 3
+
+    def item(index):
+        """
+        See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+class IDOMImplementationSource(Interface):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+    # introduced in DOM Level 3
+
+    def getDOMImplementation(features):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def getDOMImplementations(features):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+class IDOMImplementation(Interface):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+
+    def createDocument(namespaceURI, qualifiedName, doctype):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def createDocumentType(qualifiedName, publicId, systemId):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def getFeature(feature, version):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+        # introduced in DOM Level 3
+
+    def hasFeature(feature, version):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+class INode(Interface):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+
+    #
+    # Definition group NodeType
+    #
+
+    ELEMENT_NODE                = Int()
+    ATTRIBUTE_NODE              = Int()
+    TEXT_NODE                   = Int()
+    CDATA_SECTION_NODE          = Int()
+    ENTITY_REFERENCE_NODE       = Int()
+    ENTITY_NODE                 = Int()
+    PROCESSING_INSTRUCTION_NODE = Int()
+    COMMENT_NODE                = Int()
+    DOCUMENT_NODE               = Int()
+    DOCUMENT_TYPE_NODE          = Int()
+    DOCUMENT_FRAGMENT_NODE      = Int()
+    NOTATION_NODE               = Int()
+
+    #
+    # Definition group DocumentPosition
+    #
+
+    DOCUMENT_POSITION_DISCONNECTED            = Int()
+    DOCUMENT_POSITION_PRECEDING               = Int()
+    DOCUMENT_POSITION_FOLLOWING               = Int()
+    DOCUMENT_POSITION_CONTAINS                = Int()
+    DOCUMENT_POSITION_CONTAINED_BY            = Int()
+    DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = Int()
+
+    #
+    # Attributes
+    #
+
+    attributes = Field(
+        title=u"Attributes",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    baseURI = URI(
+        title=u"Base URI",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        # introduced in DOM Level 3
+        )
+
+    childNodes = Field(
+        title=u"Child nodes",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    firstChild = Field(
+        title=u"First child",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    lastChild = Field(
+        title=u"Last child",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    localName = TextLine(
+        title=u"Local name",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    namespaceURI = URI(
+        title=u"Namespace",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    nextSibling = Field(
+        title=u"Next sibling",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    nodeName = TextLine(
+        title=u"Node name",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    nodeType = Int(
+        title=u"Node type",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    nodeValue = TextLine(
+        title=u"Node value",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html"
+        )
+
+    ownerDocument = Field(
+        title=u"Owner document",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    parentNode = Field(
+        title=u"Parent node",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    prefix = TextLine(
+        title=u"Prefix",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html"
+        )
+
+    previousSibling = Field(
+        title=u"Previous sibling",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    textContent = Text(
+        title=u"Text content",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html"
+        # introduced in DOM Level 3
+        )
+
+    #
+    # Methods
+    #
+
+    def appendChild(newChild):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def cloneNode(deep):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def compareDocumentPosition(other):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+        # introduced in DOM Level 3
+
+    def getFeature(feature, version):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+        # introduced in DOM Level 3
+
+    def getUserData(key):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+        # introduced in DOM Level 3
+
+    def hasAttributes():
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def hasChildNodes():
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def insertBefore(newChild, refChild):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def isDefaultNamespace(namespaceURI):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+        # introduced in DOM Level 3
+
+    def isEqualNode(arg):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+        # introduced in DOM Level 3
+
+    def isSameNode(other):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+        # introduced in DOM Level 3
+
+    def isSupported(feature, version):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def lookupNamespaceURI(prefix):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+        # introduced in DOM Level 3
+
+    def lookupPrefix(namespaceURI):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+        # introduced in DOM Level 3
+
+    def normalize():
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def removeChild(oldChild):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def replaceChild(newChild, oldChild):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def setUserData(key, data, handler):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+        # introduced in DOM Level 3
+
+class IDocument(INode, IXMLSource):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+
+    #
+    # Attributes
+    #
+
+    doctype = Field(
+        title=u"Doctype",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    documentElement = Field(
+        title=u"Document element",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    documentURI = URI(
+        title=u"Document URI",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html"
+        # introduced in DOM Level 3
+        )
+
+    domConfig = Field(
+        title=u"DOM config",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        # introduced in DOM Level 3
+        )
+
+    implementation = Field(
+        title=u"Implementation",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    strictErrorChecking = Bool(
+        title=u"Strict error checking",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html"
+        # introduced in DOM Level 3
+        )
+
+    inputEncoding = TextLine(
+        title=u"Input encoding",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        # introduced in DOM Level 3
+        )
+
+    strictErrorChecking = Bool(
+        title=u"Strict error checking",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html"
+        # introduced in DOM Level 3
+        )
+
+    xmlEncoding = TextLine(
+        title=u"XML Encoding",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        # introduced in DOM Level 3
+        )
+
+    xmlStandalone = Bool(
+        title=u"XML Standalone",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html"
+        # introduced in DOM Level 3
+        )
+
+    xmlVersion = TextLine(
+        title=u"XML Version",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html"
+        # introduced in DOM Level 3
+        )
+
+    #
+    # Methods
+    #
+
+    def adoptNode(source):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+        # introduced in DOM Level 3
+
+    def createAttribute(name):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def createAttributeNS(namespaceURI, qualifiedName):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def createCDATASection(data):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def createComment(data):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def createDocumentFragment():
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def createElement(tagElement):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def createElementNS(namespaceURI, qualifiedName):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def createEntityReference(name):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def createProcessingInstruction(target, data):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def createTextNode(data):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def getElementById(elementId):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def getElementsByTagName(tagname):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def getElementsByTagNameNS(namespaceURI, localName):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def importNode(importedNode, deep):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def normalizeDocument():
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+        # introduced in DOM Level 3
+
+    def renameNode(n, namespaceURI, qualifiedName):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+        # introduced in DOM Level 3
+
+class IDocumentFragment(INode):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+
+class INodeList(ILength):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+
+    def item(index):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+class INamedNodeMap(ILength):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+
+    def getNamedItem(name):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def getNamedItemNS(namespaceURI, qualifiedName):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def item(index):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def removeNamedItem(name):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def removeNamedItemNS(namespaceURI, qualifiedName):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def setNamedItem(arg):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def setNamedItemNS(arg):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+class ICharacterData(ILength):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+
+    #
+    # Attributes
+    #
+
+    data = Text(
+        title=u"Data",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html"
+        )
+
+    #
+    # Methods
+    #
+
+    def appendData(arg):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def deleteData(offset, count):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def insertData(offset, arg):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def replaceData(offset, count, arg):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def substringData(offset, count):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+class IAttr(INode):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+
+    isId = Bool(
+        title=u"Is ID",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        # introduced in DOM Level 3
+        )
+
+    name = TextLine(
+        title=u"Name",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    ownerElement = Field(
+        title=u"Owner element",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    schemaTypeInfo = Field(
+        title=u"Schema type info",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        # introduced in DOM Level 3
+        )
+
+    specified = Bool(
+        title=u"Specified",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    value = Text(
+        title=u"Value",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html"
+        )
+
+class IElement(INode):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+
+    #
+    # Attributes
+    #
+
+    schemaTypeInfo = Field(
+        title=u"Schema type info",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        # introduced in DOM Level 3
+        )
+
+    tagName = TextLine(
+        title=u"Tag name",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    #
+    # Methods
+    #
+
+    def getAttribute(name):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def getAttributeNS(namespaceURI, localName):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def getAttributeNode(name):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def getAttributeNodeNS(namespaceURI, localName):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def getElementsByTagName(name):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def getElementsByTagNameNS(namespaceURI, localName):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def hasAttribute(name):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def hasAttributeNS(namespaceURI, localName):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def removeAttribute(name):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def removeAttributeNS(namespaceURI, localName):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def removeAttributeNode(oldAttr):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def setAttribute(name, value):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def setAttributeNS(namespaceURI, qualifiedName, value):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def setAttributeNode(newAttr):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def setAttributeNodeNS(newAttr):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def setIdAttribute(name, isId):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+        # introduced in DOM Level 3
+
+    def setIdAttributeNS(namespaceURI, localName, isId):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+        # introduced in DOM Level 3
+
+    def setIdAttributeNode(idAttr, isId):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+class IText(ICharacterData):
+    """
+    See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+
+    isElementContentWhitespace = Bool(
+        title=u"Is element content whitespace",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        # introduced in DOM Level 3
+        )
+
+    wholeText = Text(
+        title=u"Whole text",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        # introduced in DOM Level 3
+        )
+
+    def replaceWholeText(content):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+        # introduced in DOM Level 3
+
+    def splitText(offset):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+class IComment(ICharacterData):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+
+class ITypeInfo(Interface):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+    # introduced in DOM Level 3
+
+    DERIVATION_RESTRICTION         = Int()
+    DERIVATION_EXTENSION           = Int()
+    DERIVATION_UNION               = Int()
+    DERIVATION_LIST                = Int()
+
+    typeName = TextLine(
+        title=u"Type name",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    typeNameSpace = TextLine(
+        title=u"Type Namespace",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    def isDerivedFrom(typeNamespaceArg, typeNameArg, derivationMethod):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """        
+
+class IUserDataHandler(Interface):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+    # introduced in DOM Level 3
+
+    #
+    # Definition group OperationType
+    #
+
+    NODE_CLONED                    = Int()
+    NODE_IMPORTED                  = Int()
+    NODE_DELETED                   = Int()
+    NODE_RENAMED                   = Int()
+    NODE_ADOPTED                   = Int()
+  
+    #
+    # Methods
+    #
+
+    def handle(operations, key, data, src, dst):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+class IDOMErrorHandler(Interface):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+    # introduced in DOM Level 3
+
+    def handleError(error):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+class IDOMError(Interface):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+
+    SEVERITY_WARNING               = Int()
+    SEVERITY_ERROR                 = Int()
+    SEVERITY_FATAL_ERROR           = Int()
+
+    severity = Int(
+        title=u"Severity",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    message = Text(
+        title=u"Message",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    type = TextLine(
+        title=u"Type",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    relatedException = Field(
+        title=u"Related exception",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    relatedData = Field(
+        title=u"Related data",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    location = Field(
+        title=u"Location",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+class IDOMLocator(Interface):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+    # introduced in DOM Level 3
+
+    columnNumber = Int(
+        title=u"Column number",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    lineNumber = Int(
+        title=u"Line number",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    byteOffset = Int(
+        title=u"Byte offset",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    utf16Offset = Int(
+        title=u"UTF160 offset",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )        
+
+    relatedNode = Field(
+        title=u"Related node",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    uri = URI(
+        title=u"URI",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+class IDOMConfiguration(Interface):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+    # introduced in DOM Level 3
+
+    parameterNames = List(
+        title=u"Parameter names",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True,
+        value_type=TextLine()
+        )
+
+    def canSetParameter(name, value):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def getParemeter(name):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """
+
+    def setParameter(name, value):
+        """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+        """

Added: z3/zopexml/trunk/interfaces/dom/loadsave.py
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/interfaces/dom/loadsave.py	Wed Jun 16 16:54:15 2004
@@ -0,0 +1,303 @@
+##############################################################################
+#
+# Copyright (c) 2003 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+DOM interfaces for the DOM Level 3 'Load and Save' feature
+
+See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html for more
+detailled information
+
+$Id: loadsave.py,v 1.1 2004/02/09 00:49:31 philikon Exp $
+"""
+
+from zope.interface import Interface, Attribute
+from zope.schema import Int, Bool, Text, TextLine, URI
+
+from traversal import INodeFilter
+
+class LSException(Exception):
+    """See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html
+    """
+
+class IDOMImplementationLS(Interface):
+    """See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html
+    """
+
+    #
+    # Definition Group DOMImplementationLSMode
+    #
+
+    MODE_ASYNCHRONOUS = Int()
+    MODE_SYNCHRONOUS  = Int()
+
+    #
+    # Methods
+    #
+
+    def createDOMInput():
+        """
+        See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html
+        """
+
+    def createDOMParser(mode, schemaType):
+        """
+        See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html
+        """
+
+    def createDOMSerializer():
+        """
+        See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html
+        """
+
+class ILSParser(Interface):
+    """See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html
+    """
+
+    #
+    # Definition Group ACTION_TYPES
+    #
+
+    ACTION_APPEND_AS_CHILDREN = Int()
+    ACTION_INSERT_AFTER       = Int()
+    ACTION_INSERT_BEFORE      = Int()
+    ACTION_REPLACE            = Int()
+    ACTION_REPLACE_CHILDREN   = Int()
+
+    #
+    # Attributes
+    #
+
+    async = Bool(
+        title=u"Asynchronous",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html"
+        )
+
+    busy = Bool(
+        title=u"Busy",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html"
+        )
+
+    config = Attribute(
+        "See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html"
+        )
+
+    filter = Attribute(
+        "See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html"
+        )
+
+    #
+    # Methods
+    #
+
+    def abort():
+        """See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html
+        """
+
+    def parse(input):
+        """See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html
+        """
+
+    def parseURI(uri):
+        """See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html
+        """
+
+    def parseWithContext(input, context, action):
+        """See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html
+        """
+
+class ILSInput(Interface):
+    """See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html
+    """
+
+    baseURI = URI(
+        title=u"Base URI",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html"
+        )
+
+    byteStream = Attribute(
+        "See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html"
+        )
+
+    certifiedText = Bool(
+        title=u"Certified text",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html"
+        )
+
+    # The spec says "Depending on the language binding in use, this
+    # attribute may not be available."
+    characterStream = Attribute(
+        "See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html"
+        )
+
+    encoding = TextLine(
+        title=u"Encoding",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html"
+        )
+
+    publicId = TextLine(
+        title=u"Public identifier",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html"
+        )
+
+    stringData = Text(
+        title=u"String data",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html"
+        )
+
+    systemId = TextLine(
+        title=u"System identifier",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html"
+        )
+
+class ILSResourceResolver(Interface):
+    """See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html
+    """
+
+    def resolveResource(type, namespaceURI, publicId, systemId, baseURI):
+        """See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html
+        """
+
+class IDOMParserFilter(Interface):
+    """See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html
+    """
+
+    #
+    # Definition group Constants returned by startElement and acceptNode
+    #
+
+    FILTER_ACCEPT    = Int()
+    FILTER_INTERRUPT = Int()
+    FILTER_REJECT    = Int()
+    FILTER_SKIP      = Int()
+
+    #
+    # Attributes
+    #
+
+    whatToShow = Int(
+        title=u"What to show",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html",
+        readonly=True
+        )
+
+    #
+    # Methods
+    #
+
+    def acceptNode(nodeArg):
+        """See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html
+        """
+
+    def startElement(elementArg):
+        """See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html
+        """
+
+class ILSProgressEvent(Interface):
+    """See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html
+    """
+
+    input = Attribute(
+        "See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html"
+        )
+
+    position = Int(
+        title=u"Position",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html"
+        )
+
+    totalSize = Int(
+        title=u"Total size",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html"
+        )
+
+class ILSLoadEvent(Interface):
+    """See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html
+    """
+
+    input = Attribute(
+        "See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html"
+        )
+
+    newDocument = Attribute(
+        "See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html"
+        )
+
+class ILSSerializer(Interface):
+    """See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html
+    """
+
+    #
+    # Attributes
+    #
+
+    domConfig = Attribute(
+        "See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html"
+        )
+
+    filter = Attribute(
+        "See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html"
+        )
+
+    newLine = Text(
+        title=u"New line",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html"
+        )
+
+    #
+    # Methods
+    #
+
+    def write(nodeArg, destination):
+        """See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html
+        """
+
+    def writeToString(nodeArg):
+        """See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html
+        """
+
+    def writeURI(nodeArg, URI):
+        """See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html
+        """
+
+class ILSOutput(Interface):
+    """See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html
+    """
+
+    byteStream = Attribute(
+        "See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html"
+        )
+
+    # The spec says "Depending on the language binding in use, this
+    # attribute may not be available."
+    characterStream = Attribute(
+        "See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html"
+        )
+
+    encoding = TextLine(
+        title=u"Enconding",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html"
+        )
+
+    systemId = TextLine(
+        title=u"System identifier",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html"
+        )
+
+class ILSSerializerFilter(INodeFilter):
+    """See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html
+    """
+
+    whatToShow = Int(
+        title=u"What to show",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-LS/load-save.html"
+        )

Added: z3/zopexml/trunk/interfaces/dom/printer.py
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/interfaces/dom/printer.py	Wed Jun 16 16:54:15 2004
@@ -0,0 +1,30 @@
+##############################################################################
+#
+# Copyright (c) 2003 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+DOM XML printer
+
+$Id: printer.py,v 1.1 2004/02/09 00:49:31 philikon Exp $
+"""
+
+from zope.interface import Interface
+
+class IPrinter(Interface):
+    """DOM printer interface
+    """
+
+    def render(stream, node):
+        """
+        Render a node (and all of its child nodes) to file-handle like
+        object stream.
+        """

Added: z3/zopexml/trunk/interfaces/dom/traversal.py
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/interfaces/dom/traversal.py	Wed Jun 16 16:54:15 2004
@@ -0,0 +1,161 @@
+##############################################################################
+#
+# Copyright (c) 2003 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+DOM interfaces for the DOM Level 2 Traversal feature
+
+See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html for more
+detailled information
+
+$Id: traversal.py,v 1.1 2004/02/09 00:49:31 philikon Exp $
+"""
+
+from zope.interface import Interface
+from zope.schema import Field, Int, Bool
+
+class ICommonAttributes(Interface):
+
+    expandEntityReferences = Bool(
+        title=u"Expand entity references",
+        description=u"See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html",
+        readonly=True
+        )
+
+    filter = Field(
+        title=u"Filter",
+        description=u"See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html",
+        readonly=True
+        )
+
+    root = Field(
+        title=u"Root",
+        description=u"See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html",
+        readonly=True
+        )
+
+    whatToShow = Int(
+        title=u"What to show",
+        description=u"See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html",
+        readonly=True
+        )
+
+class INodeIterator(ICommonAttributes):
+    """See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html
+    """
+
+    def detach():
+        """See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html
+        """
+
+    def nextNode():
+        """See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html
+        """
+
+    def previousNode():
+        """See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html
+        """
+
+class INodeFilter(Interface):
+    """See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html
+    """
+
+    #
+    # Definition group Constants returned by acceptNode
+    #
+
+    FILTER_ACCEPT = Int()
+    FILTER_REJECT = Int()
+    FILTER_SKIP   = Int()
+
+    #
+    # Definition group Constants for whatToShow
+    #
+
+    SHOW_ALL                       = Int()
+    SHOW_ELEMENT                   = Int()
+    SHOW_ATTRIBUTE                 = Int()
+    SHOW_TEXT                      = Int()
+    SHOW_CDATA_SECTION             = Int()
+    SHOW_ENTITY_REFERENCE          = Int()
+    SHOW_ENTITY                    = Int()
+    SHOW_PROCESSING_INSTRUCTION    = Int()
+    SHOW_COMMENT                   = Int()
+    SHOW_DOCUMENT                  = Int()
+    SHOW_DOCUMENT_TYPE             = Int()
+    SHOW_DOCUMENT_FRAGMENT         = Int()
+    SHOW_NOTATION                  = Int()
+  
+    #
+    # Methods
+    #
+
+    def acceptNode(n):
+        """See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html
+        """
+
+class ITreeWalker(ICommonAttributes):
+    """See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html
+    """
+
+    #
+    # Attributes
+    #
+
+    currentNode = Field(
+        title=u"Current node",
+        description=u"See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html"
+        )
+
+    #
+    # Methods
+    #
+
+    def firstChild():
+        """See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html
+        """
+
+    def lastChild():
+        """See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html
+        """
+
+    def nextNode():
+        """See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html
+        """
+
+    def nextSibling():
+        """See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html
+        """
+
+    def parentNode():
+        """See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html
+        """
+
+    def previousNode():
+        """See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html
+        """
+
+    def previousSibling():
+        """See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html
+        """
+
+class IDocumentTraversal(Interface):
+    """See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html
+    """
+
+    def createNodeIterator(root, whatToShow, filter, entityReferenceExpansion):
+        """See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html
+        """
+
+    def createTreeWalker(root, whatToShow, filter, entityReferenceExpansion):
+        """See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html
+        """

Added: z3/zopexml/trunk/interfaces/dom/xmlextended.py
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/interfaces/dom/xmlextended.py	Wed Jun 16 16:54:15 2004
@@ -0,0 +1,119 @@
+##############################################################################
+#
+# Copyright (c) 2003 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+DOM XML extended interfaces
+
+See the W3C DOM Level 3 specification for detailled documentation:
+http://www.w3.org/TR/DOM-Level-3-Core/core.html
+
+$Id: xmlextended.py,v 1.1 2004/02/09 00:49:31 philikon Exp $
+"""
+
+from zope.schema import Field, Text, TextLine
+from core import INode, IText
+
+class ICDATASection(IText):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+
+class INotation(INode):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+
+    publicId = TextLine(
+        title=u"Public identifier",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    systemId = TextLine(
+        title=u"System identifier",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+class IDocumentType(INode):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+
+    entities = Field(
+        title=u"Entities",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    internalSubset = Text(
+        title=u"Internal subset",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    name = TextLine(
+        title=u"Name",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    notations = Field(
+        title=u"Notations",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+class IEntity(INotation):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+
+    inputEncoding = TextLine(
+        title=u"Input encoding",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    notationName = TextLine(
+        title=u"Notation name",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    xmlEncoding = TextLine(
+        title=u"XML encoding",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+    xmlVersion = TextLine(
+        title=u"XML version",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )
+
+class IEntityReference(INode):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+
+class IProcessingInstruction(INode):
+    """See http://www.w3.org/TR/DOM-Level-3-Core/core.html
+    """
+
+    data = Text(
+        title=u"Data",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html"
+        )
+
+    target = Text(
+        title=u"Target",
+        description=u"See http://www.w3.org/TR/DOM-Level-3-Core/core.html",
+        readonly=True
+        )

Added: z3/zopexml/trunk/interfaces/field.py
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/interfaces/field.py	Wed Jun 16 16:54:15 2004
@@ -0,0 +1,28 @@
+##############################################################################
+#
+# Copyright (c) 2002, 2003 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+Revision information:
+$Id: field.py,v 1.1.1.1 2003/12/06 15:02:19 faassen Exp $
+"""
+from zope.schema.interfaces import IBytes
+from zope.schema import Bool
+
+class IXML(IBytes):
+    """A field that can store XML text.
+    """
+
+    check_wellformedness = Bool(
+        title=u"Check for wellformedness",
+        default=True)

Added: z3/zopexml/trunk/interfaces/source.py
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/interfaces/source.py	Wed Jun 16 16:54:15 2004
@@ -0,0 +1,37 @@
+##############################################################################
+#
+# Copyright (c) 2003 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+$Id: source.py,v 1.2 2003/12/07 11:44:40 faassen Exp $
+"""
+
+from zope.interface import Interface, Attribute
+
+class IXMLSource(Interface):
+    """
+    This object can be adapted to one form of XML data representation
+    """
+
+class IXMLText(IXMLSource):
+    """
+    This object represents XML data as text.
+    """
+
+    source = Attribute("XML text")
+
+class IXMLElementTree(IXMLSource):
+    """
+    Represent XML data as an ElementTree (and as XML text).
+    """
+    tree = Attribute("Element Tree")
+    

Added: z3/zopexml/trunk/interfaces/statistics.py
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/interfaces/statistics.py	Wed Jun 16 16:54:15 2004
@@ -0,0 +1,34 @@
+from zope.interface import Interface
+
+class IStatistics(Interface):
+    def getElementCount(name):
+        """Get amount of elements for certain (uri, name).
+        """
+
+    def getElementCountMap():
+        """Get a dictionary mapping element name to amount.
+        """
+
+    def getElements():
+        """Get amount of distinct elements.
+        """
+
+    def getAttributeCount(name):
+        """Get amount of attributes for certain (uri, name).
+        """
+
+    def getAttributeCountMap():
+        """Get a dictionary mapping attribute to amount.
+        """
+
+    def getMaxDepth():
+        """Get maximum depth of tree.
+        """
+
+    def getMaxChildren():
+        """Get the maximum amount of children of a node.
+        """
+
+    def getCharacterCount():
+        """Get the amount of characters in the document.
+        """

Added: z3/zopexml/trunk/interfaces/xmldocument.py
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/interfaces/xmldocument.py	Wed Jun 16 16:54:15 2004
@@ -0,0 +1,34 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+$Id: xmldocument.py,v 1.2 2003/12/07 11:44:40 faassen Exp $
+"""
+from zopexml.field import XML
+from zopexml.interfaces.source import IXMLText, IXMLElementTree
+from zope.app.i18n import ZopeMessageIDFactory as _
+
+class IXMLDocument(IXMLText):
+    """XMLDocument stores XML text."""
+
+    source = XML(
+        title=_(u"Source"),
+        description=_(u"The text source of the XML document."),
+        required=True)
+
+class IElementTreeDocument(IXMLElementTree):
+    
+    source = XML(
+        title=_(u"Source"),
+        description=_(u"The text source of the XML document."),
+        required=True)

Added: z3/zopexml/trunk/statistics.pt
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/statistics.pt	Wed Jun 16 16:54:15 2004
@@ -0,0 +1,16 @@
+<html metal:use-macro="views/standard_macros/page">
+<body>
+  <div metal:fill-slot="body">
+    <h2 i18n:translate="">XML statistics</h2>
+    <p>
+      <span i18n:translate="">Maximum depth:</span>
+      <span tal:content="view/max_depth"></span>
+    </p>
+    <p>
+      <span i18n:translate="">Maximum children:</span>
+      <span tal:content="view/max_children"></span>
+    </p>
+  </div>
+</body>
+</html>
+

Added: z3/zopexml/trunk/statistics.py
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/statistics.py	Wed Jun 16 16:54:15 2004
@@ -0,0 +1,73 @@
+import xml.sax
+from StringIO import StringIO
+
+class StatisticsHandler(xml.sax.handler.ContentHandler):
+    """Gathers some boring statistics on an XML document.
+    """
+    def __init__(self):
+        self._element_count = {}
+        self._attribute_count = {}
+        self._max_depth = 0
+        self._max_children = 0
+        self._stack = [0]
+        self._character_count = 0
+
+    def getElementCount(self, name):
+        return self._element_count.get(name, 0)
+
+    def getElementCountMap(self):
+        return self._element_count
+    
+    def getElements(self):
+        return self._element_count.keys()
+
+    def getAttributeCount(self, name):
+        return self._attribute_count.get(name, 0)
+
+    def getAttributeCountMap(self):
+        return self._attribute_count
+    
+    def getAttributes(self):
+        return self._attribute_count.keys()
+
+    def getMaxDepth(self):
+        return self._max_depth - 1
+
+    def getMaxChildren(self):
+        return self._max_children
+
+    def getCharacterCount(self):
+        return self._character_count
+    
+    def startElementNS(self, name, qname, attrs):
+        self._stack[-1] += 1
+        if self._stack[-1] > self._max_children:
+            self._max_children = self._stack[-1]
+        self._stack.append(0)
+        if len(self._stack) > self._max_depth:
+            self._max_depth = len(self._stack)
+        count = self._element_count.get(name, 0)
+        count += 1
+        self._element_count[name] = count
+        for name, value in attrs.items():
+            count = self._attribute_count.get(name, 0)
+            count += 1
+            self._attribute_count[name] = count
+    
+    def endElementNS(self, name, qname):
+        self._stack.pop()
+
+    def characters(self, content):
+        self._character_count += len(content)
+    
+def parseFile(f):
+    parser = xml.sax.make_parser()
+    parser.setFeature(xml.sax.handler.feature_namespaces, True)
+    handler = StatisticsHandler()
+    parser.setContentHandler(handler)
+    parser.parse(f)
+    return handler
+
+def parse(s):
+    f = StringIO(s)
+    return parseFile(f)

Added: z3/zopexml/trunk/tests/__init__.py
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/tests/__init__.py	Wed Jun 16 16:54:15 2004
@@ -0,0 +1 @@
+# this is a package

Added: z3/zopexml/trunk/tests/test_field.py
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/tests/test_field.py	Wed Jun 16 16:54:15 2004
@@ -0,0 +1,57 @@
+##############################################################################
+#
+# Copyright (c) 2003 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+$Id: test_field.py,v 1.1.1.1 2003/12/06 15:02:19 faassen Exp $
+"""
+import unittest
+from zopexml.field import XML, NotWellFormedXML
+from zope.schema.tests.test_field import FieldTestBase
+from zope.schema import errornames
+
+class XMLFieldTestCase(FieldTestBase):
+
+    _Field_Factory = XML
+    
+    def testValidate(self):
+        field = XML(title=u"XML field", description=u'',
+                    readonly=False, required=False)
+        field.validate('<doc/>')
+        field.validate('<?xml version="1.0" ?><doc />')
+
+        self.assertRaisesErrorNames(NotWellFormedXML, field.validate, 'foo')
+        self.assertRaisesErrorNames(NotWellFormedXML, field.validate, '<doc>')
+        self.assertRaisesErrorNames(NotWellFormedXML, field.validate,
+                                    '<p></foo></p><foo>')
+        # shouldn't accept this, as XML by default is encoded as UTF-8
+        self.assertRaisesErrorNames(errornames.WrongType, field.validate,
+                                    u'<doc></doc>')
+        
+    def testValidateRequired(self):
+        field = XML(title=u"XML field", description=u'',
+                    readonly=False, required=True)
+        self.assertRaisesErrorNames(errornames.RequiredMissing,
+                                    field.validate, None)
+
+    def testTurnOffWellformedness(self):
+        field = XML(title=u"XML field")
+        field.check_wellformedness = False
+        field.validate('bad')
+        field.check_wellformedness = True
+        self.assertRaisesErrorNames(NotWellFormedXML, field.validate, 'bad')
+        
+        
+def test_suite():
+    return unittest.TestSuite([
+        unittest.makeSuite(XMLFieldTestCase)
+        ])

Added: z3/zopexml/trunk/tests/test_statistics.py
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/tests/test_statistics.py	Wed Jun 16 16:54:15 2004
@@ -0,0 +1,66 @@
+import unittest
+from zopexml import statistics
+
+class TestXMLStat(unittest.TestCase):
+    def test_characters(self):
+        xml = '<a>1234<b>5678</b><b>9012345678</b></a>'
+        stats = statistics.parse(xml)
+        self.assertEquals(18, stats.getCharacterCount())
+        self.assertEquals(1, stats.getElementCount((None, 'a')))
+        self.assertEquals(2, stats.getElementCount((None, 'b')))
+
+    def test_elements(self):
+        xml = '<a><b /><b /><c /><b /><c><d/></c></a>'
+        stats = statistics.parse(xml)
+        self.assertEquals(0, stats.getCharacterCount())
+        self.assertEquals(1, stats.getElementCount((None, 'a')))
+        self.assertEquals(3, stats.getElementCount((None, 'b')))
+        self.assertEquals(2, stats.getElementCount((None, 'c')))
+        self.assertEquals(1, stats.getElementCount((None, 'd')))
+        # other elements don't exist
+        self.assertEquals(0, stats.getElementCount((None, 'e')))
+        # list
+        l = stats.getElements()
+        l.sort()
+        self.assertEquals(
+            [(None, 'a'), (None, 'b'), (None, 'c'), (None, 'd')],
+            l)
+        
+    def test_attributes(self):
+        xml = '<a foo="Foo" bar="Bar"><b foo="Foo" /></a>'
+        stats = statistics.parse(xml)
+        self.assertEquals(2, stats.getAttributeCount((None, 'foo')))
+        self.assertEquals(1, stats.getAttributeCount((None, 'bar')))
+        # nonexistent
+        self.assertEquals(0, stats.getAttributeCount((None, 'baz')))
+        # list
+        l = stats.getAttributes()
+        l.sort()
+        self.assertEquals(
+            [(None, 'bar'), (None, 'foo')],
+            l)
+
+    def test_depth(self):
+        xml = '<a><b><c><d/></c></b><b><c/></b></a>'
+        stats = statistics.parse(xml)
+        self.assertEquals(4, stats.getMaxDepth())
+        xml = '<a></a>'
+        stats = statistics.parse(xml)
+        self.assertEquals(1, stats.getMaxDepth())
+
+    def test_children(self):
+        xml = '<a/>'
+        stats = statistics.parse(xml)
+        self.assertEquals(1, stats.getMaxChildren())
+        xml = '<a><b/><b/></a>'
+        stats = statistics.parse(xml)
+        self.assertEquals(2, stats.getMaxChildren())
+        xml = '<a><b><c/><c/></b><b><c/></b><b><c/><c/></b><b><d><c/><c/><c/><c/><c/><c/></d></b><b><c/></b></a>'
+        stats = statistics.parse(xml)
+        self.assertEquals(6, stats.getMaxChildren())
+        
+def test_suite():
+    return unittest.TestSuite((
+        unittest.makeSuite(TestXMLStat),
+        ))
+

Added: z3/zopexml/trunk/tests/test_xmldocument.py
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/tests/test_xmldocument.py	Wed Jun 16 16:54:15 2004
@@ -0,0 +1,51 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+Basic tests for XML Document.
+
+$Id: test_xmldocument.py,v 1.3 2003/12/07 11:44:40 faassen Exp $
+"""
+
+import unittest
+from zopexml.xmldocument import XMLDocument
+
+class XMLDocumentTests(unittest.TestCase):
+
+    def factory(self, *args, **kw):
+        return XMLDocument(*args, **kw)
+
+    # XXX
+    # a bit annoying is that ElementTree serializes <doc/> as <doc />
+    # this means that the test XML needs to conform to this, as the
+    # elementtree tests derive from this.
+    # <doc/> and <doc /> are of course equivalent in the XML infoset,
+    # so this isn't a big deal.
+    
+    def test_create(self):
+        doc = self.factory()
+        self.assertEquals('<doc />', doc.source)
+
+        doc = self.factory('<mydoc />')
+        self.assertEquals('<mydoc />', doc.source)
+
+    def test_set(self):
+        src = '<mydoc />'
+        doc = self.factory(src)
+        self.assertEqual(src, doc.source)
+        new_src = '<newdoc />'
+        doc.source = new_src
+        self.assertEqual(new_src, doc.source)
+
+def test_suite():
+    return unittest.makeSuite(XMLDocumentTests)

Added: z3/zopexml/trunk/xmldocument.py
==============================================================================
--- (empty file)
+++ z3/zopexml/trunk/xmldocument.py	Wed Jun 16 16:54:15 2004
@@ -0,0 +1,57 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+$Id: xmldocument.py,v 1.3 2004/01/16 13:41:53 philikon Exp $
+"""
+from persistence import Persistent
+
+from zope.interface import implements
+from zope.fssync.server.entryadapter import ObjectEntryAdapter
+from zope.fssync.server.interfaces import IObjectFile
+
+from zopexml.interfaces.xmldocument import IXMLDocument
+
+class XMLDocument(Persistent):
+    """A very simple document object that can store XML text.
+    """
+    implements(IXMLDocument)
+    
+    def __init__(self, source='<doc />'):
+        self.source = source
+
+    # XXX property is not necessary at this point -- used to be useful
+    # when we were checking for schema assignments but we're not doing
+    # that at the moment
+    def _setSource(self, value):
+        self._source = value
+        # check for schema assignments
+        
+    def _getSource(self):
+        return self._source
+
+    source = property(_getSource, _setSource)
+        
+class XMLDocumentAdapter(ObjectEntryAdapter):
+    """Adapter to make XML documents work as a file.
+    """
+    implements(IObjectFile)
+
+    def getBody(self):
+        return self.context.source
+
+    def setBody(self, data):
+        self.context.source = data
+
+    def extra(self):
+        return None


More information about the z3-checkins mailing list