Tôi đang thử nghiệm tạo các lớp ràng buộc dữ liệu XML với LinqToXSD và một Lược đồ XML chứa một số lược đồ đã nhập. Tất cả các lược đồ là located here.Làm cách nào để tôi nhận được LinqToXSD để khai báo đúng các khai báo tiền tố không gian tên?
Để thực hiện điều này, tôi đã sử dụng tài liệu giản đồ gốc sau:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:TmatsG="http://www.spiraltechinc.com/tmats/106-13/TmatsG" elementFormDefault="unqualified">
<xs:import namespace="http://www.spiraltechinc.com/tmats/106-13/TmatsCommon" schemaLocation="TmatsCommonTypes.xsd"/>
<xs:import namespace="http://www.spiraltechinc.com/tmats/106-13/TmatsC" schemaLocation="TmatsCGroup.xsd"/>
<xs:import namespace="http://www.spiraltechinc.com/tmats/106-13/TmatsD" schemaLocation="TmatsDGroup.xsd"/>
<xs:import namespace="http://www.spiraltechinc.com/tmats/106-13/TmatsG" schemaLocation="TmatsGGroup.xsd"/>
<xs:import namespace="http://www.spiraltechinc.com/tmats/106-13/TmatsH" schemaLocation="TmatsHGroup.xsd"/>
<xs:import namespace="http://www.spiraltechinc.com/tmats/106-13/TmatsM" schemaLocation="TmatsMGroup.xsd"/>
<xs:import namespace="http://www.spiraltechinc.com/tmats/106-13/TmatsP" schemaLocation="TmatsPGroup.xsd"/>
<xs:import namespace="http://www.spiraltechinc.com/tmats/106-13/TmatsR" schemaLocation="TmatsRGroup.xsd"/>
<xs:import namespace="http://www.spiraltechinc.com/tmats/106-13/TmatsS" schemaLocation="TmatsSGroup.xsd"/>
<xs:import namespace="http://www.spiraltechinc.com/tmats/106-13/TmatsT" schemaLocation="TmatsTGroup.xsd"/>
<xs:import namespace="http://www.spiraltechinc.com/tmats/106-13/TmatsV" schemaLocation="TmatsVGroup.xsd"/>
<xs:element name="Tmats" type="TmatsG:Tmats">
<xs:annotation>
<xs:documentation>Tmats Root</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>
Tôi tạo ra các lớp học sử dụng LINQ to XSD. sau đó tôi đã viết bài kiểm tra sau:
[TestMethod()]
public void TmatsXmlExample4()
{
Tmats tmats = new Tmats
{
ProgramName = "My Program",
OriginationDate = DateTime.Now,
};
tmats.PointOfContact.Add(new PointOfContactType
{
Address = "12345 Anywhere Street",
Agency = "My Agency",
Name = "Robert Harvey",
Telephone = "111-222-3333"
});
Debug.Print(tmats.ToString());
}
tôi mong đợi đầu ra mà nhìn một cái gì đó như thế này:
<Tmats>
<TmatsG:ProgramName>My Program</TmatsG:ProgramName>
<TmatsG:OriginationDate>2012-05-09-07:00</TmatsG:OriginationDate>
<TmatsG:PointOfContact>
<TmatsCommon:Name>Robert Harvey</TmatsCommon:Name>
<TmatsCommon:Agency>My Agency</TmatsCommon:Agency>
<TmatsCommon:Address>12345 Anywhere Street</TmatsCommon:Address>
<TmatsCommon:Telephone>111-222-3333</TmatsCommon:Telephone>
</TmatsG:PointOfContact>
</Tmats>
Thay vào đó, những gì tôi nhận được điều này:
<Tmats>
<ProgramName xmlns="http://www.spiraltechinc.com/tmats/106-13/TmatsG">My Program</ProgramName>
<OriginationDate xmlns="http://www.spiraltechinc.com/tmats/106-13/TmatsG">2012-05-09-07:00</OriginationDate>
<PointOfContact xmlns="http://www.spiraltechinc.com/tmats/106-13/TmatsG">
<Name xmlns="http://www.spiraltechinc.com/tmats/106-13/TmatsCommon">Robert Harvey</Name>
<Agency xmlns="http://www.spiraltechinc.com/tmats/106-13/TmatsCommon">My Agency</Agency>
<Address xmlns="http://www.spiraltechinc.com/tmats/106-13/TmatsCommon">12345 Anywhere Street</Address>
<Telephone xmlns="http://www.spiraltechinc.com/tmats/106-13/TmatsCommon">111-222-3333</Telephone>
</PointOfContact>
</Tmats>
Có cách nào để có được LinqToXSD để sản xuất sản lượng dự kiến?
Cảm ơn! - Nếu bạn tin tưởng rằng lược đồ không có khả năng thay đổi chúng, bạn có thể chú thích tất cả các phần tử trong tệp 'Tmats.cs' để hỗ trợ trình nối tiếp, nhưng cá nhân tôi chỉ chuyển đổi nó thành một biểu định kiểu và để nó được. –