我需要在 XML 文档中搜索我网站的特定 url 名称。
这样当用户浏览我的网站时,他们所在的任何页面都会决定侧边菜单的外观。到目前为止,这是我的代码:
var urlName = Path.GetFileNameWithoutExtension(Request.Url.AbsolutePath);
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(Server.MapPath("~/App_Data/menu.xml"));
xmlDocument.SelectNodes("//*[contains(text(), 'urlName')]");
一旦找到,我希望结果返回该网站节点和父节点。
<menu type="personal">
<L1 shortName="Something here" id="/personal/something-here.aspx" url="../personal/something-here.aspx" regions="123">
<L2 shortName="anything here" id="/personal/anything-here.aspx" url="../personal/anything-here.aspx" regions="123">
<L3 shortName="everything here" id="/personal/everything-here.aspx" url="../personal/everything-here.aspx" regions="123"/>
</L2>
<L2 shortName="something" id="/personal/something.aspx" url="../personal/something.aspx" regions="123">
<L3 shortName="anything" id="/personal/anything.aspx" url="../personal/anything.aspx" regions="123" />
<L3 shortName="everything" id="/personal/everything.aspx" url="../personal/everything.aspx" regions="123" />
</L2>
</L1>
</menu>