Esempio n. 1
0
def generate_etd_ms_xml(etd_ms_dict):
    """Generate an ETD MS XML string."""
    return pydict2xmlstring(
        etd_ms_dict,
        ordering=ETD_MS_ORDER,
        root_label='thesis',
        namespace_map=ETD_MS_NAMESPACES,
    )
Esempio n. 2
0
def generate_dc_xml(dc_dict):
    """Generate a DC XML string."""
    # Define the root namespace.
    root_namespace = '{%s}' % DC_NAMESPACES['oai_dc']
    # Set the elements namespace URL.
    elements_namespace = '{%s}' % DC_NAMESPACES['dc']
    schema_location = ('http://www.openarchives.org/OAI/2.0/oai_dc/ '
                       'http://www.openarchives.org/OAI/2.0/oai_dc.xsd')
    root_attributes = {
        '{%s}schemaLocation' % XSI: schema_location,
    }
    # Return the DC XML string.
    return pydict2xmlstring(
        dc_dict,
        ordering=DC_ORDER,
        root_label='dc',
        root_namespace=root_namespace,
        elements_namespace=elements_namespace,
        namespace_map=DC_NAMESPACES,
        root_attributes=root_attributes,
    )
Esempio n. 3
0
def generate_dc_xml(dc_dict):
    """Generate a DC XML string."""
    # Define the root namespace.
    root_namespace = '{%s}' % DC_NAMESPACES['oai_dc']
    # Set the elements namespace URL.
    elements_namespace = '{%s}' % DC_NAMESPACES['dc']
    schema_location = ('http://www.openarchives.org/OAI/2.0/oai_dc/ '
                       'http://www.openarchives.org/OAI/2.0/oai_dc.xsd')
    root_attributes = {
        '{%s}schemaLocation' % XSI: schema_location,
    }
    # Return the DC XML string.
    return pydict2xmlstring(
        dc_dict,
        ordering=DC_ORDER,
        root_label='dc',
        root_namespace=root_namespace,
        elements_namespace=elements_namespace,
        namespace_map=DC_NAMESPACES,
        root_attributes=root_attributes,
    )
Esempio n. 4
0
def test_pydict2xmlstring_no_root_namespace_no_nsmap():
    metadata_dict = {
        'title': [{
            'qualifier': 'serialtitle',
            'content': 'A Title'
        }],
        'creator': [{
            'qualifier': 'aut',
            'content': {
                'name': 'Noway, José'
            }
        }]
    }
    xml = mg.pydict2xmlstring(metadata_dict)
    assert xml.decode('utf-8') == (
        '<?xml version="1.0" encoding="UTF-8"?>\n'
        '<metadata>\n'
        '  <title qualifier="serialtitle">A Title</title>\n'
        '  <creator qualifier="aut">\n'
        '    <name>Noway, José</name>\n'
        '  </creator>\n'
        '</metadata>\n')
Esempio n. 5
0
def test_pydict2xmlstring_root_namespace_attributes_nsmap():
    metadata_dict = {
        'title': [{
            'qualifier': 'officialtitle',
            'content': 'A Dissertation'
        }],
        'degree': [{
            'content': {
                'grantor': 'UNT'
            }
        }],
        'contributor': [{
            'role': 'chair',
            'content': 'Case, J.'
        }],
        'subject': [{
            'scheme': 'LC',
            'content': 'dog'
        }]
    }
    xml = mg.pydict2xmlstring(
        metadata_dict,
        root_attributes={'schemaLocation': 'http://example.org/schema'},
        root_namespace='{http://purl.org/dc/elements/1.1/}',
        namespace_map={'dc': 'http://purl.org/dc/elements/1.1/'})
    assert xml.decode('utf-8') == (
        '<?xml version="1.0" encoding="UTF-8"?>\n'
        '<dc:metadata xmlns:dc="http://purl.org/dc/elements/1.1/"'
        ' schemaLocation="http://example.org/schema">\n'
        '  <title qualifier="officialtitle">A Dissertation</title>\n'
        '  <contributor role="chair">Case, J.</contributor>\n'
        '  <subject scheme="LC">dog</subject>\n'
        '  <degree>\n'
        '    <grantor>UNT</grantor>\n'
        '  </degree>\n'
        '</dc:metadata>\n')
Esempio n. 6
0
 def testCircularEquality(self):
     self.assertEqual(
         py2dict(untlxml2py(BytesIO(
                 pydict2xmlstring(UNTL_DICT)))), UNTL_DICT)
Esempio n. 7
0
 def testCircularEquality(self):
     self.assertEqual(
         py2dict(untlxml2py(StringIO.StringIO(
                 pydict2xmlstring(UNTL_DICT)))), UNTL_DICT)
Esempio n. 8
0
def untlpydict2xmlstring(untl_dict):
    """Create an XML string from a Python UNTL dictionary."""
    return pydict2xmlstring(untl_dict)
Esempio n. 9
0
def untlpydict2xmlstring(untl_dict):
    """Create an XML string from a Python UNTL dictionary."""
    return pydict2xmlstring(untl_dict)