rng_file = get_abspath('OpenDocument-strict-schema-v1.1.rng') rng_file = ro_database.get_handler(rng_file, RelaxNGFile) namespaces = rng_file.get_namespaces() # Apply the metadata for uri, element_name in inline_elements: element = namespaces[uri].get_element_schema(element_name) element.is_inline = True for uri, element_name in skip_content_elements: element = namespaces[uri].get_element_schema(element_name) element.skip_content = True for uri, element_name in unknown_elements: elements = namespaces[uri].elements if element_name in elements: raise ValueError, 'element "%s" is defined twice' % element_name elements[element_name] = ElementSchema(element_name, default_datatype=String) for uri, element_name, context in contexts: element = namespaces[uri].get_element_schema(element_name) element.context = context # The namespaces fo and svg have two names fo_uri_2 = 'http://www.w3.org/1999/XSL/Format' duplicate_ns(namespaces, fo_uri, fo_uri_2) svg_uri_2 = 'http://www.w3.org/2000/svg' duplicate_ns(namespaces, svg_uri, svg_uri_2) # Register the namespaces for uri, namespace in namespaces.iteritems(): if not has_namespace(uri): register_namespace(namespace)
# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # Import from itools from itools.xml import XMLNamespace, register_namespace from itools.xml import ElementSchema xliff_elements = [ # Top Level and Header ElementSchema('xliff'), ElementSchema('file'), ElementSchema('header'), ElementSchema('skl'), ElementSchema('external-file'), ElementSchema('internal-file'), ElementSchema('glossary'), ElementSchema('reference'), ElementSchema('phase-group'), ElementSchema('phase'), ElementSchema('tool'), # 1.2 ElementSchema('note'), # Named Group ElementSchema('context-group'), ElementSchema('context'), ElementSchema('count-group'),
def make_namespaces(context): # Shortcuts elements = context['elements'] references = context['references'] # Find all namespaces, and fill them with elements namespaces = {} for element in elements: qnames = element['qnames'] attributes = element['attributes'] data = element['data'] is_empty = element['is_empty'] refs = element['refs'] # Replace the references of "refs" while refs: new_refs = [] for ref in refs: try: ref = references[ref] except KeyError: raise KeyError, ('the define "%s" is missing in your ' 'relax NG file') % ref attributes.extend(ref['attributes']) new_refs.extend(ref['refs']) is_empty = is_empty and ref['is_empty'] ref_data = ref['data'] if ref_data is not None: if data is not None and data != ref_data: data = '' elif data is None: data = ref_data refs = new_refs # Now, data is good if data is not None: is_empty = False # Replace the references of "attributes" for attribute in attributes: refs = attribute['refs'] while refs: new_refs = [] for ref in refs: try: ref = references[ref] except KeyError: raise KeyError, ('the define "%s" is missing in your ' 'relax NG file') % ref new_refs.extend(ref['refs']) ref_data = ref['data'] attr_data = attribute['data'] if ref_data is not None: if attr_data is not None and attr_data != ref_data: attr_data = '' elif attr_data is None: attr_data = ref_data refs = new_refs # Update the good namespaces if qnames is not None: for uri, name in element['qnames']: own, free = split_attributes(uri, attributes) # Element + its attributes namespace = namespaces.setdefault(uri, { 'elements': {}, 'free_attributes': {} }) element = ElementSchema(name, default_datatype=String, is_empty=is_empty, attributes=own) namespace['elements'][name] = element # Free attributes for (uri, name), datatype in free.iteritems(): namespace = namespaces.setdefault(uri, { 'elements': {}, 'free_attributes': {} }) namespace['free_attributes'][name] = datatype result = {} prefix2uri = context['prefix'] for namespace, data in namespaces.iteritems(): # Find the prefix for prefix, uri in prefix2uri.iteritems(): if uri == namespace: result[uri] = XMLNamespace(uri, prefix, data['elements'].values(), data['free_attributes'], String) break else: log_warning('relaxng: namespace "%s" not found' % namespace) return result
def __init__(self, name, attributes, **kw): # By default: context = name of element self.context = '%s' % name ElementSchema.__init__(self, name, **kw) self.attributes = frozenset(attributes)