주어진 XSD에 대해 유효성을 검사해야하는 xml로 변환해야하는 많은 개체 모음이 있습니다.제공된 xsd 스키마로 다수의 객체를 직렬화하는 방법은 무엇입니까?
클래스 구조가없는 매우 복잡 (하는게 먼지 너도 스무 속성과 자식 클래스의 두 목록) 예 :
public class Person
{
public string Street, Town, City, PostCode etc;
public double Income, Tax, etc.;
public List<Account> Accounts;
...
}
하지만 예상 XML 출력 복잡하고 일치하지 않는 클래스 구조
<Person>
<Address>
<Street/><Town/><City/>
</Address>
<FinancialData>
<Income/><Tax/>
</FinancialData>
<Accounts>
<Account>
<No>1</No>
...
</Accounts>
</Person>
그렇게하는 가장 좋은 방법은 무엇입니까?
나는
XElement document = new XElement("Person",
new XElement("Address",
new XElement("Street", this.Street),
new XElement("City", this.City),
new XElement("FinancialData",
new XElement("Income", this.Income), ...
을 각 개체에 대해 XElement를 구조를 만든 다음하여 XDocument로 결합하고 저장하려고하지만 XElements을 만드는 과정은 매우 느리고 내가 50.000를 직렬화 할 필요가 wheras 200 개체가 몇 분 소요 사물.
XmlSerializer에 대해 생각했지만 class와 xsd가 일치하지 않습니다.
업데이트 : 내 기본 클래스를 매핑 한 사용자 지정 클래스를 만들었습니다. 그런 다음 XmlSerializer 및 해당 특성을 사용하여 xml 내 개체를 serialize합니다. 꽤 빠릅니다.