[英]C# XmlDocument.LoadXml And Wildcards
I have an asp.net application and I'm using C#. 我有一个asp.net应用程序,正在使用C#。 I want to use the XmlDocument.LoadXml() method to read from an .xml file.
我想使用XmlDocument.LoadXml()方法从.xml文件读取。 However, the xml file will not always have the same name so I wanted to pass into the LoadXml() method the path to the file and then read any .xml files that are inside.
但是,该xml文件不会总是具有相同的名称,因此我想将文件的路径传递给LoadXml()方法,然后读取其中的任何.xml文件。 So, something like this LoadXml(C:\\Docs*.xml).
因此,类似这样的LoadXml(C:\\ Docs * .xml)。 It doesn't work for me.
它对我不起作用。 Is there another way I can accomplish this?
我还有另一种方法可以做到这一点吗?
You need to separate out the "loading XML from a file" from "picking which file to load". 您需要从“选择要加载的文件”中分离出“从文件加载XML”。 The two are unrelated concepts.
两者是不相关的概念。 (Although I would point out that
XmlDocument.LoadXml
takes raw XML as a string, not a filename. I think you want XmlDocument.Load
.) (尽管我会指出
XmlDocument.LoadXml
将原始XML作为字符串而不是文件名。我认为您需要XmlDocument.Load
。)
What do you want to happen if there's more than one XML document in c:\\Docs
? 如果
c:\\Docs
有多个XML文档,您想怎么办? XmlDocument
can only load one of them. XmlDocument
只能加载其中之一。
Use Directory.GetFiles(@"C:\\Docs", "*.xml")
to get the list of matching files in the directory. 使用
Directory.GetFiles(@"C:\\Docs", "*.xml")
获取目录中匹配文件的列表。 What you should do if there's more than one of them (or none) is up to you. 如果其中一个(或以上)不止一个,该怎么办取决于您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.