我们可以将XML文件导入另一个XML文件吗?

我们可以将一个XML文件导入另一个XML文件吗?

我的意思是说,在XML中是否有任何导入标记,它将XML路径作为参数并导入XML(为其提供路径)。


茅侃侃
浏览 702回答 3
3回答

莫回无

Mads Hansen的解决方案很好,但是要成功读取.NET 4中的外部文件,需要花费一些时间来弄清楚使用有关解析程序,ProhibitDTD等的注释中的提示。这是这样做的:&nbsp; &nbsp; &nbsp; &nbsp; XmlReaderSettings settings = new XmlReaderSettings();&nbsp; &nbsp; &nbsp; &nbsp; settings.DtdProcessing = DtdProcessing.Parse;&nbsp; &nbsp; &nbsp; &nbsp; XmlUrlResolver resolver = new XmlUrlResolver();&nbsp; &nbsp; &nbsp; &nbsp; resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;&nbsp; &nbsp; &nbsp; &nbsp; settings.XmlResolver = resolver;&nbsp; &nbsp; &nbsp; &nbsp; var reader = XmlReader.Create("logfile.xml", settings);&nbsp; &nbsp; &nbsp; &nbsp; XmlDocument doc = new XmlDocument();&nbsp; &nbsp; &nbsp; &nbsp; doc.Load(reader);&nbsp; &nbsp; &nbsp; &nbsp; foreach (XmlElement element in doc.SelectNodes("//event"))&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var ch = element.ChildNodes;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var count = ch.Count;&nbsp; &nbsp; &nbsp; &nbsp; }logfile.xml:<?xml version="1.0"?><!DOCTYPE logfile [<!ENTITY events&nbsp; &nbsp;&nbsp;&nbsp;SYSTEM "events.txt">]><logfile>&events;</logfile>events.txt:<event>&nbsp; &nbsp; <item1>item1</item1>&nbsp; &nbsp; <item2>item2</item2></event>
打开App,查看更多内容
随时随地看视频慕课网APP