How to select a dl tag with all child in c#

c# html-agility-pack

Question

I am unable to pick everything.dt and dd from the HTML table below

<dl class="Grid Grid--multicol Grid--2col:40em Grid--4col:60em">
    <div class="Grid-cell u-flex u-flexOne u-flexRow">
        <dt> Item ID:</dt>
        <dd class="u-weightSemibold u-paddingL5px">72547664</dd>
    </div>
    <div class="Grid-cell u-flex u-flexOne u-flexRow">
            <dt> License:</dt>
            <dd class="u-weightSemibold u-paddingL5px">
                <a class="u-linkDodgerBlue js-infoLicenseString" href="" target="_blank">Standard</a>
            </dd>
    </div>
    <div class="Grid-cell u-flex u-flexOne u-flexRow">
            <dt> Usage:</dt>
            <dd class="u-weightSemibold">Commercial<span class="TooltipQuestionMark"></span></dd>
    </div>
    <div class="Grid-cell u-flex u-flexOne u-flexRow">
            <dt> Required Plugins:</dt>
            <dd class="u-weightSemibold u-paddingL5px">None</dd>
    </div>
    <div class="Grid-cell u-flex u-flexOne u-flexRow">
            <dt> Creation Tool:</dt>
            <dd class="u-weightSemibold u-paddingL5px">Autodesk</dd>
    </div>
    <div class="Grid-cell u-flex u-flexOne u-isHidden:0-60em"></div>
</dl>

writing this

            i = 0; doc.DocumentNode.SelectNodes("//dl").Where(x => x.HasClass("Grid")).FirstOrDefault().SelectNodes(".//div").ToList().ForEach(x =>
            {
                result.Items.Add(new DownloadItem { Name = "specs-title", Index = i,    Type = DownloadItemType.Text, Value = x.SelectNodes(".//dt").FirstOrDefault().GetText() });
                result.Items.Add(new DownloadItem { Name = "specs",       Index = i++,  Type = DownloadItemType.Text, Value = x.SelectNodes(".//dd").GetText() });
            });

The code above just selects the first row.Item ID: | 72547664 what are all of my issuesdt and dd information

1
0
8/9/2018 4:00:23 PM

Accepted Answer

the issue with your code is that when you first wish to get alldl the components of classGrid using the technique, you only choose the first DOM element of that kind.FirstOrDefault() .

i = 0; doc.DocumentNode.SelectNodes("//dl").Where(x => x.HasClass("Grid")).SelectNodes(".//div").ToList().ForEach(x =>
            {
                result.Items.Add(new DownloadItem { Name = "specs-title", Index = i,    Type = DownloadItemType.Text, Value = x.SelectNodes(".//dt").FirstOrDefault().GetText() });
                result.Items.Add(new DownloadItem { Name = "specs",       Index = i++,  Type = DownloadItemType.Text, Value = x.SelectNodes(".//dd").GetText() });
            });

You must eliminateFirstOrDefault() to gather all the components that meet your needs.

0
8/9/2018 8:24:25 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow