We help IT Professionals succeed at work.

xmlwriter not recognised

peterdungan
peterdungan asked
on
Hi
I'm looking at an example use of the xmlwriter in .net 2.0.
When I compile the code shown, I get errors like

The type or namespace name 'XmlWriterSettings' could not be found (are you missing a using directive or an assembly reference?)      

Why is this happening please? Do I need to add a reference to the project?

Thanks
<%@ WebHandler Language="C#" Class="Handler" %>
 
using System;
using System.Web;
 
public class Handler : IHttpHandler {
 
    public void ProcessRequest(HttpContext context)
    {
        XmlWriterSettings settings = new XmlWriterSettings();
        settings.Indent = true;
 
        context.Response.ContentType = "text/xml";
 
        using (XmlWriter writer = XmlWriter.Create(context.Response.OutputStream, settings))
        {
            writer.WriteStartElement("slides");
            writer.WriteStartElement("slide");
            writer.WriteAttributeString("imageUrl", "foo.jpg");
            writer.WriteAttributeString("thumbnailUrl", "foo_thumb.jpg");
            writer.WriteAttributeString("caption", "this is a test");
            writer.WriteEndElement();
            writer.WriteEndElement();
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }
 
}

Open in new window

Comment
Watch Question

It works after adding using system.xml to the references.

Jaime OlivaresSoftware Architect
CERTIFIED EXPERT
Top Expert 2008

Commented:
You will need:

using System.Xml;

at the beginning of your source code file, and also check the project References, as peter stated.
Jaime OlivaresSoftware Architect
CERTIFIED EXPERT
Top Expert 2008

Commented:
to be more specific, go to Menu -> Project -> Add Reference... -> .net tab
Check if System.Xml.dll reference is checked.

Author

Commented:
Yes thanks I realised that and posted the reply above.
Jaime OlivaresSoftware Architect
CERTIFIED EXPERT
Top Expert 2008

Commented:
sorry, not noticed, that you was the question's author.