def process_data_element
      # FIXME: This method has grown a bit messy and isn't very pleasant to read. Cleanup possible?
      # After having been into a possible unknown sequence with undefined length, we may need to reset
      # explicitness from implicit to explicit:
      if !@original_explicit.nil? && @explicitness_reset_parent == @current_parent
        @explicit = @original_explicit
      end
      # STEP 1:
      # Attempt to read data element tag:
      tag = read_tag
      # Return nil if we have (naturally) reached the end of the data string.
      return nil unless tag
      # STEP 2:
      # Access library to retrieve the data element name and VR from the tag we just read:
      # (Note: VR will be overwritten in the next step if the DICOM string contains VR (explicit encoding))
      name, vr = LIBRARY.name_and_vr(tag)
      # STEP 3:
      # Read VR (if it exists) and the length value:
      vr, length = read_vr_length(vr,tag)
      level_vr = vr
      # STEP 4:
      # Reading value of data element.
      # Special handling needed for items in encapsulated image data:
      if @enc_image and tag == ITEM_TAG
        # The first item appearing after the image element is a 'normal' item, the rest hold image data.
        # Note that the first item will contain data if there are multiple images, and so must be read.
        vr = "OW" # how about alternatives like OB?
        # Modify name of item if this is an item that holds pixel data:
        if @current_element.tag != PIXEL_TAG
          name = PIXEL_ITEM_NAME
        end
      end
      # Read the binary string of the element:
      bin = read_bin(length) if length > 0
      # Read the value of the element (if it contains data, and it is not a sequence or ordinary item):
      if length > 0 and vr != "SQ" and tag != ITEM_TAG
        # Read the element's processed value:
        value = read_value(vr, length)
      else
        # Data element has no value (data).
        value = nil
        # Special case: Check if pixel data element is sequenced:
        if tag == PIXEL_TAG
          # Change name and vr of pixel data element if it does not contain data itself:
          name = ENCAPSULATED_PIXEL_NAME
          level_vr = "SQ"
          @enc_image = true
        end
      end
      # Create an Element from the gathered data:
      # if vr is UN ("unknown") and length is -1, treat as a sequence (sec. 6.2.2 of DICOM standard)
      if level_vr == "SQ" or tag == ITEM_TAG or (level_vr == "UN" and length == -1)
        if level_vr == "SQ" or (level_vr == "UN" and length == -1)
          check_duplicate(tag, 'Sequence')
          # If we get an unknown sequence with undefined length, we must switch to implicit for decoding its content:
          if level_vr == "UN" and length == -1
            @original_explicit = @explicit
            @explicit = false
            @explicitness_reset_parent = @current_parent
          end
          unless @current_parent[tag] and !@overwrite
            @current_element = Sequence.new(tag, :length => length, :name => name, :parent => @current_parent, :vr => vr)
          else
            # We have skipped a sequence. This means that any following children
            # of this sequence must be skipped as well. We solve this by creating an 'orphaned'
            # sequence that has a parent defined, but does not add itself to this parent:
            @current_element = Sequence.new(tag, :length => length, :name => name, :vr => vr)
            @current_element.set_parent(@current_parent)
          end
        elsif tag == ITEM_TAG
          # Create an Item:
          if @enc_image
            @current_element = Item.new(:bin => bin, :length => length, :name => name, :parent => @current_parent, :vr => vr)
          else
            @current_element = Item.new(:length => length, :name => name, :parent => @current_parent, :vr => vr)
          end
        end
        # Common operations on the two types of parent elements:
        if length == 0 and @enc_image
          # Set as parent. Exceptions when parent will not be set:
          # Item/Sequence has zero length & Item is a pixel item (which contains pixels, not child elements).
          @current_parent = @current_element
        elsif length != 0
          @current_parent = @current_element unless name == PIXEL_ITEM_NAME
        end
        # If length is specified (no delimitation items), load a new DRead instance to read these child elements
        # and load them into the current sequence. The exception is when we have a pixel data item.
        if length > 0 and not @enc_image
          @current_element.parse(bin, @transfer_syntax, switched=@switched, @explicit)
          @current_parent = @current_parent.parent
          return false unless @read_success
        end
      elsif DELIMITER_TAGS.include?(tag)
        # We do not create an element for the delimiter items.
        # The occurance of such a tag indicates that a sequence or item has ended, and the parent must be changed:
        @current_parent = @current_parent.parent
      else
        check_duplicate(tag, 'Element')
        unless @current_parent[tag] and !@overwrite
          @current_element = Element.new(tag, value, :bin => bin, :name => name, :parent => @current_parent, :vr => vr)
          # Check that the data stream didn't end abruptly:
          raise "The actual length of the value (#{@current_element.bin.length}) does not match its specified length (#{length}) for Data Element #{@current_element.tag}" if length != @current_element.bin.length
        end
      end
      # Return true to indicate success:
      return true
    end
