C# 如何从以下文件中读取xml元素?

C# 如何从以下文件中读取xml元素?,c#,xml,C#,Xml,我有下面的xml文件,我正在尝试读取我无法读取的name元素,知道如何读取该元素和其他元素吗 <?xml version="1.0" encoding="us-ascii"?> <WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1"> <name>tata</name> <SSIDConfig> <SSID&g

我有下面的xml文件,我正在尝试读取我无法读取的
name
元素,知道如何读取该元素和其他元素吗

<?xml version="1.0" encoding="us-ascii"?>
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
    <name>tata</name>
    <SSIDConfig>
        <SSID>
            <name>SampleSingleSignOn</name>
        </SSID>
    </SSIDConfig>
    <connectionType>ESS</connectionType>
    <connectionMode>auto</connectionMode>
    <autoSwitch>false</autoSwitch>
    <MSM>
        <security>
            <authEncryption>
                <authentication>WPA2</authentication>
                <encryption>AES</encryption>
                <useOneX>true</useOneX>
            </authEncryption>
            <OneX xmlns="http://www.microsoft.com/networking/OneX/v1">
                <cacheUserData>true</cacheUserData>
                <maxAuthFailures>3</maxAuthFailures>
                <authMode>user</authMode>
                <singleSignOn>
                    <type>preLogon</type>
                    <maxDelay>10</maxDelay>
                </singleSignOn>
                <EAPConfig>
                    <EapHostConfig xmlns="http://www.microsoft.com/provisioning/EapHostConfig"
                                        xmlns:eapCommon="http://www.microsoft.com/provisioning/EapCommon"
                                        xmlns:baseEap="http://www.microsoft.com/provisioning/BaseEapMethodConfig">
                        <EapMethod>
                            <eapCommon:Type>25</eapCommon:Type>
                            <eapCommon:AuthorId>0</eapCommon:AuthorId>
                        </EapMethod>
                        <Config xmlns:baseEap="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1"
                                  xmlns:msPeap="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV1"
                                  xmlns:msChapV2="http://www.microsoft.com/provisioning/MsChapV2ConnectionPropertiesV1">
                            <baseEap:Eap>
                                <baseEap:Type>25</baseEap:Type>
                                <msPeap:EapType>
                                    <msPeap:ServerValidation>
                                        <msPeap:DisableUserPromptForServerValidation>false</msPeap:DisableUserPromptForServerValidation>
                                        <msPeap:TrustedRootCA />
                                    </msPeap:ServerValidation>
                                    <msPeap:FastReconnect>true</msPeap:FastReconnect>
                                    <msPeap:InnerEapOptional>0</msPeap:InnerEapOptional>
                                    <baseEap:Eap>
                                        <baseEap:Type>26</baseEap:Type>
                                        <msChapV2:EapType>
                                            <msChapV2:UseWinLogonCredentials>true</msChapV2:UseWinLogonCredentials>
                                        </msChapV2:EapType>
                                    </baseEap:Eap>
                                    <msPeap:EnableQuarantineChecks>false</msPeap:EnableQuarantineChecks>
                                    <msPeap:RequireCryptoBinding>false</msPeap:RequireCryptoBinding>
                                    <msPeap:PeapExtensions />
                                </msPeap:EapType>
                            </baseEap:Eap>
                        </Config>
                    </EapHostConfig>
                </EAPConfig>
            </OneX>
        </security>
    </MSM>
</WLANProfile>

它返回
null
元素。

您必须考虑XML名称空间:

XNamespace ns = "http://www.microsoft.com/networking/WLAN/profile/v1";
XElement name = xdoc.Root.Element(ns + "name");

您必须考虑XML名称空间:

XNamespace ns = "http://www.microsoft.com/networking/WLAN/profile/v1";
XElement name = xdoc.Root.Element(ns + "name");