Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support default namespaces #44

Conversation

flibbertigibbet
Copy link

Allow definition of default namespaces on input XML document.
Handles namespace prefixes in document.

Closes #43.

Tested with the provided XSD by changing schema declaration to:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="https://github.com/google/election_results_xml_validator/blob/master/nist_1500_100_spec.xsd" targetNamespace="https://github.com/google/election_results_xml_validator/blob/master/nist_1500_100_spec.xsd" elementFormDefault="qualified" version="1.0">

and changed the ElectionReport opening tag in the XML file to validate to:

<ElectionReport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://github.com/google/election_results_xml_validator/blob/master/nist_1500_100_spec.xsd" xsi:schemaLocation="https://github.com/google/election_results_xml_validator/blob/master/nist_1500_100_spec.xsd">

XML continues to validate. Before, this would have failed with:

Traceback (most recent call last):
  File "/usr/local/bin/election_results_xml_validator", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/election_results_xml_validator/rules.py", line 783, in main
    found_errors = registry.check_rules()
  File "/usr/local/lib/python2.7/dist-packages/election_results_xml_validator/base.py", line 265, in check_rules
    self.register_rules(election_tree)
  File "/usr/local/lib/python2.7/dist-packages/election_results_xml_validator/base.py", line 186, in register_rules
    rule_instance = rule(election_tree, self.schema_file)
  File "/usr/local/lib/python2.7/dist-packages/election_results_xml_validator/rules.py", line 627, in __init__
    election_type_elem = election_elem.find("Type")
AttributeError: 'NoneType' object has no attribute 'find'

Allow definition of default namespaces on input XML document.
Handles namespace prefixes in document.

Closes google#43.
@jdmgoogle
Copy link
Contributor

Thank you for the example. I have two concerns about this change.

  1. Right now there's no long-term stable home for the specification itself. The NIST URL is a weird path based on the number of draft revisions the spec went through. The URL for this particular repository is not stable and we (Google) reserve the right to change it around.
  2. Your example seems to say "if I add this attribute to my XML, it fails validation under the current spec." Is that correct? If so, why is the solution to change the XSD and not "don't add that attribute to the XML"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support default namespaces
2 participants