<s> import xml . dom . minidom as mod_minidom <EOL> def get_children_by_tag_name ( node , tag_name ) : <EOL> result = [ ] <EOL> for child in node . childNodes : <EOL> if child . nodeName == tag_name : <EOL> result . append ( child ) <EOL> return result <EOL> def get_indented ( indentation , string ) : <EOL> result = '<STR_LIT>' <EOL> for i in range ( indentation ) : <EOL> result += '<STR_LIT:U+0020>' <EOL> return result + str ( string ) + '<STR_LIT:\n>' <EOL> def parse_1_1 ( dom ) : <EOL> root_node = dom . childNodes [ <NUM_LIT:0> ] <EOL> complex_type_nodes = parse_1_1_find_complex_type ( root_node ) <EOL> gpx_element_nodes = parse_1_1_find_elements ( root_node ) <EOL> result = '<STR_LIT>' <EOL> for gpx_element_node in gpx_element_nodes : <EOL> result += parse_1_1_element_node ( gpx_element_node , complex_type_nodes ) <EOL> return result <EOL> def parse_1_1_element_node ( gpx_element_node , complex_type_nodes , depth = <NUM_LIT:0> ) : <EOL> result = '<STR_LIT>' <EOL> node_type = gpx_element_node . attributes [ '<STR_LIT:type>' ] . value <EOL> node_name = gpx_element_node . attributes [ '<STR_LIT:name>' ] . value <EOL> result += get_indented ( depth , '<STR_LIT>' % ( node_name , node_type ) ) <EOL> if node_type in complex_type_nodes : <EOL> attribute_nodes = get_children_by_tag_name ( complex_type_nodes [ node_type ] , '<STR_LIT>' ) <EOL> for attribute_node in attribute_nodes : <EOL> attribute_node_name = attribute_node . attributes [ '<STR_LIT:name>' ] . value <EOL> attribute_node_type = attribute_node . attributes [ '<STR_LIT:type>' ] . value <EOL> attribute_node_required = attribute_node . attributes [ '<STR_LIT>' ] . value if attribute_node . attributes . has_key ( '<STR_LIT>' ) else None <EOL> result += get_indented ( depth + <NUM_LIT:1> , '<STR_LIT>' % ( attribute_node_name , attribute_node_type , attribute_node_required ) ) <EOL> sequence_nodes = get_children_by_tag_name ( complex_type_nodes [ node_type ] , '<STR_LIT>' ) <EOL> if len ( sequence_nodes ) > <NUM_LIT:0> : <EOL> sequence_node = sequence_nodes [ <NUM_LIT:0> ] <EOL> for element_node in get_children_by_tag_name ( sequence_node , '<STR_LIT>' ) : <EOL> result += parse_1_1_element_node ( element_node , complex_type_nodes , depth = depth + <NUM_LIT:1> ) <EOL> return result <EOL> def parse_1_1_find_elements ( node ) : <EOL> result = [ ] <EOL> for node in node . childNodes : <EOL> if node . nodeName == '<STR_LIT>' : <EOL> result . append ( node ) <EOL> return result <EOL> def parse_1_1_find_complex_type ( root_node ) : <EOL> result = { } <EOL> for node in root_node . childNodes : <EOL> if node . nodeName == '<STR_LIT>' : <EOL> node_name = node . attributes [ '<STR_LIT:name>' ] . value <EOL> result [ node_name ] = node <EOL> return result <EOL> def parse_1_0 ( dom ) : <EOL> root_node = dom . getElementsByTagName ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> return parse_1_0_elements ( root_node ) <EOL> def parse_1_0_elements ( element , depth = <NUM_LIT:0> ) : <EOL> result = '<STR_LIT>' <EOL> result += get_indented ( depth , element . attributes [ '<STR_LIT:name>' ] . value ) <EOL> complex_types = get_children_by_tag_name ( element , '<STR_LIT>' ) <EOL> if len ( complex_types ) > <NUM_LIT:0> : <EOL> print ( complex_types ) <EOL> complex_type = complex_types [ <NUM_LIT:0> ] <EOL> for attribute_node in get_children_by_tag_name ( complex_type , '<STR_LIT>' ) : <EOL> attribute_node_name = attribute_node . attributes [ '<STR_LIT:name>' ] . value <EOL> attribute_node_type = attribute_node . attributes [ '<STR_LIT:type>' ] . value <EOL> attribute_node_use = attribute_node . attributes [ '<STR_LIT>' ] . value if attribute_node . attributes . has_key ( '<STR_LIT>' ) else None <EOL> result += get_indented ( depth + <NUM_LIT:1> , '<STR_LIT>' % ( attribute_node_name , attribute_node_type , attribute_node_use ) ) <EOL> sequences = get_children_by_tag_name ( complex_type , '<STR_LIT>' ) <EOL> if len ( sequences ) > <NUM_LIT:0> : <EOL> sequence = sequences [ <NUM_LIT:0> ] <EOL> for sub_element in get_children_by_tag_name ( sequence , '<STR_LIT>' ) : <EOL> result += parse_1_0_elements ( sub_element , depth = depth + <NUM_LIT:1> ) <EOL> return result <EOL> dom = mod_minidom . parseString ( open ( '<STR_LIT>' ) . read ( ) ) <EOL> prety_print_1_0 = parse_1_0 ( dom ) <EOL> with open ( '<STR_LIT>' , '<STR_LIT:w>' ) as f : <EOL> f . write ( prety_print_1_0 ) <EOL> print '<STR_LIT>' <EOL> dom = mod_minidom . parseString ( open ( '<STR_LIT>' ) . read ( ) ) <EOL> prety_print_1_1 = parse_1_1 ( dom ) <EOL> with open ( '<STR_LIT>' , '<STR_LIT:w>' ) as f : <EOL> f . write ( prety_print_1_1 ) <EOL> print '<STR_LIT>' </s>
