/**
   * Populates the object from the XMLStreamReader
   *
   * @param xmlr the XMLStreamReader to read from
   * @throws XMLStreamException if there is an error parsing the stream
   * @throws ParseException if there is an error in parsing a date
   * @throws URISyntaxException if the uri is invalid
   */
  protected static BlobContainerAttributes readBlobContainerAttributes(final XMLStreamReader xmlr)
      throws XMLStreamException, ParseException, URISyntaxException {
    int eventType = xmlr.getEventType();

    final BlobContainerAttributes attributes = new BlobContainerAttributes();

    while (xmlr.hasNext()) {
      eventType = xmlr.next();
      final String name = xmlr.getName().toString();
      if (eventType == XMLStreamConstants.START_ELEMENT) {
        if (name.equals(BlobConstants.PROPERTIES)) {
          attributes.setProperties(BlobDeserializationHelper.readBlobContainerProperties(xmlr));
          xmlr.require(XMLStreamConstants.END_ELEMENT, null, BlobConstants.PROPERTIES);
        } else if (name.equals(Constants.URL_ELEMENT)) {
          attributes.setUri(new URI(Utility.readElementFromXMLReader(xmlr, Constants.URL_ELEMENT)));
        } else if (name.equals(Constants.NAME_ELEMENT)) {
          attributes.setName(Utility.readElementFromXMLReader(xmlr, Constants.NAME_ELEMENT));
        } else if (name.equals(Constants.METADATA_ELEMENT)) {
          // parse metadata
          attributes.setMetadata(DeserializationHelper.parseMetadateFromXML(xmlr));
          xmlr.require(XMLStreamConstants.END_ELEMENT, null, Constants.METADATA_ELEMENT);
        }
      } else if (eventType == XMLStreamConstants.END_ELEMENT
          && name.equals(BlobConstants.CONTAINER_ELEMENT)) {
        break;
      }
    }

    return attributes;
  }
  /**
   * Populates the container from an XMLStreamReader
   *
   * @param xmlr the XMLStreamReader to read from
   * @throws XMLStreamException if there is an error parsing the stream
   * @throws ParseException if there is an error in parsing a date
   * @throws URISyntaxException if the uri is invalid
   * @throws StorageException
   */
  protected static CloudBlobContainer readContainer(
      final XMLStreamReader xmlr, final CloudBlobClient serviceClient)
      throws XMLStreamException, ParseException, URISyntaxException, StorageException {

    xmlr.require(XMLStreamConstants.START_ELEMENT, null, BlobConstants.CONTAINER_ELEMENT);

    final BlobContainerAttributes attributes =
        BlobDeserializationHelper.readBlobContainerAttributes(xmlr);

    final CloudBlobContainer retContainer =
        new CloudBlobContainer(attributes.getUri(), serviceClient);
    retContainer.setMetadata(attributes.getMetadata());
    retContainer.setName(attributes.getName());
    retContainer.setProperties(attributes.getProperties());
    retContainer.setUri(attributes.getUri());

    xmlr.require(XMLStreamConstants.END_ELEMENT, null, BlobConstants.CONTAINER_ELEMENT);
    return retContainer;
  }