读书人

百分求解:如何将一个XML格式的字符串读

发布时间: 2012-03-06 20:47:55 作者: rapoo

百分求解:怎么将一个XML格式的字符串读取到DataSet中
网页接收的值是一个XML格式的字符串
想把它读到DataSet中进行处理,应该怎么做?


Stream s = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(entity));
ds = new System.Data.DataSet();
ds.ReadXml( s );

我这样写提示
System.Xml.XmlException: 系统不支持“UTF8”编码。 行 1,位置 31。
在 System.Xml.XmlTextReaderImpl.Throw(Exception e)
在 System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
在 System.Xml.XmlTextReaderImpl.CheckEncoding(String newEncodingName)
在 System.Xml.XmlTextReaderImpl.ParseXmlDeclaration(Boolean isTextDecl)
在 System.Xml.XmlTextReaderImpl.Read()
在 System.Xml.XmlTextReader.Read()
在 System.Xml.XmlReader.MoveToContent()
在 System.Data.DataSet.ReadXml(XmlReader reader, Boolean denyResolving)
在 System.Data.DataSet.ReadXml(Stream stream)


[解决办法]
<?xml version= "1.0 " ?> <Entity> <PseudoId> 08000000000000000029657805|1B0DFE90D39F3A910E055789BC216500 </PseudoId> <TimeStamp> 20070404101416.375 </TimeStamp> <ProductId> 080000000017000000006 </ProductId> <ProductName> 新包月产品001 </ProductName> <AuthType> 2 </AuthType> </Entity>

就好了。

[解决办法]
晕哦 你的编码 设置错了

不是UTF8 应该是 UTF-8

<?xml version= "1.0 " encoding= "UTF-8 "?> <Entity> <PseudoId> 08000000000000000029657805|1B0DFE90D39F3A910E055789BC216500 </PseudoId> <TimeStamp> 20070404101416.375 </TimeStamp> <ProductId> 080000000017000000006 </ProductId> <ProductName> 新包月产品001 </ProductName> <AuthType> 2 </AuthType> </Entity>

读书人网 >asp.net

热点推荐