如何使用xml文件 [英] How to work with xml files

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

问题描述



我需要一个代码来从保存在本地驱动器中的文件夹中的一组xml中搜索某些文本,并显示其中包含匹配文本的xml文件的名称!

请整理一下!

Hi,

I need a code to search a certain text from a set of xmls in a folder saved to my local drive and display the name of the xml file that has the matching text in it !

Kindly, sort it out !

推荐答案

您好

您可以使用循环方法读取每个xml文件,然后在xml中有可用文本的情况下,在另一个控件中获取文件名,否则可以移动到另一个文件,直到所有文件完成.

试试下面的代码

TextBox1.Text ="Books"&环境换行"Books2"
昏暗arrFiles()为字符串= TextBox1.Text.Split(Environment.NewLine)

对于arrFiles中的每个f作为字符串
将阅读器用作新的Xml.XmlTextReader(String.Format("C:\ Temp \ {0} .xml",f))
而reader.Read()
''做某事
结束时
最终使用
下一页
Hi

You can read the each xml file using loop method, then fetch the file name in another control if the text is available in the xml else you can move to another file until the all files complete.

Try the below code

TextBox1.Text = "Books" & Environment.NewLine & "Books2"
Dim arrFiles() As String = TextBox1.Text.Split(Environment.NewLine)

For Each f As String In arrFiles
Using reader As New Xml.XmlTextReader(String.Format("C:\Temp\{0}.xml", f))
While reader.Read()
''Do Something
End While
End Using
Next


请在下面查看我的概述:

Please see my overview below:


  1. 使用System.Xml.XmlDocument类.它实现了DOM接口;如果文档太大,则这种方法最简单,也足够好.
    请参见 http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx [ http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx [ http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx [http://msdn.microsoft.com/en-us/library/bb387063.aspx [

  1. Use System.Xml.XmlDocument class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^].
  2. Use the classes System.Xml.XmlTextWriter and System.Xml.XmlTextReader; this is the fastest way of reading, especially is you need to skip some data.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx[^], http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^].
  3. Use the class System.Xml.Linq.XDocument; this is the most adequate way similar to that of XmlDocument, supporting LINQ to XML Programming.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].



—SA



—SA


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

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