Note that there are some explanatory texts on larger screens.

plurals
  1. PODOM parsing in JavaScript
    primarykey
    data
    text
    <p><strong>Some background:</strong><br> I'm developing a web based mobile application using JavaScript. HTML rendering is Safari based. Cross domain policy is disabled, so I can make calls to other domains using XmlHttpRequests. The idea is to parse external HTML and get text content of specific element.<br> In the past I was parsing the text line by line, finding the line I need. Then get the content of the tag which is a substring of that line. This is very troublesome and requires a lot of maintenance each time the target html changes.<br> So now I want to parse the html text into DOM and run css or xpath queries on it.<br> It works well:</p> <pre><code>$('&lt;div&gt;&lt;/div&gt;').append(htmlBody).find('#theElementToFind').text() </code></pre> <p>The only problem is that when I use the browser to load html text into DOM element, it will try to load all external resources (images, js files, etc.). Although it isn't causing any serious problem, I would like to avoid that.</p> <p><strong>Now the question:</strong><br> <strong>How can I parse html text to DOM without the browser loading external resources, or run js scripts ?</strong><br> Some ideas I've been thinking about:</p> <ul> <li>creating new document object using createDocument call (<code>document.implementation.createDocument()</code>), but I'm not sure it will skip the loading of external resources.</li> <li>use third party DOM parser in JS - the only one I've tried was very bad with handling errors</li> <li>use iframe to create new document, so that external resources with relative path will not throw an error in console</li> </ul>
    singulars
    1. This table or related slice is empty.
    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