HTML敏捷包解析使用Upper&小写标签? [英] HTML Agility Pack Parsing With Upper & Lower Case Tags?
问题描述
我使用HTML Agility Pack的效果非常好,并且对它印象深刻 - 但是,我选择的内容就像这样
doc.DocumentNode.SelectSingleNode(// body)。InnerHtml
如何处理以下情况,用不同的文件?
< body>
< Body>
< BODY>
上面的代码只能得到小写版本吗?
这意味着它将以同样的方式解析身体,身体和身体。它的设计原因是HTML不区分大小写(XHTML是)。
也就是说,当你使用它的XPATH特性时,你必须使用标签小写。这意味着// body
表达式将匹配BODY,Body和body,// BODY不会匹配任何内容。
I am using the HTML Agility Pack to great effect, and am really impressed with it - However, I am selecting content like so
doc.DocumentNode.SelectSingleNode("//body").InnerHtml
How to I deal with the following situation, with different documents?
<body>
<Body>
<BODY>
Will my code above only get the lower case versions?
The Html Agility Pack handles HTML in a case insensitive way. It means it will parse BODY, Body and body the same way. It's by design since HTML is not case sensitive (XHTML is).
That said, when you use its XPATH feature, you must use tags written in lower case. It means the "//body"
expression will match BODY, Body and body, and "//BODY" will match nothing.
这篇关于HTML敏捷包解析使用Upper&小写标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!