1

こんにちは、次の問題が発生しました。を使用して、次のコードからbaseLocation(D:\NewSites\TEST )の値を取得したいと思いますlinq。いくつか試してみましたが、うまくいかないようです。これがどのように行われるかについてのアイデアはありますか?前もって感謝します。トラストス

私はこのようなものから始めましたが、これはnullを返しました

XDocument document = XDocument.Load("C:\\web.config");
var dataList = from item in document.Descendants("configuration") select item;

ここに私のXMLがあります

<?xml version="1.0"?>
<configuration>
    <configSections>
    </configSections>
    <log4net>
    </log4net>
    <web>
        <website runtimeMode="Development" siteName="TEST" baseLocation="D:\NewSites\TEST"      sitePath="D:\NewSites\TEST\WebApps\Website" siteUri="http://test.co.uk" s    iteEmail="test@gmail.com" />
        <cms defaultTemplate="TEST\Content.aspx" templatesUrl="/Manager/Templates/">
        <publishingLocations>
            <publishingLocation name="TEST" uri="http://test.co.uk" path="WebApps\Website" />
        </publishingLocations>
        <redirectables />
        <searchEngineSiteMapNotifications />
        <siteMapXmlUrls />
        <pingServices />
        <reservedTemplates />
        <templateFilters />
        </cms>
    </web>
    <location path="Manager">
    </location>
    <connectionStrings>
    </connectionStrings>
    <system.web>
    </system.web>
</configuration>
4

3 に答える 3

1
This will do the task:

XmlDocument xml = new XmlDocument();
xml.Load(@"location of xml/config");//  xml.Load(@""~/web.config");
XmlNode node = xml.DocumentElement.SelectSingleNode("//website");
Response.Write(node.Attributes["baseLocation"].Value);

さらにサポートが必要な場合はお知らせください。または、役に立った場合はマークしてください。

于 2013-04-10T08:51:57.317 に答える
0

これはどう:

string baseLocation = document.Descendants("website").First().Attribute("baseLocation").Value;
于 2013-04-10T08:54:37.857 に答える