XML转DataSet问题

cwmwss 2008-12-24 08:44:39
<?xml version="1.0" encoding="utf-8"?>
<NewDataSet>
<m5mapply>
<dept_no>3503</dept_no>
<sheet_no>08C070</sheet_no>
<comp_no>huachun</comp_no>
<buy_kind>waigou</buy_kind>
<is_urgent>normal</is_urgent>
<cost_no>guangzhou</cost_no>
<budget_dept>guangzhou</budget_dept>
<budget_kind>years</budget_kind>
<budget_no>guzi</budget_no>
<mat_kind>预备</mat_kind>
<is_tryout>试用</is_tryout>
<is_batch>不准分批</is_batch>
<is_contract>是</is_contract>
<tax_kind>保税</tax_kind>
<need_date>2008-12-25T00:00:00</need_date>
<remarks>0</remarks>
<print_times>1</print_times>
<date_print_last></date_print_last>
<date_submit>2008-12-25T00:00:00</date_submit>
<approved>N</approved>
<date_approve>2008-12-25T00:00:00</date_approve>
<emp_entry>05344</emp_entry>
<date_entry>2008-12-23T16:47:47</date_entry>
<state_no>0</state_no>
</m5mapply>
</NewDataSet>
这里XML文件;后台代码:
DataSet ds = new DataSet();
ds.ReadXmlSchema(@"D:\OAreport\ImpTrade\XSD\M5.xsd");
//如果不读这句没有问题
ds.ReadXml(@"D:\OAreport\ImpTrade\XML\M5350308C070.xml");
this.GridView1.DataSource = ds.Tables["m5mapply"];
this.GridView1.DataBind();

如果写了红色这句,如果xml中日期为空,则出错:字符串“”不是有效的 AllXsd 值;
如果其它字符有空,则出错:输入字符串的格式不正确;
请教解决方法,需要先读ds.ReadXmlSchema(@"D:\OAreport\ImpTrade\XSD\M5.xsd");
...全文
1062 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
半卷书 2010-06-29
  • 打赏
  • 举报
回复
我也遇到了。

Exception in thread "main" org.apache.axis2.AxisFault: 服务器无法读取请求。 ---> XML 文档(1, 536)中有错误。 ---> 字符串“07:30”不是有效的 AllXsd 值。


正的郁闷中。LZ有没有什么好办法啊?
Firklaag117 2010-04-19
  • 打赏
  • 举报
回复
我也碰到这个问题了
greatverve 2008-12-25
  • 打赏
  • 举报
回复
cwmwss 2008-12-25
  • 打赏
  • 举报
回复
谢谢各位,在xml文件中加入schema后,不再出现上迷错误!
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="m9mother">
<xs:complexType>
<xs:sequence>
<xs:element name="dept_no" type="xs:string" minOccurs="0" />
<xs:element name="sheet_no" type="xs:string" minOccurs="0" />
<xs:element name="comp_no" type="xs:string" minOccurs="0" />
<xs:element name="cost_no" type="xs:string" minOccurs="0" />
<xs:element name="budget_dept" type="xs:string" minOccurs="0" />
<xs:element name="budget_no" type="xs:string" minOccurs="0" />
<xs:element name="tax_kind" type="xs:string" minOccurs="0" />
<xs:element name="is_io" type="xs:string" minOccurs="0" />
<xs:element name="io_kind" type="xs:string" minOccurs="0" />
<xs:element name="jiezhuanid" type="xs:string" minOccurs="0" />
<xs:element name="invoiceid" type="xs:string" minOccurs="0" />
<xs:element name="remarks" type="xs:string" minOccurs="0" />
<xs:element name="print_times" type="xs:short" minOccurs="0" />
<xs:element name="date_print_last" type="xs:dateTime" minOccurs="0" />
<xs:element name="date_submit" type="xs:dateTime" minOccurs="0" />
<xs:element name="approved" type="xs:string" minOccurs="0" />
<xs:element name="date_approve" type="xs:dateTime" minOccurs="0" />
<xs:element name="emp_entry" type="xs:string" minOccurs="0" />
<xs:element name="date_entry" type="xs:dateTime" minOccurs="0" />
<xs:element name="state_no" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="m9dother">
<xs:complexType>
<xs:sequence>
<xs:element name="dept_no" type="xs:string" minOccurs="0" />
<xs:element name="sheet_no" type="xs:string" minOccurs="0" />
<xs:element name="item_no" type="xs:short" minOccurs="0" />
<xs:element name="warehouse_no" type="xs:string" minOccurs="0" />
<xs:element name="manual_no" type="xs:string" minOccurs="0" />
<xs:element name="manual_item" type="xs:string" minOccurs="0" />
<xs:element name="material_no" type="xs:string" minOccurs="0" />
<xs:element name="mat_name" type="xs:string" minOccurs="0" />
<xs:element name="mat_spec_notes" type="xs:string" minOccurs="0" />
<xs:element name="lot_no" type="xs:string" minOccurs="0" />
<xs:element name="grade" type="xs:string" minOccurs="0" />
<xs:element name="units" type="xs:string" minOccurs="0" />
<xs:element name="unit_price" type="xs:decimal" minOccurs="0" />
<xs:element name="mat_qty" type="xs:decimal" minOccurs="0" />
<xs:element name="amount" type="xs:decimal" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<m9mother>
<dept_no>3503</dept_no>
<sheet_no>08C002</sheet_no>
<comp_no></comp_no>
<cost_no></cost_no>
<budget_dept></budget_dept>
<budget_no>固资</budget_no>
<tax_kind>保税</tax_kind>
<is_io>入</is_io>
<io_kind>生产领用</io_kind>
<jiezhuanid>1</jiezhuanid>
<invoiceid>1</invoiceid>
<remarks>1</remarks>
<print_times>0</print_times>
<approved>N</approved>
<emp_entry>05344</emp_entry>
<date_entry>2008-12-23T10:35:04.813+08:00</date_entry>
<state_no>0</state_no>
</m9mother>
</NewDataSet>
zlb789 2008-12-24
  • 打赏
  • 举报
