C# 如何在xml中获取节点的内部值

C# 如何在xml中获取节点的内部值,c#,xml,xml-parsing,C#,Xml,Xml Parsing,我有一个类似于: <Employee> <Name> XXXX </Name> <Address> YYYY </Addeess> <Country> ZZZZ </Country> </Employee> XXXX YYYY ZZZZ 我怎样才能获得国家的内在价值?此处动态生成国家(基于用户输入) 它可能存在也可能不存在。如果存在,我需要使用c#获取内部值。这可能会帮助您: XmlDocume

我有一个类似于:

<Employee>
<Name> XXXX </Name>
<Address> YYYY </Addeess>
<Country> ZZZZ </Country>
</Employee>

XXXX
YYYY
ZZZZ
我怎样才能获得国家的内在价值?此处动态生成国家(基于用户输入)

它可能存在也可能不存在。如果存在,我需要使用c#获取内部值。

这可能会帮助您:

XmlDocument ob = new XmlDocument();
ob.Load("yourxmlfile.xml");
XmlNodeList obj_country = ob.GetElementsByTagName("Country");
  if(obj_country!= null)
     {
        string innertext_country_node = obj_country[0].InnerText;
     }
这可能会帮助您:

XmlDocument ob = new XmlDocument();
ob.Load("yourxmlfile.xml");
XmlNodeList obj_country = ob.GetElementsByTagName("Country");
  if(obj_country!= null)
     {
        string innertext_country_node = obj_country[0].InnerText;
     }

你在哪里陷入了这样的代码?你在哪里陷入了这样的代码?我试着像
XmlDocument xdoc=newxmldocument();LoadXml(xmlpath);var countryElement=XElement.Parse(xdoc.Element)(“国家”);字符串结果=(countryElement!=null)?countryElement.Value:string.Empty它不允许解析(xdoc)说的参数无效。@用户1658567:如果从文件加载,请使用load,而不是Parse。我试过像
XmlDocument xdoc=new XmlDocument();LoadXml(xmlpath);var countryElement=XElement.Parse(xdoc.Element)(“国家”);字符串结果=(countryElement!=null)?countryElement.Value:string.Empty它不允许解析(xdoc)说的参数无效。@user1658567:如果从文件加载,请使用load,而不是Parse