The xcheck module contains classes for validating XML elements. It uses the ElementTree interface.
xcheck defines the structure of an XML-Data node, and validates XML-Data nodes.
This is the default XCheck object that can handle attributes and children. All other checkers are subclasses of XCheck.
Parameters: |
|
---|
Note
There is an interface for XCheck written in wxPython. It will be released in 2013. This will use the required and helpstr attributes
Deprecated since version The: check_children paramater will most likely be removed in future versions.
XCheck objects have the following properties:
Returns the name of the checker.
Returns true if there are children present in the validator
Returs true if the xcheck object expects attributes
XCheck objects have the following methods useful in creation:
- xcheck.add_child(children)¶
add a list of child objects to the expected children raises an error if any child object is not an instance of an XCheck class
If passing a list, unpack it:
>>>x = XCheck('test') >>>kids = [XCheck('a'), XCheck('b'), XCheck('c')] >>>x.addchildren(*kids)
- xcheck.add_children(children)¶
This is an alias for addchild. The same rules apply
- xcheck.add_attribute(attributes)¶
Adds expected attributes to the xcheck object.
If passing a list, unpack it.
- xcheck.is_att(tag)¶
returns True if the tag represents an attribute in the checker object
The following methods are useful when using the xcheck-derived objects.
- xcheck.to_dict(node)¶
Creates a dictionar representing the node
- xcheck.has_attribute(tag)¶
Returns True if one of the checker’s attributes matches ‘tag’.
- xcheck.has_child(tag)¶
Returns True if one of the checker’s children attributes matches ‘tag’.
- xcheck.get(tag)¶
Returns the attribute or child checker object
- xcheck.dict_key(tag)¶
Returns an XMLPath dotted with the attribute (if needed).
- xcheck.path_to(tag)¶
Returns an (XMLPath, attribute) tuple to the given tag.
- xcheck.xpath_to(tag)¶
Returns a formatted xpath string.
The following methods allow an XCheck object to manipulate nodes.
- xcheck.insert_node(parent, child)¶
Takes a node and inserts a child node, based on the organiziational rules of the checker.
Parameters: child (parent,) – ElementTree.Elements to manipulate Warning
Only works on first-generation children of the checker!
- xcheck.sort_children(parent, child_name, sortkey[, reverse=False])¶
Sorts children of a node according to sortkey.
Parameters:
- xcheck.to_definition_node()¶
Creates an ElementTree.Element that represents the checker tree, not data that can be checked by the checker.
see load_checker() for more information on the definition node.
Calling an xcheck object validates whatever is passed to it:
Validates the data
Parameters: |
|
---|
Note
The normalize and as_string parameters do nothing with XCheck objects. They are useful for the subclasses.
Note
The verbose parameter will be relpaced in future, relying on the logging module.
XCheck classes are callable, and rely on two helper methods. For more information and examples, see Rolling your own.
- xcheck.check_content(item)¶
Checks the item against the checker’s rules (either an attribute value or node text) and returns a boolean value.
This method can also raise an error. Errors should be consistent with Python. See Errors for more information.
- xcheck.nomalize_content(item)¶
Uses the checker’s normalization rules without checking the validity of the item being normalized.