【发布时间】:2009-08-21 18:21:01
【问题描述】:
我正在尝试解析 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;
【问题讨论】:
-
在你的html下划线并点击“代码”按钮
-
查看此页面以获得完整的标记参考。 stackoverflow.com/editing-help
-
那么添加你的 linq-statement-that-is-not-working 怎么样?