Source

scatter-share / balisage09 / slide30.py

Full commit
from amara import bindery
from amara.bindery.model import *

LABEL_MODEL = '''<?xml version="1.0" encoding="utf-8"?>
<labels>
  <label>
    <name>[Addressee name]</name>
    <address>
      <street>[Address street info]</street>
      <city>[City]</city>
      <state>[State abbreviation]</state>
    </address>
  </label>
</labels>
'''

VALID_LABEL_XML = '''<?xml version="1.0" encoding="utf-8"?>
<labels>
  <label>
    <name>Thomas Eliot</name>
    <address>
      <street>3 Prufrock Lane</street>
      <city>Stamford</city>
      <state>CT</state>
    </address>
  </label>
</labels>
'''

#Construct a set of constraints and other model info from the example
label_model = examplotron_model(LABEL_MODEL)

#Now use this to validate an instant document VALID_LABEL_XML
doc = bindery.parse(VALID_LABEL_XML, model=label_model)
doc.xml_validate()