我正在处理XML文档并提取它的特定部分以创建新对象。我已经处理过导航到doc-number和date(appNumber& appDate属性)。但是,我无法浏览申请人的姓名。
通过在运行时查看局部变量,我可以看到我已设法导航到正确的元素,但是我似乎无法从中获取名称值。
var myCase = from theCases in allCasesXML.Descendants("exchange-document")
select new case_
{
appNumber = (string)theCases.Element("bibliographic-data").Element("application-reference").Element("document-id").Element("doc-number"),
appDate = (from p in theCases.Descendants("application-reference").Descendants("document-id")
where ((string)p.Attribute("document-id-type") == "epodoc") && (p.Element("date") != null)
select (p.Element("date").Value)).FirstOrDefault(),
applicant = (string)(from q in theCases.Descendants("applicants").Descendants("applicant")//.Descendants("applicant-name")
where ((string)q.Attribute("data-format") == "original") && (q.Element("name") != null)
select (q.Descendants("name")).FirstOrDefault().Value.FirstOrDefault())
// title = "",
// pubNumber = "",
// pubDate = ""
};
答案 0 :(得分:0)
这提供了答案:
applicant = (from q in theCases.Descendants("applicants").Descendants("applicant")//.Descendants("applicant-name")
where ((string)q.Attribute("data-format") == "original")// && (q.Element("name") != null)
select q.Value).FirstOrDefault()