Deleting Values from an Attribute

Previously, the Color attribute for Item_03 was assigned three values (Blue, Yellow, and Pink). This section provides examples of how to delete the value of an attribute for the sample item.

The following sample code snippets demonstrate deletion of the value Blue from the Color attribute of Item_03. The other color values will remain (i.e., Yellow, Pink).

Java

To run the sample

  1. Open a clean copy of DeleteAttributesSample.java.

  2. Remove any comment marks from the invokeDeleteAttributes(service, request); line and add the following lines after // @TODO: set request parameters here:

    String domainName = "MyStore";
    String itemName = "Item_03";
    Attribute attribute = new Attribute("Color", "Blue");
    
    DeleteAttributes request = (new DeleteAttributes()).withDomainName(domainName).withItemName(itemName).withAttribute(attribute);
    
  3. Compile and run the sample.

    Amazon SimpleDB deletes the Blue value from the Color attribute of Item_03.

To verify whether the value is deleted, see Getting the Attributes of an Item.

C#

To run the sample

  1. Open AmazonSimpleDBSamples.cs.

  2. Comment out the code you added in the previous section.

  3. Replace the Delete Attributes Action section with the following:

    Amazon.SimpleDB.Model.Attribute deleteValueAttribute = new Amazon.SimpleDB.Model.Attribute().WithName("Color").WithValue("Blue");
    DeleteAttributes deleteValueAction = new DeleteAttributes().WithDomainName("MyStore").WithItemName("Item_03").WithAttribute(deleteValueAttribute);
    
    DeleteAttributesSample.InvokeDeleteAttributes(service, deleteValueAction);
    
  4. Run the sample.

    Amazon SimpleDB deletes the Blue value from the Color attribute of Item_03

To verify whether the value is deleted, see Getting the Attributes of an Item.

Perl

To run the sample

  1. Open a clean copy of DeleteAttributesSample.pl.

  2. Remove any comment marks from the invokeDeleteAttributes($service, $request); line and add the following lines after the // @TODO: set request line:

    my $request = Amazon::SimpleDB::Model::DeleteAttributes->new({
    ItemName => "Item_03",
    DomainName=> "MyStore",
    Attribute => [
    {
    Name => "Color",
    Value => "Blue"
    }
    ],
    });
    
  3. Run the sample.

    Amazon SimpleDB deletes the Blue value from the Color attribute of Item_03.

To verify whether the value is deleted, see Getting the Attributes of an Item.

PHP

To run the sample

  1. Open a clean copy of DeleteAttributesSample.php.

  2. Remove any comment marks from the invokeDeleteAttributes($service, $request); line and add the following lines after the // @TODO: set request line:

     require_once ('Amazon/SimpleDB/Model/Attribute.php');
    
     $attribute = new Amazon_SimpleDB_Model_Attribute();
     $attribute->withName('Color')->withValue('Blue');
    
     $request = new Amazon_SimpleDB_Model_DeleteAttributes();
     $request->withDomainName('MyStore')->withItemName('Item_03')->withAttribute($attribute);
    
  3. Run the sample.

    Amazon SimpleDB deletes the Blue value from the Color attribute of Item_03.

To verify whether the value is deleted, see Getting the Attributes of an Item.

VB.NET

To run the sample

  1. Open AmazonSimpleDBSamples.vb.

  2. Comment out the code you added in the previous section.

  3. Replace the Delete Attributes Action section with the following:

    Dim deleteValueAttribute As New Amazon.SimpleDB.Model.Attribute
    deleteValueAttribute.WithName("Color").WithValue("Blue")
    
    Dim deleteValueAction As New DeleteAttributes()
    deleteValueAction.WithDomainName("MyStore").WithItemName("Item_03").WithAttribute(deleteValueAttribute)
    
    DeleteAttributesSample.InvokeDeleteAttributes(service, deleteValueAction)
    
  4. Run the sample.

    Amazon SimpleDB deletes the Blue value from the Color attribute of Item_03.

To verify whether the value is deleted, see Getting the Attributes of an Item.

Scratchpad

To run the sample

  1. Open the scratchpad application with a web browser.

  2. Select DeleteAttributes from the Explore API list box.

  3. Enter MyStore in the Domain Name field.

  4. Enter Color in the Name field and Blue in the Value field.

  5. Select from the following:

    • To invoke the request, click Invoke Request.

      Amazon SimpleDB deletes the Blue value from the Color attribute of Item_03.

    • To view the signed URL, click Display Signed URL. Then, copy and paste the signed URL into a browser.

      Amazon SimpleDB deletes the Blue value from the Color attribute of Item_03.

    • To view the string to sign, click Display String to Sign.