User1
User1

Reputation: 13

System.Xml in visual studio not working

I am trying to process XML with C# in Visual Studio and it will not allow me to import System.Xml. I looked at other posts about this problem and this was usually caused by misspelling System.Xml to System.XML. I have the right spelling so I am not sure what is causing me problems. I looked under references and there is no System.Xml and I am using Visual Studio 2013 The error message was
Error 1 The type or namespace name 'Xml' does not exist in the namespace 'System' (are you missing an assembly reference?)

Do I have to download System.Xml?

Here is the code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace WebTesting
{
    class Test1
    {
        public static void Main(string [] args)
        {
            using(XmlReader reader = XmlReader.Create("myData.Xml"))
            {
                while(reader.Reader())
                {
                    if(reader.IsStartElement())
                    {
                        Console.Write("The start element is " + reader.ReadString());
                    }

                }

            }

            Console.ReadLine();
        }
    }
}

Upvotes: 0

Views: 6964

Answers (2)

Miguel Rodriguez
Miguel Rodriguez

Reputation: 299

by using XDocument (in using System.Xml.Linq;) you'll get more flexible functionality to handling XML-documents

Upvotes: 0

adv12
adv12

Reputation: 8551

You'll need to add an assembly reference. Right-click "References" under your project in Solution Explorer and select "Add Reference..." Switch to the .NET tab and find System.Xml. Click OK.

Upvotes: 5

Related Questions