Validate presence of xml:id in section

In tools/validate.py, check for xml:id attributes.

While testing this, found a file that contained missing xml:id, that
was corrected.

See bug #1181659

Change-Id: I61f61c5f6de87bee8c7bc2eb9e3bfe23426a3adb
This commit is contained in:
Lorin Hochstein 2013-05-20 10:54:53 -04:00
parent a5c38ec386
commit 9a5a297b79
1 changed files with 15 additions and 0 deletions

View File

@ -44,6 +44,17 @@ def validation_failed(schema, doc):
any(log.type_name != "DTD_UNKNOWN_ID" for log in schema.error_log)
def verify_section_tags_have_xmid(doc):
"""Check that all section tags have an xml:id attribute
Will throw an exception if there's at least one missing"""
ns = {"docbook": "http://docbook.org/ns/docbook"}
for node in doc.xpath('//docbook:section', namespaces=ns):
if "{http://www.w3.org/XML/1998/namespace}id" not in node.attrib:
raise ValueError("section missing xml:id attribute, line %d" %
node.sourceline)
def error_message(error_log):
"""Return a string that contains the error message.
@ -78,9 +89,13 @@ def main(rootdir):
if validation_failed(schema, doc):
any_failures = True
print error_message(schema.error_log)
verify_section_tags_have_xmid(doc)
except etree.XMLSyntaxError as e:
any_failures = True
print "%s: %s" % (path, e)
except ValueError as e:
any_failures = True
print "%s: %s" % (path, e)
if any_failures:
sys.exit(1)