Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you insist on parsing the web page as XML, try this:</p> <pre><code>var elements = from element in document.Descendants(xmlns + "div") where (string)element.Attribute("id") == "maincolumn" from element2 in element.Descendants(xmlns + "img") let src = ((string)element2.Attribute("src")).Trim() where String.IsNullOrEmpty(src) select new { element2, src }; foreach (var item in elements) { Console.WriteLine(item.src); } </code></pre> <p>Notes:</p> <ul> <li>What is the type of <code>document</code>? I am assuming it's an <code>XDocument</code>. If that is the case, you can use <code>Descendants</code> directly on <code>XDocument</code>. (OTOTH if <code>document</code> is an <code>XDocument</code>, where does that <code>fullPath</code> property come from?)</li> <li>Cast the <code>XAttribute</code> to a string. If it's empty, the result of the cast will be null. This will save on the double check. (This doesn't offer any performance benefits.)</li> <li>Use <code>let</code> to "save" a value for later reuse, in this case for use in the foreach. Unless all you need is that final Assert, in which case it might be more efficient to use <code>Any</code> instead of <code>Count</code>. <code>Any</code> only has to iterate over the first result in order to return a value; <code>Count</code> has to iterate over all of them.</li> <li>Why is <code>subdocument</code> of type <code>XDocument</code>? Wouldn't <code>XElement</code> be the appropriate type?</li> <li>You can also use <code>String.IsNullOrWhitespace</code> to check for whitespace in <code>src</code>, instead of <code>String.IsNullOrEmpty</code>, assuming you want to process the <code>src</code> as is, with any whitespace it might have.</li> </ul>
    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.
    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