<?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>
의 인스턴스로 설정되지 않았습니다 그리고이 파일을 새로운 데이터 쓰기 :XML : 개체 참조가 개체
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);
하지만 내가 얻을 :
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);
라인 51시 빨간색으로. 나를 도와 주실 수있으세요?
은 (Web.sitemap 내가 루트 파일 내가가 someting /가 someting/Someting.aspx에있는 코드에서, 그래서 adrress 내가 생각하는 올바른 것입니다.)
** 예외 스택 추적 ** 표시. – Aliostad
내 해결책을 확인하십시오. 그것은 작동, 나는 그것을 테스트했습니다. –