【发布时间】:2017-02-19 21:48:47
【问题描述】:
我有以下简单的 XML 文件:
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit http://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>False</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<publishUrl>E:\PublishTest</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
</PropertyGroup>
</Project>
我正在尝试通过执行以下操作来更改其中一个元素的值:
XmlDocument xDoc = new XmlDocument();
xDoc.Load(fullPathToPortalPublishSettings);
// Change the publish url to be the one we want
var a = xDoc.SelectNodes("/Project/PropertyGroup");
但它总是会爆炸。我已经删除了 XML 文件顶部的 cmets,我只尝试了 /Project,只是 Project,但我似乎无法理解出了什么问题。我看过其他帖子,但看不到我的问题。任何想法?谢谢!
【问题讨论】:
-
丢失尾部斜杠以使其成为
/Project/PropertyGroup或实际选择孩子:/Project/PropertyGroup/* -
抱歉,我应该提到我也尝试过 "xDoc.SelectNodes("/Project"),但即使这样也没有任何效果。
-
您在手表中检查过 xDoc 吗?它包含您的期望吗?
-
是的,那里有文档,根为#document。不过,我不知道出了什么问题。
-
啊,命名空间...@see stackoverflow.com/questions/4171451/…
标签: c# .net xml xmldocument selectnodes