Note that there are some explanatory texts on larger screens.

plurals
  1. POUse HtmlAgilityPack to divy up a document
    primarykey
    data
    text
    <p>I'm wondering if this is possible.</p> <p>I have html like so:</p> <pre><code>&lt;p&gt; &lt;font face="Georgia"&gt; &lt;b&gt;History&lt;/b&gt;&lt;br&gt;&amp;nbsp; &lt;br&gt;Two of the polysaccharides used in the manufacture of...&lt;/font&gt; &lt;a title="PubMed" href="http://www.www.gov/pubmed/" target="_blank"&gt; &lt;font face="Georgia"&gt;) and this web site for new development by...well as Self Affirmed Medical Food GRAS status.&amp;nbsp; &lt;/font&gt; &lt;/p&gt; &lt;p&gt; &lt;font face="Georgia"&gt;[READMORE]&lt;/font&gt; &lt;/p&gt; &lt;p&gt;&lt;font face="Georgia"&gt;&lt;br&gt;&lt;strong&gt;Proprietary Composition&lt;/strong&gt;&lt;br&gt; &lt;br&gt;The method in which soluble fibres are made into... REST OF ARTICLE... &lt;/p&gt; </code></pre> <p>Yes, it's ugly html and it comes from a WYSIWYG so I have little control over it. </p> <p>What I want to do is search for <strong>[READMORE]</strong> in the document, remove any parent tags ( in this case, the <code>&lt;font&gt;</code> and the <code>&lt;p&gt;</code> tags ) and replace them with a readmore link while wrapping the REST of the document in a giant `...rest of article...</p> <p>I'm pretty sure the HtmlAgilityPack will get me part of the way there, but I'm just trying to figure out where to start. </p> <p>So far, I'm pretty sure that I have to use <code>htmlDoc.DocumentNode.SelectSingleNode(//p[text()="[READMORE]"])</code> or something. I'm not too familiar with XPATH. </p> <p>For my documents, the readmore may or may not be in a nested <code>font</code> tag.</p> <p>Also, in some cases, it may not be in a tag at all, but rather at the document root. I can just do a regular search and replace in that case and it should be straightforward.</p> <p>My ideal situation would be something like this (PSEUDOCODE)</p> <pre><code>var node = SelectNodeContaining("[READMORE]"). node.Replace( "link here" ); node.RestOfDocument().Wrap("&lt;div class='wrapper'"); </code></pre> <p>I know, I'm dreaming... but I hope this makes sense.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload