我正在尝试从 HTML 文件中解析一些数据,但我的 Linq 语句不起作用。这是 XML/HTML。下面,如何从 geo.position 元标记中提取字符串“41.8;12.23”?谢谢!!
这是我的 Linq
String longLat = (String)
from el in xdoc.Descendants()
where
(string)el.Name.LocalName == "meta"
& el.FirstAttribute.Name == "geo.position"
select (String) el.LastAttribute.Value;
这是我的 Xdocument
<span>
<!--CTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="application/xhtml+xml; charset=utf-8" http-equiv="Content-Type" />
<meta content="text/css" http-equiv="Content-Style-Type" />
<meta name="geo.position" content="41.8;12.23" />
<meta name="geo.placename" content="RomeFiumicino, Italy" />
<title>RomeFiumicino, Italy</title>
</head>
<body />
</html>
</span>
编辑:我给定的查询没有返回任何内容。“内部”查询似乎返回了所有元元素的列表,而不仅仅是我想要的一个元素。
编辑:以下 Linq 查询适用于同一个 XDocument 以检索具有类名 = "data" 的表
var dataTable =
from el in xdoc.Descendants()
where (string)el.Attribute("class") == "data"
select el;