Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1051589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:57:30+00:00 2026-05-16T16:57:30+00:00

Normally I write a class and add XML Serialization to it for my web

  • 0

Normally I write a class and add XML Serialization to it for my web services.

[XmlRootAttribute(ElementName = "dsXmlSummary", IsNullable=true)]
public class Class1
{
    //declare properties
    //make database calls to pull data and load properties
}

I am working on a project that requires me to use a strict XSD, I’ve followed instructions on using the XSD.EXE tool to create a class based on the XSD. My interpretation was that this auto-generated class would replace my normal serialized class.

If this is the case I am completely lost on loading the data into the class properties.
I’ve gathered this from another walk through:

[WebMethod]
public dsXmlSummary getXML()
{
    TextReader reader = new StreamReader("data.xml");
    dsXmlSummary ds = (dsXmlSummary)serializer.Deserialize(reader);
    reader.Close();
}

However the data I have is located in a SQL database…I figured I should be able to write a method to fill the dsXmlSummary class, however I cannot find any documentation on doing this. All examples are like the above, loading or reading from an actual physical xml document.

I tried testing out a manual load:

    [WebMethod]
    public dsXmlSummary getXML()
    {
        dsXmlSummary xml = new dsXmlSummary();
        xml.Items[0].nameFirst = "Mark"; //error thrown here: System.NullReferenceException: Object reference not set to an instance of an object.
        xml.Items[0].nameLast = "Twain";
        xml.Items[0].Type = "Writer";

        return xml;
    }

Obviously I’m going about this all wrong. Any guidance is greatly appreciated.

EDIT

My WebMethod

        [WebMethod]
    public dsXmlSummary getXML()
    {
        dsXmlSummary xml = new dsXmlSummary();
        dsXmlSummaryAdmin_reports_xmlReports[] items = new dsXmlSummaryAdmin_reports_xmlReports[1];
        items[0].nameFirst = "Mark"; //error still thrown here: System.NullReferenceException: Object reference not set to an instance of an object.
        items[0].nameLast = "Twain";
        items[0].Type = "Writer";

        xml.Items = items;
        return xml;
    }

The Auto generated class

public partial class dsXmlSummary {

private dsXmlSummaryAdmin_reports_xmlReports[] itemsField;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("admin_reports_xmlReports")]
public dsXmlSummaryAdmin_reports_xmlReports[] Items {
    get {
        return this.itemsField;
    }
    set {
        this.itemsField = value;
    }
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T16:57:30+00:00Added an answer on May 16, 2026 at 4:57 pm

    If you get your XML from the database as a string you can use a StringReader. Or if you get a byte[] you may try a MemoryStream.

    [WebMethod]
    public dsXmlSummary getXML()
    {
        TextReader reader = new StringReader("<dsXmlSummary><FirstName>Mark</FirstName></dsXmlSummary>");
        dsXmlSummary ds = (dsXmlSummary)serializer.Deserialize(reader);
        reader.Close();
    }
    

    Regarding your “manual” example you need to initialize your Items array.
    <edit> Added xml.Items[0] = new YourItemsType();</edit>

    [WebMethod]
    public dsXmlSummary getXML()
    {
        dsXmlSummary xml = new dsXmlSummary();
        xml.Items = new YourItemsType[1];    // <-- initialize here
        xml.Items[0] = new YourItemsType();  // <-- initialize first object
        xml.Items[0].nameFirst = "Mark"; //error thrown here: System.NullReferenceException: Object reference not set to an instance of an object.
        xml.Items[0].nameLast = "Twain";
        xml.Items[0].Type = "Writer";
    
        return xml;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Normally when you write a template class and have a specialization of a function
I normally write code with tabs but many python libraries use spaces. Is there
Normally when I want to query large result set using Mysql I write this
I want to write a CMakeLists.txt so that I can run my tests normally
Normally the XML files I have to parse are like this: <row id=1> <title>widget<title>
In languages like C++ or Objective-C a class normally consist of two files. The
Normally if I had Class 1 and I wanted to use it elsewhere, I
I am preparing to write my first web crawler, and it looks like Anemone
In my compilers class, I decided to write my compiler in Python since I
Take this sample code: Class Foo ReadOnly name As String Public Sub New(name As

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.