C#从XML文件中获取标记数据(包括内部标记)
我有以下XML文件:C#从XML文件中获取标记数据(包括内部标记),c#,xml,string,C#,Xml,String,我有以下XML文件: <organizations default="pre-test_organization"> <organization identifier="data"> <title>Date</title> <item identifier="5BD294BF-0722-45FC-B888-9F31CD076BF9" ident
<organizations default="pre-test_organization">
<organization identifier="data">
<title>Date</title>
<item identifier="5BD294BF-0722-45FC-B888-9F31CD076BF9" identifierref="resource">
<title>Reference</title>
</item>
</organization>
</organizations>
<resources>
<resource identifier="resource" type="webcontent" adlcp:scormtype="sco" href="res/index.html">
<file href="res/data/apple-touch-icon.png"/>
<file href="res/data/browsersupport.js"/>
</resource>
</resources>
返回(上下文正确):
而不是(我真正想要的):
参考
尝试获取InnerXml
var node = doc.SelectSingleNode("/organizations/organization/item").InnerXml;
或
最好使用LINQ转换为XML。自2007年以来,它在.Net Framework中可用。
Reference
<title>Reference</title>
var node = doc.SelectSingleNode("/organizations/organization/item").InnerXml;
var lst = root.GetElementsByTagName("item")[0].InnerXml;