读取引用另一个xml文件的XML文件

时间:2014-09-11 10:06:52

标签: c# xml linq linq-to-xml

我正在尝试从以下文件中读取XML:

var XmlData = XElement.Load(@"D:\test.xml");

test.xml引用另一个xml文件,如:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE document [ <!ENTITY systems SYSTEM 'file:D:\systems.xml'> ]>
<Root>  
    &systems;
    <Servers>
         <Server>Server1</Server>
         <Server>Server2</Server>
    </Servers>
</Root>

systems.xml

的内容
<Systems>
  <System Id="1" Name="System1" />
  <System Id="2" Name="System2" />
</Systems>

然而,我在XmlData取回的是

<Root>  
    <Servers>
         <Server>Server1</Server>
         <Server>Server2</Server>
    </Servers>
</Root>

如何在阅读systems.xml

时添加test.xml的内容

1 个答案:

答案 0 :(得分:1)

尝试这样的事情:

XmlReaderSettings settings = new XmlReaderSettings();
settings.DtdProcessing = DtdProcessing.Parse;
XmlReader reader = XmlReader.Create("test.xml", settings);

var XmlData = XElement.Load(reader);