0

Ive been create some code that save an xml file and loads an xml file and it does both perfectly.

here is where i found a bug. when i save a xml file then load it and finally re-save it does something really weird

so i save a file that looks like this

<partlist>
  <item>
    <series>51 Series</series>
    <part>29251</part>
    <size>29251-6-6</size>
    <alt></alt>
    <description>BSP Swiv FM, BN</description>
  </item>
  <item>
    <series>51 Series</series>
    <part>29251</part>
    <size>29251-8-8</size>
    <alt></alt>
    <description>BSP Swiv FM, BN</description>
  </item>
</partlist>

when i load it into my flex app and then resave it looks like this

<partlist>
  <item>
    <series>
      <series>51 Series</series>
    </series>
    <part>
      <part>29251</part>
    </part>
    <size>
      <size>29251-6-6</size>
    </size>
    <alt>5654</alt>
    <description>
      <description>BSP Swiv FM, BN</description>
    </description>
  </item>
  <item>
    <series>
      <series>51 Series</series>
    </series>
    <part>
      <part>29251</part>
    </part>
    <size>
      <size>29251-8-8</size>
    </size>
    <alt>
      <alt/>
    </alt>
    <description>
      <description>BSP Swiv FM, BN</description>
    </description>
  </item>
</partlist>

the values that are saved and loaded are stored in an Arraycollection an here is how i create the nodes

var SavelistXml:XML=new XML();
SavelistXml = <partlist/>;
for (var i:Number = 0; i < PartsArray.length; i++)
{
var obj:Object = Object(PrintListGrid[i]);

var newItemNode:XML= <item/>;                   
var newSeriesNode:XML = <series/>;
newSeriesNode.appendChild(obj.PartGroup);
var newPartNode:XML = <part/>;
newPartNode.appendChild(obj.PartType);
var newSizeNode:XML = <size/>;
newSizeNode.appendChild(obj.PartNumber);
var newAltPartNode:XML = <alt/>;
newAltPartNode.appendChild(obj.AltPartNum);
var newDescriptionNode:XML = <description/>;
newDescriptionNode.appendChild(obj.PartDesc);

newItemNode.appendChild(newSeriesNode);
newItemNode.appendChild(newPartNode);
newItemNode.appendChild(newSizeNode);
newItemNode.appendChild(newAltPartNode);
newItemNode.appendChild(newDescriptionNode);

SavelistXml.appendChild(newItemNode);
}

dont know why it works but as soon as the data comes from a loaded file it stops working right. if i alert obj.PartGroup for example it gives me the right value but the appendChild() is creating a node of it self inside a node of it self

Chito
  • 21
  • 1
  • What exactly is the output of that alert? How do you parse and store the values into the ArrayCollection? – weltraumpirat May 03 '12 at 08:42
  • 1
    What type is `obj`? It looks like its already an `XML` object, or at least the properties off of it are XML nodes. You are re-boxing each node inside of another node of the same type. Or at least it looks that way. – J. Holmes May 03 '12 at 09:32
  • Load a template xml file that looks like what you want, then amend the values – Neil May 03 '12 at 15:04

0 Answers0