def json_struct_to_xml(json_obj, root, custom_namespace=None):
if isinstance(root, (str, unicode)):<EOL><INDENT>if root.startswith('<STR_LIT:!>'):<EOL><INDENT>root = etree.Element('<STR_LIT>' % (NS_PROTECTED, root[<NUM_LIT:1>:]))<EOL><DEDENT>elif root.startswith('<STR_LIT:+>'):<EOL><INDENT>if not custom_namespace:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>root = etree.Element('<STR_LIT>' % (custom_namespace, root[<NUM_LIT:1>:]))<EOL><DEDENT>else:<EOL><INDENT>root = etree.Element(root)<EOL><DEDENT><DEDENT>if root.tag in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>for link in json_obj:<EOL><INDENT>root.append(json_link_to_xml(link))<EOL><DEDENT><DEDENT>elif isinstance(json_obj, (str, unicode)):<EOL><INDENT>root.text = json_obj<EOL><DEDENT>elif isinstance(json_obj, (int, float)):<EOL><INDENT>root.text = unicode(json_obj)<EOL><DEDENT>elif isinstance(json_obj, dict):<EOL><INDENT>if frozenset(json_obj.keys()) == frozenset(('<STR_LIT:type>', '<STR_LIT>')):<EOL><INDENT>root.append(geojson_to_gml(json_obj))<EOL><DEDENT>else:<EOL><INDENT>for key, val in json_obj.items():<EOL><INDENT>if key == '<STR_LIT:url>' or key.endswith('<STR_LIT>'):<EOL><INDENT>el = json_link_to_xml(val, json_link_key_to_xml_rel(key))<EOL><DEDENT>else:<EOL><INDENT>el = json_struct_to_xml(val, key, custom_namespace=custom_namespace)<EOL><DEDENT>if el is not None:<EOL><INDENT>root.append(el)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>elif isinstance(json_obj, list):<EOL><INDENT>tag_name = root.tag<EOL>if tag_name.endswith('<STR_LIT>'):<EOL><INDENT>tag_name = tag_name[:-<NUM_LIT:3>] + '<STR_LIT:y>'<EOL><DEDENT>elif tag_name.endswith('<STR_LIT:s>'):<EOL><INDENT>tag_name = tag_name[:-<NUM_LIT:1>]<EOL><DEDENT>for val in json_obj:<EOL><INDENT>el = json_struct_to_xml(val, tag_name, custom_namespace=custom_namespace)<EOL>if el is not None:<EOL><INDENT>root.append(el)<EOL><DEDENT><DEDENT><DEDENT>elif json_obj is None:<EOL><INDENT>return None<EOL><DEDENT>else:<EOL><INDENT>raise NotImplementedError<EOL><DEDENT>return root<EOL>
Converts a Open511 JSON fragment to XML.

    Takes a dict deserialized from JSON, returns an lxml Element.

    This won't provide a conforming document if you pass in a full JSON document;
    it's for translating little fragments, and is mostly used internally.