Forum » Programiranje » XmlSerializacija
XmlSerializacija

DubleG ::
public class studenti
{
[XmlElement("ime")]
public string ime = string.Empty;
[XmlElement("priimek")]
public string priimek = string.Empty;
[XmlElement("vzdevek")]
public string vzdevek = string.Empty;
[XmlElement("naslov")]
public naslov naslovi;
[XmlElement("drzavljanstvo")]
public string drzavljanstvo = string.Empty;
[XmlElement("rojstni_podatki")]
public rojstni_podatki rojstni_podatki;
[XmlElement("opravljeni_izpiti")]
public opravljeni_izpiti opravljeni_izpiti;
[XmlElement("letnik")]
public int letnik = 0;
[XmlElement("vpisna_stevilka")]
public string vpisna_stevilka = string.Empty;
}
[XmlRoot("student_collection")]
public class student_collection
{
public studenti[] student;
}
studenti[] temp = new studenti[100];
int steviloStudentov;
//dodajanje objektov v array
pot_datoteke = (@"C:\Users\miminr\Desktop\ll.xml");
student_collection studentarija = new student_collection();
studenti[] dodajanje = new studenti[steviloStudentov];
// studentarija.studenti_vsi = new studenti();
for (int i = 0; i < steviloStudentov; i++)
{
dodajanje[i] = temp[i]; //ker imamo novice v temp polju, jih skopiramo v pravo polje novic
}
studentarija.student = dodajanje;
XmlSerializer s = new XmlSerializer(typeof(student_collection));
TextWriter w = new StreamWriter(pot_datoteke);
s.Serialize(w, studentarija);
w.Close();
w = null;
s = null;
dodajanje = null;
itd classoc.
Kako naj hranim študente, da mi serializacija ne bo kreirala še tega elementa < student >, ki nastane z razredom student_collection v katerem imam array, ki mi hrani objekte tipa studenti
-
<student_collection>
-<student>
- <studenti>
< ime>2</ime>
<priimek>2</priimek>
<vzdevek>2</vzdevek>
GA-P55M-UD2,i5,12GB RAM,Radeon HD 4850,Crucial SSD 64GB,
WD 320GB,WD 5000GB,RevoDrive X2 100GB
WD 320GB,WD 5000GB,RevoDrive X2 100GB
- spremenil: DubleG ()

Looooooka ::
1)ne uporabljaj mnozine pri razredih (class student in ne class students)
2)ali implementiraj potrebne interface za custom serializacijo
ali pa preprosto naredi naslednjo stvar:
ko bos to seriliziral na disk bos dobil:
2)ali implementiraj potrebne interface za custom serializacijo
ali pa preprosto naredi naslednjo stvar:
[XmlRoot("student_collection")]
public class student_collection:List<studenti>
{
}
student_collection students = new student_collection();
for (int i = 0; i < 3; i++)
{
students.Add(new studenti());
}
ko bos to seriliziral na disk bos dobil:
<?xml version="1.0" encoding="utf-8" ?>
- <student_collection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <studenti>
<ime />
<priimek />
<vzdevek />
<drzavljanstvo />
<letnik>0</letnik>
<vpisna_stevilka />
</studenti>
- <studenti>
<ime />
<priimek />
<vzdevek />
<drzavljanstvo />
<letnik>0</letnik>
<vpisna_stevilka />
</studenti>
- <studenti>
<ime />
<priimek />
<vzdevek />
<drzavljanstvo />
<letnik>0</letnik>
<vpisna_stevilka />
</studenti>
</student_collection>

DubleG ::
Hvala.
GA-P55M-UD2,i5,12GB RAM,Radeon HD 4850,Crucial SSD 64GB,
WD 320GB,WD 5000GB,RevoDrive X2 100GB
WD 320GB,WD 5000GB,RevoDrive X2 100GB

DubleG ::
Delam en xpath query:
String strExpression = ("sum(/student_collection/student/opravljeni_izpiti/ocena) div count(/student_collection/student/opravljeni_izpiti/ocena)");
vendar, mi ne uspe napisat, pa tudi dokumentacija je bolj švohna... Da bi preštel ocene, samo znotraj očeta, kjer velja da je indeks_stevilka enaka 123456.
String strExpression = ("sum(/student_collection/student/opravljeni_izpiti/ocena) div count(/student_collection/student/opravljeni_izpiti/ocena)");
vendar, mi ne uspe napisat, pa tudi dokumentacija je bolj švohna... Da bi preštel ocene, samo znotraj očeta, kjer velja da je indeks_stevilka enaka 123456.
<student>
<opravljeni_izpiti>
<predmet>MAT</predmet>
<ocena>9</ocena>
<datum>
<dan_>5</dan_>
<mesec_>1</mesec_>
<leto_>2009</leto_>
</datum>
</opravljeni_izpiti>
<opravljeni_izpiti>
<predmet>ANG</predmet>
<ocena>9</ocena>
<datum>
<dan_>5</dan_>
<mesec_>1</mesec_>
<leto_>2009</leto_>
</datum>
</opravljeni_izpiti>
<strong> <vpisna_stevilka>1234156</vpisna_stevilka></strong>
</student>
GA-P55M-UD2,i5,12GB RAM,Radeon HD 4850,Crucial SSD 64GB,
WD 320GB,WD 5000GB,RevoDrive X2 100GB
WD 320GB,WD 5000GB,RevoDrive X2 100GB
Zgodovina sprememb…
- spremenil: DubleG ()
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | [C#] WPF vprašanjaOddelek: Programiranje | 1196 (818) | Ciklamen |
» | E-računOddelek: Programiranje | 7965 (4728) | ivanhoe5x |
» | [c#] Napačen izpis -- prazni stringiOddelek: Programiranje | 1620 (1562) | Spura |
» | [C#] Xml Serializacija Attribut pred NamespaceOddelek: Programiranje | 1022 (908) | Looooooka |
» | [C#] Simobilov GlasnikOddelek: Programiranje | 4494 (1574) | Mrch |