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

  • Home
  • SEARCH
  • 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 6069745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:51:19+00:00 2026-05-23T09:51:19+00:00

Here is my XML document that is passed into the CreateListOfAddresses() method: <?xml version=1.0?>

  • 0

Here is my XML document that is passed into the CreateListOfAddresses() method:

<?xml version="1.0"?>
    <AddressValidateResponse>
        <Address ID="0">
        <Address2>8 WILDWOOD DR</Address2>
        <City>OLD LYME</City>
        <State>CT</State>
        <Zip5>06371</Zip5>
        <Zip4>1844</Zip4>
    </Address>
</AddressValidateResponse>

Here is my method:

    private List<AddressBlockResponse> CreateListOfAddresses(XmlDocument xmlDoc)
    {
        // Convert XML document to xdocument so we can use LINQ.
        XDocument xDoc = xmlDoc.ToXDocument();

        var address = from a in xDoc.Descendants("AddressValidateResponse")
                      select new AddressBlockResponse
                      {
                          Order = int.Parse(a.Attribute("ID").Value),
                          AddressLine2 = a.Element("Address2").Value,
                          City = a.Element("City").Value,
                          State = a.Element("State").Value,
                          ZipCode = a.Element("Zip5").Value,
                          ZipPlus4 = a.Element("Zip4").Value
                      };
        return address.ToList();
    }

Here is the extension method that converts my XML document to an XDocument type:

public static XDocument ToXDocument(this XmlDocument xmlDocument)
{
    using (var nodeReader = new XmlNodeReader(xmlDocument))
    {
        nodeReader.MoveToContent();
        return XDocument.Load(nodeReader);
    }
}

Here is my object:

[Serializable]
public struct AddressBlockResponse
{
    // Standardized address returned from the service
    [DataMember(IsRequired = true)]
    public int Order;

    [DataMember(IsRequired = true)]
    public string AddressLine1;

    [DataMember(IsRequired = false)]
    public string AddressLine2;

    [DataMember(IsRequired = true)]
    public string City;

    [DataMember(IsRequired = true)]
    public string State;

    [DataMember(IsRequired = true)]
    public string ZipCode;

    [DataMember(IsRequired = true)]
    public string ZipPlus4;
}

Here is my problem: the CreateListOfAddresses() method returns

Enumeration yielded no results

What am I doing wrong?

  • 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-23T09:51:20+00:00Added an answer on May 23, 2026 at 9:51 am

    It looks like your issue is that AddressValidateResponse is the root node of your document.

    You should change it to:

    var address = from a in xDoc.Descendants("Address")
                      select new AddressBlockResponse
                      {
                          // stuff
                      };
    

    Also when you are using xelements like

    City = a.Element("City").Value,
    

    You should do:

    City = (string)a.Element("City"),
    

    because if the element doesn’t exist your program will throw a null reference exception. I know you will probably always have these xml nodes but I think it is just a good habit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got an XML document that gives me addresses. Here's an excerpt: <ezi:orderaddresses> <ezi:orderaddress>
Here's the deal. I have an XML document with a lot of records. Something
Here is my sample code: from xml.dom.minidom import * def make_xml(): doc = Document()
I have the following XML document that I have to parse using python's minidom:
I have an XML document (an InfoPath form) that looks similar to this: <my:ClientMaintenance
I'm getting an error here that says I haven't defined a method, but it
I have an XML document that looks like this: <file> <name>NAME_OF_FILE</name> </file> <file> <name>NAME_OF_FILE</name>
I have an xml document that contains some html. <begin-line> <verse-num>6</verse-num>a mixed people<footnote id=f2>
I have XML document that I parse with jDOM and then try to take
I have an xml document that contains spaces and equal signs in the node

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.