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 7008249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:42:38+00:00 2026-05-27T21:42:38+00:00

I have this code that is supposed to load the attributes of an XML

  • 0

I have this code that is supposed to load the attributes of an XML file to a string variable when the user clicks a button:

    public void Button1_Click(object sender, EventArgs e)
    {
        XDocument doc = XDocument.Load("C:/Structure.xml");
        Visit(doc.Root);


    }

    public static void Visit(XElement element)
    {

        string siteURL1 = element.Attribute("URL").Value;
        string siteTitle1 = element.Attribute("siteTitle").Value;
        string siteDescription1 = element.Attribute("siteDescription").Value;
        string siteTemplate = element.Attribute("siteTemplate").Value;
        string name = element.Attribute("type").Value;
        Execute(name, siteURL1, siteTitle1, siteDescription1, siteTemplate); 
}

But when I deploy the webpart, and click the button, I get the “NullreferenceException was unhandled by user code / Object reference not set to an instance of an object” errors. on:

  string siteURL1 = element.Attribute("URL").Value;" 

Any idea of what I may be doing wrong?

This is what the structure looks something like this:

<root>
  <level1 name="level1A"
          type="Private"
          template="3 
          siteTitle="Private"
          siteDescription="Private Site"  
          URL"private">
    <level2 name="level2A">
      <level3 name="level3A">
        <level4 name="level4A">
          <level5 name="level5A">
            <level6 name="level6A">
              <level7 name="level7A">
                <level8 name="level8A"></level8>
              </level7>
            </level6>
          </level5>
        </level4>
      </level3>
    </level2>
  </level1>
</root> 
  • 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-27T21:42:39+00:00Added an answer on May 27, 2026 at 9:42 pm

    One of two things I could see being wrong…

    Either the object element is null

    or

    the attribute URL doesn’t exist for that element

    Try something like…

    var url = element.Attribute("URL");
    string siteURL1;
    
    if(url != null)
    {
       siteURL1 = url.Value;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code that has one button that let's me choose an entry
I have this code that saves a pdf file. FileStream fs = new FileStream(SaveLocation,
I have this javascript code below that uses jquery, it is suppoed to be
I have this code that performs an ajax call and loads the results into
I have this code that works in a unit test but doesn't work when
I have this code that I want to make point-free; (\k t -> chr
I have this code that fetches some text from a page using BeautifulSoup soup=
I have this code that changes the opacity of the div on hover. $(#navigationcontainer).fadeTo(slow,0.6);
So I have this code that takes care of command acknowledgment from remote computers,
Challenge: I have this code that fails to compile. Can you figure out what's

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.