Dobry den, prosim o pomoc. Vim, ze to mam spatne, ale nevim, jak to spravne udelat. Mam tridu TestRun, ktera ma atributy, ale i List a to chci serializovat:
[XmlRoot("test-run")]
[Serializable]
public class TestRun
{
[XmlAttribute("name")]
public string Name { get; set; }
[XmlAttribute("total")]
public int Total { get; set; }
[XmlAttribute("passed")]
public int Passed { get; set; }
[XmlAttribute("failed")]
public int Failed { get; set; }
[XmlAttribute("start-time")]
public DateTime StartTime { get; set; }
[XmlAttribute("end-time")]
public DateTime EndTime { get; set; }
[XmlArray("test-run"), XmlArrayItem(typeof(TestSuiteTag), ElementName = "test-suite")]
public List<TestSuiteTag> TestSuites { get; set; }
}
Kdyz ji serializuju, dostanu:
<?xml version="1.0" encoding="UTF-8"?>
<test-run end-time="0001-01-01T00:00:00" start-time="0001-01-01T00:00:00" failed="0" passed="0" total="0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
[b] <test-run>[/b]
<test-suite id="1">
<dalsi tag></dalsi tag>
</test-suite>
<test-suite id="2">
<dalsi tag></dalsi tag>
</test-suite>
[b] </test-run>[/b]
</test-run>
A mne tam ty oznacene (druhe) test-run zavazi, pritom ale ten List potrebuju serializovat. Potreboval bych neceho takoveho:
<?xml version="1.0" encoding="UTF-8"?>
<test-run end-time="0001-01-01T00:00:00" start-time="0001-01-01T00:00:00" failed="0" passed="0" total="0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<test-suite id="1">
<dalsi tag></dalsi tag>
</test-suite>
<test-suite id="2">
<dalsi tag></dalsi tag>
</test-suite>
</test-run>
Vi prosim nekdo, jak na to? Pouzivam XMLSerializer.
Budu moc rad, pokud nekdo poradi.
G.