既然你有两个
XDocument
,对于每个示例xml,调用
doc1
和
doc2
分别是,那么这个代码:
var ns1 = doc1.Root.GetDefaultNamespace();
var ns2 = doc2.Root.GetDefaultNamespace();
var functionCode1 = doc1.Root.Descendants(ns1 + "FunctionCode").First().Value;
var functionCode2 = doc2.Root.Descendants(ns2 + "FunctionCode").First().Value;
Console.WriteLine(functionCode1);
Console.WriteLine(functionCode2);
…生产:
FunctionCode1
FunctionCode2
因此,如果您有一个这种格式的未知xml文档,一般情况是:
var ns = doc.Root.GetDefaultNamespace();
var functionCode = doc.Root.Descendants(ns + "FunctionCode").First().Value;