I have a code needed to load an XML document from a reader, something like this:
private static XmlDocument GetDocumentStream(string xmlAddress)
{
var settings = new XmlReaderSettings();
settings.DtdProcessing = DtdProcessing.Ignore;
settings.ValidationFlags = XmlSchemaValidationFlags.None;
var document = new XmlDocument();
var reader = XmlReader.Create(xmlAddress, settings);
document.Load(reader);
return document;
}
But in my XML document, 开发者_运维百科I have nodes like this one:
<link rel="edit-media" title="Package"
href="Packages(Id='51Degrees.mobi',Version='0.1.11.9')/$value" />
Is to my understanding that the node should be like
<link rel="edit-media" title="Package"></link>
But, I don't create the Xml document and I certainly don't want to change it, but when I try to load the XML document, the document.Load line throws an exception. To be more specific, the XML file is the RSS source for the nuPack project.
Any ideas would be very appreaciated on how to be able to read this document properly.
In my screnario I use WebClient class to download the data and load it into a stream that is loaded by XmlDocument directly:
private static System.Xml.XmlDocument GetDocumentStream(string xmlAddress)
{
System.Xml.XmlDocument document;
byte[] xmlBlob = new System.Net.WebClient().DownloadData(xmlAddress);
using (System.IO.MemoryStream temp = new System.IO.MemoryStream(xmlBlob))
{
document = new System.Xml.XmlDocument();
document.Load(temp);
}
return document;
}
So I have an offline copy as byte array and do not need to parse it over an XML validator.
精彩评论