def process_data_element
      # FIXME: This method has grown a bit messy and isn't very pleasant to read. Cleanup possible?
      # After having been into a possible unknown sequence with undefined length, we may need to reset
      # explicitness from implicit to explicit:
      if !@original_explicit.nil? && @explicitness_reset_parent == @current_parent
        @explicit = @original_explicit
      end
      # STEP 1:
      # Attempt to read data element tag:
      tag = read_tag
      # Return nil if we have (naturally) reached the end of the data string.
      return nil unless tag
      # STEP 2:
      # Access library to retrieve the data element name and VR from the tag we just read:
      # (Note: VR will be overwritten in the next step if the DICOM string contains VR (explicit encoding))
      name, vr = LIBRARY.name_and_vr(tag)
      # STEP 3:
      # Read VR (if it exists) and the length value:
      vr, length = read_vr_length(vr,tag)
      level_vr = vr
      # STEP 4:
      # Reading value of data element.
      # Special handling needed for items in encapsulated image data:
      if @enc_image and tag == ITEM_TAG
        # The first item appearing after the image element is a 'normal' item, the rest hold image data.
        # Note that the first item will contain data if there are multiple images, and so must be read.
        vr = "OW" # how about alternatives like OB?
        # Modify name of item if this is an item that holds pixel data:
        if @current_element.tag != PIXEL_TAG
          name = PIXEL_ITEM_NAME
        end
      end
      # Read the binary string of the element:
      bin = read_bin(length) if length > 0
      # Read the value of the element (if it contains data, and it is not a sequence or ordinary item):
      if length > 0 and vr != "SQ" and tag != ITEM_TAG
        # Read the element's processed value:
        value = read_value(vr, length)
      else
        # Data element has no value (data).
        value = nil
        # Special case: Check if pixel data element is sequenced:
        if tag == PIXEL_TAG
          # Change name and vr of pixel data element if it does not contain data itself:
          name = ENCAPSULATED_PIXEL_NAME
          level_vr = "SQ"
          @enc_image = true
        end
      end
      # Create an Element from the gathered data:
      # if vr is UN ("unknown") and length is -1, treat as a sequence (sec. 6.2.2 of DICOM standard)
      if level_vr == "SQ" or tag == ITEM_TAG or (level_vr == "UN" and length == -1)
        if level_vr == "SQ" or (level_vr == "UN" and length == -1)
          check_duplicate(tag, 'Sequence')
          # If we get an unknown sequence with undefined length, we must switch to implicit for decoding its content:
          if level_vr == "UN" and length == -1
            @original_explicit = @explicit
            @explicit = false
            @explicitness_reset_parent = @current_parent
          end
          unless @current_parent[tag] and !@overwrite
            @current_element = Sequence.new(tag, :length => length, :name => name, :parent => @current_parent, :vr => vr)
          else
            # We have skipped a sequence. This means that any following children
            # of this sequence must be skipped as well. We solve this by creating an 'orphaned'
            # sequence that has a parent defined, but does not add itself to this parent:
            @current_element = Sequence.new(tag, :length => length, :name => name, :vr => vr)
            @current_element.set_parent(@current_parent)
          end
        elsif tag == ITEM_TAG
          # Create an Item:
          if @enc_image
            @current_element = Item.new(:bin => bin, :length => length, :name => name, :parent => @current_parent, :vr => vr)
          else
            @current_element = Item.new(:length => length, :name => name, :parent => @current_parent, :vr => vr)
          end
        end
        # Common operations on the two types of parent elements:
        if length == 0 and @enc_image
          # Set as parent. Exceptions when parent will not be set:
          # Item/Sequence has zero length & Item is a pixel item (which contains pixels, not child elements).
          @current_parent = @current_element
        elsif length != 0
          @current_parent = @current_element unless name == PIXEL_ITEM_NAME
        end
        # If length is specified (no delimitation items), load a new DRead instance to read these child elements
        # and load them into the current sequence. The exception is when we have a pixel data item.
        if length > 0 and not @enc_image
          @current_element.parse(bin, @transfer_syntax, switched=@switched, @explicit)
          @current_parent = @current_parent.parent
          return false unless @read_success
        end
      elsif DELIMITER_TAGS.include?(tag)
        # We do not create an element for the delimiter items.
        # The occurance of such a tag indicates that a sequence or item has ended, and the parent must be changed:
        @current_parent = @current_parent.parent
      else
        check_duplicate(tag, 'Element')
        unless @current_parent[tag] and !@overwrite
          @current_element = Element.new(tag, value, :bin => bin, :name => name, :parent => @current_parent, :vr => vr)
          # Check that the data stream didn't end abruptly:
          raise "The actual length of the value (#{@current_element.bin.length}) does not match its specified length (#{length}) for Data Element #{@current_element.tag}" if length != @current_element.bin.length
        end
      end
      # Return true to indicate success:
      return true
    end
Handles the process of reading a data element from the DICOM string, and
 creating an element object from the parsed data.

 @return [Boolean] nil if end of string has been reached (in an expected way), false if the element parse failed, and true if an element was parsed successfully