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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:01:59+00:00 2026-05-21T02:01:59+00:00

<?xml version=1.0 encoding=utf-8 ?> <siteMap xmlns=http://schemas.microsoft.com/AspNet/SiteMap-File-1.0 > <siteMapNode url=~/ title=Úvodní stránka> <siteMapNode url=Pocitace title=Počítače

  • 0
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
    <siteMapNode url="~/" title="Úvodní stránka">
        <siteMapNode url="Pocitace" title="Počítače" />
        <siteMapNode url="Elektronika" title="Elektronika" />
    </siteMapNode>
</siteMap>

And I write to this file new data:

XmlDocument originalXml = new XmlDocument();
originalXml.Load(Server.MapPath("../../Web.sitemap"));
XmlAttribute title = originalXml.CreateAttribute("title");
title.Value = newCategory;
XmlAttribute url = originalXml.CreateAttribute("url");
url.Value = seoCategory;
XmlNode newSub = originalXml.CreateNode(XmlNodeType.Element, "siteMapNode", null);
newSub.Attributes.Append(title);
newSub.Attributes.Append(url);
originalXml.SelectSingleNode("siteMapNode").AppendChild(newSub);

But I get:

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error: 
Line 49: newSub.Attributes.Append(title);
Line 50: newSub.Attributes.Append(url);
Line 51: originalXml.SelectSingleNode("siteMapNode").AppendChild(newSub);

Line 51 si red. Can u help me?

(Web.sitemap i have in root file and code I have in Someting/Someting/Someting.aspx, so adrress is correct i think.)

  • 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-21T02:01:59+00:00Added an answer on May 21, 2026 at 2:01 am

    The call to originalXml.SelectSingleNode("siteMapNode") returns null. You need to specify the namespace.

    Update:
    Use this code instead of the line that throws the exception (Line 51):

    XmlNamespaceManager nsmanager = new XmlNamespaceManager(originalXml.NameTable);
    nsmanager.AddNamespace("x", "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0");
    originalXml.SelectSingleNode("x:siteMap/x:siteMapNode", nsmanager).AppendChild(newSub);
    

    Explanation:
    You made two mistakes:

    1. Your XPath query to find the siteMapNode was not correct. The way you wrote it, it looked only at the root tag for the tag with the name “siteMapNode”
    2. The root tag “siteMap” specifies a namespace. You need to use that namespace in your call to SelectSingleNode
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this sitemap: <?xml version=1.0 encoding=utf-8 ?> <siteMap xmlns=http://schemas.microsoft.com/AspNet/SiteMap-File-1.0> <siteMapNode> <siteMapNode url=www.google.com title=Google
in my Web.sitemap I have this: <?xml version=1.0 encoding=utf-8?> <siteMap xmlns=http://schemas.microsoft.com/AspNet/SiteMap-File-1.0> <siteMapNode url=~/ title=Úvodní
I have sitemap which looks like this: <?xml version=1.0 encoding=utf-8 ?> <siteMap xmlns=http://schemas.microsoft.com/AspNet/SiteMap-File-1.0 >
I have this XML at http://localhost/file.xml : <?xml version=1.0 encoding=utf-8?> <val:Root xmlns:val=http://www.hw-group.com/XMLSchema/ste/values.xsd> <Agent> <Version>2.0.3</Version>
Here's the XML: <?xml version='1.0' encoding='UTF-8' standalone='yes' ?> <feed xmlns=http://www.w3.org/2005/Atom xmlns:dc=http://purl.org/dc/elements/1.1/> <title>Rated Images</title> <link
I need so generate XML like the following: <?xml version=1.0 encoding=UTF-8 standalone=yes?> <urlset xmlns=http://www.sitemaps.org/schemas/sitemap/0.9
have an xml file like this. <?xml version =1.0 encoding =utf-8?> <menu> <menuNode title=Register
I have the generic structure here: <?xml version=1.0 encoding=UTF-8?> <SOAP-ENV:Envelope xmlns:xsi= http://www.w3.org/2001/XMLSchema-instance xmlns:SOAP-ENC=http://schemas.xmlsoap.org/soap/encoding/ xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/
I have an XML file that looks like <?xml version='1.0' encoding='UTF-8'?> <root> <node name=foo1
I created an App.config file in my WPF application: <?xml version="1.0" encoding="utf-8" ?> <configuration>

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.