XPath - 在<p>元素(jQuery)中处理<br/>标签</p>

时间:2014-09-12 12:44:11

标签: jquery html xpath

我有以下XPath来获取div类'article'中的各种<p>元素:

//div[@class = 'article']/p

结果解析如下:

var outPut = '<div>';
       var newContent = data.query.results.p;
             newContent.forEach(function(node, index) {
                    outPut += '<p>' + node + '</p>';
             });

这在<br>元素中有<p>之前一直正常。在这种情况下,XPath的输出采用以下形式:{"p":[{"class":"abstract","content":"text 1"}, "text2, "text3",{"br":null,"content":"text4", "text5""},"text6","text7"]}

当解析它时,通过上面的代码,带有“br”的花括号内的内容(上例中的text4和5)呈现为(object,Object);

这是我第一次尝试XPath,所以我可能会遗漏一些明显的东西。我可以看到这部分不起作用:data.query.results.p',因为所讨论的字符串不在“p”元素中 - 但我不知道我是应该更改XPath还是仅仅解析结果。是否有一些方法来构造XPath,以便<br>标记被省略或包含“p”元素而不创建新节点?

感谢您的帮助。

修改  在回应下面的评论时,这里有更多信息,

这是确切回答的一个例子:

/**/jQuery1910007391897961497307_1410561766895({"query":{"count":6,"created":"2014-09-12T22:42:55Z","lang":"en-US","results":{"p":[{"class":"abstract","content":"This is the first paragraph"},"This is the second paragraph",{"br":null,"content":"This is the paragraph containing a <br> tag"},"This is the last paragraph"]}}});

这是问题段落如何出现在HTML中的示例:

<p>

    Text here

    <br></br>

    More text here
</p>

HTML中的所有其他段落都包含在<p> </p>中,并且已正确解析。上面的段落(包含<br>标记)被解析为(object, Object)

0 个答案:

没有答案
相关问题