将 XML 加载到 .Net 4 / VS2010 中的数据集表中,未加载所有元素/属性
我正在尝试将复杂的 XML 文档加载到数据集表中。以下是使用 xsd 文档验证 xml 并尝试加载到数据集表的代码:
DataSet ds = new DataSet();
ds.ReadXmlSchema("test.xsd");
ds.EnforceConstraints = true;
ds.ReadXml("test.xml", XmlReadMode.ReadSchema);
在此之后,我尝试查看使用以下代码创建的所有表/列“
foreach (DataTable x in ds.Tables) {
Console.WriteLine("TableName: {0}", x.TableName);
foreach (DataColumn dc in x.Columns) {
Console.WriteLine(" column: {0} , DataType: {1}",
dc.ColumnName, dc.DataType);
}
}
在打印的表/列输出中,我看不到几个当我在输出中没有的 Xs:element 部分与输出中的元素/属性之间移动时,现在输出显示了之前不存在的元素/属性,并且没有显示那些在输出中的元素/属性。以前在那里...我会很感激任何帮助/想法...
xsd 约为 50K,xml 约为 200K,不确定它们是否可以上传/粘贴到此处...
谢谢 桑卡尔
I am trying to load a complex XML document to DataSet Tables. Here is the code that validates the xml with xsd document and trying to load to the dataset tables:
DataSet ds = new DataSet();
ds.ReadXmlSchema("test.xsd");
ds.EnforceConstraints = true;
ds.ReadXml("test.xml", XmlReadMode.ReadSchema);
And after this I tried to see all table tables/ columns created using the below code"
foreach (DataTable x in ds.Tables) {
Console.WriteLine("TableName: {0}", x.TableName);
foreach (DataColumn dc in x.Columns) {
Console.WriteLine(" column: {0} , DataType: {1}",
dc.ColumnName, dc.DataType);
}
}
In the printed Tables/columns output I could not see few elements / attributes that are in the XSD. When I moved around those Xs:element sections that are no in the output with the ones that are in the output, now the output shows the ones which were not earlier and did not show the ones which was there before... I would appreciate any help/ideas...
the xsd is about 50K and the xml is about 200K , not sure if they could be uploaded/pasted in here...
Thanks
Sankar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从您想要的 DataTable 开始,然后从中创建 xsd 架构可能会更容易:
如图所示 此处。
It might be easier to start with the DataTable you desire and then create the xsd schema from it:
As shown here.