0

2Let's say I have this array:

<something>
    <items1 note="some text">
        <item1></item1>
        <item1></item1>
        <item1></item1>
    </items1>
    <items2>
        <item2></item2>
        <item2></item2>
        <item2></item2>
    </items2>
</something>

And I have a model:

public class Something
{
    public string Item1Note { get; set; }
    public List<Item1> Items1 { get; set; }
    public List<Item2> Items2 { get; set; }
}

So, Is it possible to deserialize XML into the model so that the attribute note of Items1 node was in property Item1Note. Thx in advance.

EDIT: I understand that note is property of Items1, but I don't have such class.

Kindzoku
  • 23
  • 1
  • 4

2 Answers2

2

class for that xml will be

public class Items1
{
    [XmlAttribute]
    public string note { get; set; }
    [XmlElement]
    public List<item1> item1 { get; set; }
}

public class Item2
{
    [XmlElement]
    public List<item2> item2 { get; set; }
}

[XmlRootAttribute("Something", Namespace="", IsNullable=false)]
public class Something
{
   [XmlElement]
    public Items1 items1 { get; set; }
    [XmlElement]
    public Item2 item2 { get; set; }
}


Something objSomething = this.Something();

ObjectXMLSerializer<Something>.Save(objSomething, FILE_NAME);

Loading the xml

objSomething = ObjectXMLSerializer<Something>.Load(FILE_NAME);
Shafqat Masood
  • 2,532
  • 1
  • 17
  • 23
  • Main point is I don't want to change model. So it's impossible with current model? Thx. – Kindzoku May 30 '13 at 08:57
  • if you see i have change the model.. i have mentioned two things one xmlelement and xmlattribute to explain you how note will be coiming you want to generate the xml or read the xml – Shafqat Masood May 30 '13 at 08:59
  • and using the objectxml serializer i am loading and saving the object – Shafqat Masood May 30 '13 at 09:00
  • Items1 is a wrapper in your example. I just don't want to use wrappers. I hoped for any special XmlAttribute property. :D Something like XmlAttribute("Items1@note") or something... guess no magic here. – Kindzoku May 30 '13 at 09:04
0

You can create your own parser and then save it as object. http://msdn.microsoft.com/en-us/library/cc189056%28v=vs.95%29.aspx

Sameer
  • 43
  • 3