C# 读取xml文件忽略xml文件的注释
默认情况下,读取xml文件是不忽略注释的,这样读取带注释的节点会造成异常,那么怎么屏蔽掉这些注释呢?
XmlDocument doc = new XmlDocument(); XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreComments = true; //忽略注释 //xmlFilePath:xml文件路径 XmlReader reader = XmlReader.Create(xmlFilePath, settings); doc.Load(reader);
或者判断
if (node.NodeType == System.Xml.XmlNodeType.Comment) 判断节点是注释
本文来自博客园,作者:jevan,转载请注明原文链接:https://www.cnblogs.com/DoNetCShap/p/16442388.html