John
John

Reputation: 3402

XmlDocument missing Load method in .Net Core?

I'm creating a Console App, .Net Core 1.1, and am trying to read an XML file. I brought in the System.Xml.XmlDocument nuGet package, created an XmlDocument, and then attempted to load using the file name. To my surprise, there is no overload for Load(string). See the attached image from the object browser. Is this permanently gone? I tried finding documentation, but was unsuccessful and mainly just found information like here

using System;
using System.Xml;
using System.Xml.Linq;

namespace ReadingXmlDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            XmlDocument doc = new XmlDocument();
            string content =
            doc.Load("Example.xml");

enter image description here

Upvotes: 1

Views: 2264

Answers (2)

impactro
impactro

Reputation: 604

see simple exemple:

string sourceFileXML = @"c:\temp\file.xml";
var xml = new XmlDocument();
using (var sr = new StreamReader(sourceFileXML)) {
    xml.Load(sr);
}

Upvotes: 0

Martin Ullrich
Martin Ullrich

Reputation: 100641

The XmlDocument.Load(string) method is part of .NET Core 2.0 and .NET Standard 2.0. For .NET Core 1.*, you'll need to use the Load(Stream) method and pass it FileStream obtained via File.Open.

You can check the availability of the method at API .NET Catalog for System.Xml.XmlDocument.Load(String)

Upvotes: 2

Related Questions