xml.load与xml.loadxml

本文介绍了使用C#中XmlDocument类的多种方法来加载XML数据,包括从字符串、流、URL等不同来源加载XML文档的方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

LoadXml:从指定的字符串加载 XML 文档

doc.LoadXml("<root>aa</root>");

可以理解为字符串的格式已经为xml类型,用loadxml进行解析


Load:加载指定的 XML 数据

XmlDocument.Load (Stream)//从指定的流加载 XML 文档。
XmlDocument.Load (String) //从指定的 URL 加载 XML 文档。
XmlDocument.Load (TextReader) //从指定的 TextReader 加载 XML 文档。
XmlDocument.Load (XmlReader)//从指定的 XmlReader 加载 XML 文档。

从指定两个字入手就好理解了,指定的 流、URL、TextReader、XmlReader

转载于:https://www.cnblogs.com/LeslieC/p/6978753.html

System.Xml.XmlException HResult=0x80131940 Message=XML 注释中不能包含“--”,并且“-”不能是最后一个字符。 第 49 行,位置 4。 Source=System.Xml StackTrace: 在 System.Xml.XmlTextReaderImpl.Throw(Exception e) 在 System.Xml.XmlTextReaderImpl.Throw(String res, String arg) 在 System.Xml.XmlTextReaderImpl.ParseCDataOrComment(XmlNodeType type, Int32& outStartPos, Int32& outEndPos) 在 System.Xml.XmlTextReaderImpl.ParseCDataOrComment(XmlNodeType type) 在 System.Xml.XmlTextReaderImpl.ParseComment() 在 System.Xml.XmlTextReaderImpl.ParseElementContent() 在 System.Xml.XmlTextReaderImpl.Read() 在 System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace) 在 System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc) 在 System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) 在 System.Xml.XmlDocument.Load(XmlReader reader) 在 System.Xml.XmlDocument.LoadXml(String xml) 在 AutoGenerateConfig.FileParser.FileActions.GetFileXmlDocument(String xmlContent, XmlDocument doc) 在 C:\Users\wangdongchang\source\repos\autogenerateconfig2\AutoConfig\AutoGenerateConfig\FileParser\FileActions.cs 中: 第 99 行 在 AutoGenerateConfig.XmlParser.XmlParser.Xml2Doc(TemplateInfo templateInfo) 在 C:\Users\wangdongchang\source\repos\autogenerateconfig2\AutoConfig\AutoGenerateConfig\FileParser\XmlParser.cs 中: 第 658 行 在 AutoGenerateConfig.XmlParser.XmlParser.ADD(TemplateInfo templateInfo) 在 C:\Users\wangdongchang\source\repos\autogenerateconfig2\AutoConfig\AutoGenerateConfig\FileParser\XmlParser.cs 中: 第 550 行 在 AutoGenerateConfig.XmlParser.XmlParser.<>c__DisplayClass25_0.<LoadXmlFileGroup>b__0() 在 C:\Users\wangdongchang\source\repos\autogenerateconfig2\AutoConfig\AutoGenerateConfig\FileParser\XmlParser.cs 中: 第 506 行 在 System.Threading.ThreadHelper.ThreadStart_Context(Object state) 在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 在 System.Threading.ThreadHelper.ThreadStart() 此异常最初是在此调用堆栈中引发的: [外部代码] AutoGenerateConfig.FileParser.FileActions.GetFileXmlDocument(string, System.Xml.XmlDocument) (位于 FileActions.cs 中) AutoGenerateConfig.XmlParser.XmlParser.Xml2Doc(AutoGenerateConfig.ConfigManager.TemplateInfo) (位于 XmlParser.cs 中) AutoGenerateConfig.XmlParser.XmlParser.ADD(AutoGenerateConfig.ConfigManager.TemplateInfo) (位于 XmlParser.cs 中) AutoGenerateConfig.XmlParser.XmlParser.LoadXmlFileGroup.AnonymousMethod__0() (位于 XmlParser.cs 中) [外部代码]
最新发布
08-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值