回复
up
cwmwss 2008-12-24
  • 打赏
  • 举报
回复
符上xsd文件中内容:
<xs:complexType>
<xs:sequence>
<xs:element name="dept_no" type="xs:string" minOccurs="0" />
<xs:element name="sheet_no" type="xs:string" minOccurs="0" />
<xs:element name="comp_no" type="xs:string" minOccurs="0" />
<xs:element name="buy_kind" type="xs:string" minOccurs="0" />
<xs:element name="is_urgent" type="xs:string" minOccurs="0" />
<xs:element name="cost_no" type="xs:string" minOccurs="0" />
<xs:element name="budget_dept" type="xs:string" minOccurs="0" />
<xs:element name="budget_kind" type="xs:string" minOccurs="0" />
<xs:element name="budget_no" type="xs:string" minOccurs="0" />
<xs:element name="mat_kind" type="xs:string" minOccurs="0" />
<xs:element name="is_tryout" type="xs:string" minOccurs="0" />
<xs:element name="is_batch" type="xs:string" minOccurs="0" />
<xs:element name="is_contract" type="xs:string" minOccurs="0" />
<xs:element name="tax_kind" type="xs:string" minOccurs="0" />
<xs:element name="need_date" type="xs:dateTime" minOccurs="0" />
<xs:element name="remarks" type="xs:string" minOccurs="0" />
<xs:element name="print_times" type="xs:short" minOccurs="0" />
<xs:element name="date_print_last" type="xs:dateTime" minOccurs="0" />
<xs:element name="date_submit" type="xs:dateTime" minOccurs="0" />
<xs:element name="approved" type="xs:string" minOccurs="0" />
<xs:element name="date_approve" type="xs:dateTime" minOccurs="0" />
<xs:element name="emp_entry" type="xs:string" minOccurs="0" />
<xs:element name="date_entry" type="xs:dateTime" minOccurs="0" />
<xs:element name="state_no" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
或许应该修改下这里,让元素可以为空
cwmwss 2008-12-24
  • 打赏
  • 举报
回复
二楼的。你这里没有生成xsd文件,如果单是xml文件,我用ds.ReadXml(@"D:\OAreport\ImpTrade\XML\M5350308C070.xml"); 是可以的;

ds.ReadXmlSchema(@"D:\OAreport\ImpTrade\XSD\M5.xsd"); //但这里先读取了数据框架,
ds.ReadXml(@"D:\OAreport\ImpTrade\XML\M5350308C070.xml");
cwmwss 2008-12-24
  • 打赏
  • 举报
回复
看完一楼的了,里面没有当xml文件有<print_times></print_times> 有空时,
ds.ReadXmlSchema(@"D:\OAreport\ImpTrade\XSD\M5.xsd");
ds.ReadXml(@"D:\OAreport\ImpTrade\XML\M5350308C070.xml"); //这句出错的解决办法
jiang_jiajia10 2008-12-24
  • 打赏
  • 举报
回复

System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.AppendFormat("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
sb.AppendFormat("<GWInfo>");
sb.AppendFormat("<lachuzhi>{0}</lachuzhi>",this.TextBox1.Text);
sb.AppendFormat("<daogao>{0}</daogao>",this.TextBox2.Text);
sb.AppendFormat("</GWInfo>");
DataSet ds = new DataSet();
StringReader sr = new StringReader(sb.ToString());
XmlTextReader xmlReader = new XmlTextReader(sr);
ds.ReadXml(xmlReader);
mengxj85 2008-12-24
  • 打赏
  • 举报
回复
帮顶

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