0

I use a local xml file. When I remove an item in web browser it is removed but the xml file doesn't change. Why is this appending? Here is my xml file;

<?xml version="1.0" encoding="utf-8" ?>
<products>
    <product>
        <productId>1</productId>
        <categoryId>1</categoryId>
        <name>Azalea</name>
        <nickname>California Snow</nickname>
        <instructions>Large double.</instructions>
        <catalogNumber>S1</catalogNumber>
        <price>15.99</price>
        <photo>california_snow.jpg</photo>
    </product>

    <product>
        <productId>2</productId>
        <categoryId>1</categoryId>
        <name>Tibouchina Semidecandra</name>
        <instructions>Beautiful large royal.</instructions>
        <catalogNumber>S2</catalogNumber>
        <price>33.99</price>
        <photo>princess_flower.jpg</photo>
    </product>
      ...

I write these code below.at the same time how can I add and change it? already thank you very much

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
  xmlns:s="library://ns.adobe.com/flex/spark" 
  xmlns:mx="library://ns.adobe.com/flex/mx"
  skinClass="skins.HPAppSkin">

  <fx:Script>
    <![CDATA[
      protected function button1_clickHandler(event:MouseEvent):void
      {

        productCollection.removeItemAt(productGrid.selectedIndex);


      }
    ]]>
  </fx:Script>

  <fx:Declarations>
    <fx:Model id="productModel" source="data/products.xml"/>
    <s:ArrayList id="productCollection"
      source="{productModel.product}"/>
  </fx:Declarations>

  <mx:DataGrid id="productGrid" dataProvider="{productCollection}"/>
  <s:Button label="Remove Item" click="button1_clickHandler(event)"
    enabled="{productGrid.selectedIndex != -1}"/>
</s:Application>
FeliceM
  • 4,163
  • 9
  • 48
  • 75

2 Answers2

0

removeItem removes the item from the dataProvider only - not from the XML where it's loaded from. You need to update/rewrite the XML accordingly after removing the item manually.

Pete TNT
  • 8,293
  • 4
  • 36
  • 45
0

From your xml...I think ProductId is unique... You can add ur ProductId in an Array... like this:

public var removedItemArray:Array = new Array();
protected function button1_clickHandler(event:MouseEvent):void
  {

    productCollection.removeItemAt(productGrid.selectedIndex);
    removedItemArray.push(event.currentTarget.selectedItem.productId);

  }

then You send the removedItemArray Data to where you Frame your Xml and ReFrame the Xml by Removing the ProductIds's which are in removedItemArray.

I hope this Might Kill your Prob bro!!!

Aravinth
  • 363
  • 2
  • 10
  • 33