Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linq Html敏捷包,不支持';t选择节点_Linq_Xpath_Html Agility Pack - Fatal编程技术网

Linq Html敏捷包,不支持';t选择节点

Linq Html敏捷包,不支持';t选择节点,linq,xpath,html-agility-pack,Linq,Xpath,Html Agility Pack,这是一个HTML文件,由于内容的大小,它被截断了,并且在末尾包含了一个“img”标记 <?xml version="1.0" encoding="UTF-8"?> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" xmlns:epub="http://www.idpf.org/2007/ops"> <head> <meta charset="utf-8">&

这是一个HTML文件,由于内容的大小,它被截断了,并且在末尾包含了一个“img”标记

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
xmlns:epub="http://www.idpf.org/2007/ops">
<head>
    <meta charset="utf-8"></meta>
    <title>The Waste Land</title>
    <link rel="stylesheet" type="text/css" href="wasteland.css" class="day" title="day"/> 
    <link rel="alternate stylesheet" type="text/css" href="wasteland-night.css" class="night" title="night"/>   
</head>
<body>
    <section epub:type="frontmatter" id="frontmatter">
        <section epub:type="titlepage" id="titlepage">
            <h1>The Waste Land</h1>
            <div class="aut">T.S. Eliot</div>
            <div epub:type="epigraph">              
            </div>
            <p epub:type="dedication">For Ezra Pound: <span xml:lang="it">il migliorfabbro</span></p>
        </section>
    </section>
    <section epub:type="bodymatter" id="bodymatter">
        <section id="ch1">
            <h2>I. THE BURIAL OF THE DEAD</h2>
                <div>Looking into the heart of light, the silence.</div>
                <div xml:lang="de" id="ln42">
                    <em>Od' und leer das Meer</em>.<a epub:type="noteref" class="noteref" href="#note-4">*</a>
                </div>
            </div>
            <div class="linegroup">
                <img src="www.href">The lady of situations.
                </img>
                <div>Here is the man with three staves, and here the Wheel,</div>
                <div>And here is the one-eyed merchant, and this card,</div>
                </div>
    </section>
</body>

List-imgNodes=HTMLDoc.DocumentNode.subjections()。其中(n=>n.Name==“img”).ToList();

两者都无法检索任何标记。我能做什么?

第一个带有//img的命令对我有效,它返回img。你的代码是什么?实际上完整的html代码是。我的代码是这样的:HtmlAgilityPack.HtmlDocument HTMLDoc=new HtmlAgilityPack.HtmlDocument();Load(ContainerXml.Stream);HtmlNode bodyNode=HTMLDoc.DocumentNode.SelectSingleNode(“//body”);HtmlNodeCollection imgNodes=HTMLDoc.DocumentNode.SelectSingleNode(“//img”);但它返回空值:(哦,很抱歉,请您将SelectSingleNode替换为SelectNodes。我想选择所有img标记,但我没有键入。谢谢您,sirI注意到您的HTML定义了XML名称空间,但这不会影响HAP以及它读取和查询文档的能力。您的目标框架/版本是什么?我能够找到节点与预期的一样。如果我将完整html保存为文件并使用HtmlDocument.load加载它,SelectNodes(“//img”)将返回一个节点。您必须执行其他操作,否则没有加载同一文档。
HtmlNodeCollection imgNodes= HTMLDoc.DocumentNode.SelectNodes("//img");
 List<HtmlNode> imgNodes = HTMLDoc.DocumentNode.Descendants().Where(n => n.Name =="img").ToList();