#NEWLINE# def set( self , path , child = False , attribute = False ) : #NEWLINE# #INDENT# ' Accepts a forward slash seperated path of XML elements to traverse and create if non existent.\n        Optional child and target node attributes can be set. If the `child` attribute is a tuple\n        it will create X child nodes by reading each tuple as (name, text, \'attribute:value\') where value\n        and attributes are optional for each tuple.\n\n        - path: forward slash seperated API element path as string (example: "Order/Authentication/Username")\n        - child: tuple of child node data or string to create a text node\n        - attribute: sets the target XML attributes (string format: "Key:Value")\n        ' #NEWLINE# try : #NEWLINE# #INDENT# xml_path = path . split ( '/' ) #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# xml_doc = self . doc #NEWLINE# for element_name in xml_path : #NEWLINE# #INDENT# element = self . doc . getElementsByTagName ( element_name ) #NEWLINE# if element : #NEWLINE# #INDENT# element = element [ 0 ] #NEWLINE# #UNINDENT# if ( ( not element ) or ( element_name == xml_path [ ( - 1 ) : ] [ 0 ] ) ) : #NEWLINE# #INDENT# element = self . doc . createElement ( element_name ) #NEWLINE# xml_doc . appendChild ( element ) #NEWLINE# #UNINDENT# xml_doc = element #NEWLINE# #UNINDENT# if child : #NEWLINE# #INDENT# if isinstance ( child , tuple ) : #NEWLINE# #INDENT# for obj in child : #NEWLINE# #INDENT# child = self . doc . createElement ( obj [ 0 ] ) #NEWLINE# if ( len ( obj ) >= 2 ) : #NEWLINE# #INDENT# element = self . doc . createTextNode ( str ( obj [ 1 ] ) ) #NEWLINE# child . appendChild ( element ) #NEWLINE# #UNINDENT# if ( len ( obj ) == 3 ) : #NEWLINE# #INDENT# a = obj [ 2 ] . split ( ':' ) #NEWLINE# child . setAttribute ( a [ 0 ] , a [ 1 ] ) #NEWLINE# #UNINDENT# xml_doc . appendChild ( child ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# element = self . doc . createTextNode ( str ( child ) ) #NEWLINE# xml_doc . appendChild ( element ) #NEWLINE# #UNINDENT# #UNINDENT# if attribute : #NEWLINE# #INDENT# if ( '|' in attribute ) : #NEWLINE# #INDENT# attributes = attribute . split ( '|' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# attributes = [ attribute ] #NEWLINE# #UNINDENT# for attribute in attributes : #NEWLINE# #INDENT# attribute = attribute . split ( ':' ) #NEWLINE# xml_doc . setAttribute ( attribute [ 0 ] , attribute [ 1 ] )