本文介绍了如何识别文件是否具有XML格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 如何识别文件是否具有XML格式? 以下是代码段: XmlDocument * pDomDocument = new XmlDocument(); 尝试 { pDomDocument->加载(strFileName); } catch(例外* e) { .... } Of当然,如果我们尝试加载非XML文件,则会抛出异常。 但是在其他情况下也可能抛出异常(文件不存在 等) 我需要在尝试加载非XML文件时识别具体情况。 对我来说似乎XmlException类没有提供这种细节。 /> 任何其他想法如何实现同一目标?提前致谢 How to recognize whether file has XML format or not?Here is the code segment: XmlDocument* pDomDocument = new XmlDocument();try{pDomDocument->Load(strFileName ) ;}catch(Exception* e){....} Of course if we try to load non XML file, the exception will be thrown.However exception might be thrown in other cases as well (File doesn''t existetc)I need identify the specific case when attempt was made to load non XML file.Seems to me XmlException class doesn''t provide that kind of details.Any other ideas how can I accomplish the same goal? Thanks in advance推荐答案 这篇关于如何识别文件是否具有XML格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-20 18:24