如何检查XML文件是否有效 [英] how to check XML file is valid or not

查看:272
本文介绍了如何检查XML文件是否有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用.Net 4.0框架,ASP.NET 4.0。



如何通过使用文件上传来检查上传文件是否是有效的XML文件control?

Im using .Net 4.0 framework, ASP.NET 4.0.

How to check whether the uploading file is a valid XML file while uploading it by using file upload control?

推荐答案

请仔细阅读,



http://msdn.microsoft.com/en-us/library/ms162371.aspx [ ^ ]


试试这个



只需阅读此内容并在其中添加更多代码



Try this

Just read this and add some more code in it

XElement element;

TRY
 {
    element=XElement.Load(filename);
    -- Add code to updload file here
    --Because if you reach here then it meant your file successfully 
 }
CATCH (exception ex)
 {
    -- Do not upload file and write code to handle invalid XML file
 }





阅读本文以获取更多信息

http://blogs.msdn.com/b/mcsuksoldev/archive/2010/02/04/dynamic-xml-reader-with-c -and-net-4-0.aspx [ ^ ]



---希望这有助于



Read this for more information
http://blogs.msdn.com/b/mcsuksoldev/archive/2010/02/04/dynamic-xml-reader-with-c-and-net-4-0.aspx[^]

---Hope this helps


这篇关于如何检查XML文件是否有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