akram badr

 hi

i have proplem  with me code

i have an xml  file this tha schema of it

< xml version="1.0" standalone="yes" >
<!--Sample for for exercising PFM_StateData namespace-->
<states_StateDataForm_DemoForm>
      <Attributes>
            <Type>TextBox</Type>
            <Name>txtSummary</Name>
            <Width>358</Width>
            <Height>51</Height>
            <Top>16</Top>
            <Left>12</Left>
      </Attributes>
      <Attributes>
            <Typee>Label</Typee>
            <Name>lblOfText</Name>
            <Width>96</Width>
            <Height>13</Height>
            <Top>16</Top>
            <Left>70</Left>
      </Attributes>

and i use this part of code to store it in list

private static GuiEngine.Lists.AttributList GetAttributes(System.Xml.XmlElement xmlElement)

{

GuiEngine.Lists.AttributList attributes = new GuiEngine.Lists.AttributList();

System.Xml.XmlNodeList listAttributes = xmlElement.GetElementsByTagName("Attributes");

for (int i = 0; i < listAttributes.Count; i++)

{

if (listAttributesIdea.ParentNode == xmlElement)

for (int j = 0; j < listAttributesIdea.ChildNodes.Count; ++j)

attributes.Add(listAttributesIdea.ChildNodes[j].Name, listAttributesIdea.ChildNodes[j].InnerText);

}

return attributes;

when i = 0  he work well and store the forst part of the file

  <Attributes>
            <Type>TextBox</Type>
            <Name>txtSummary</Name>
            <Width>358</Width>
            <Height>51</Height>
            <Top>16</Top>
            <Left>12</Left>
      </Attributes>

but when  i = 1 he make exception

in this line

attributes.Add(listAttributesIdea.ChildNodes[j].Name, listAttributesIdea.ChildNodes[j].InnerText);

argument exception was unhandled

An entry with the same key already exists.

can any one help me to solve this problem



Re: XML and the .NET Framework problem saving of xml file (argument exception was unhandled)

Sergey Dubinets - MSFT

It looks like GuiEngine.Lists.AttributeList doesn't want to have two attributes with the same name and this is exectly what you trying to do.

What is GuiEngine.Lists.AttributeList






Re: XML and the .NET Framework problem saving of xml file (argument exception was unhandled)

akram badr

ko can you solve for me this problem

GuiEngine.Lists.AttributeList this the code of it

using System;

namespace GuiEngine.Lists

{

public class AttributList:System.Collections.Specialized.HybridDictionary

{

public AttributList()

{

}

}

}





Re: XML and the .NET Framework problem saving of xml file (argument exception was unhandled)

Martin Honnen

What exactly do you want to achieve A dictionary like a HybridDictionary has key/value pairs so you can't have two entries with the same key.




Re: XML and the .NET Framework problem saving of xml file (argument exception was unhandled)

akram badr

i  want exactly to achieve

is to save this schema  of xml file in list

please if you have any othre solution please make ademo code to me

if there is any other thing inisted of HybridDictionary and can take the same key

please tell me





Re: XML and the .NET Framework problem saving of xml file (argument exception was unhandled)

Sergey Dubinets - MSFT

Sorry. It hard to understand what you want to do.

Use debugger to understand what's actually your program is doing.

In particular: listAttributesIdea.ChildNodes[j].Name is not value of element <Name> (i.e. "txtSummery") but rather name of this element (i.e. "Name").

When i =1 you adding the same attributes to the same attribute list ("Type", "Name", ...). This clearly don't work.