Extracting information from CSS code

I am struggling to parse a RSS feed because all the information is contained within the description element. The CSS formatting makes it challenging to extract the actual strings. For example, below is a snippet of the description element:

<table style="border-collapse: collapse; border-spacing: 0; color:#493800; font-size: 11px; border:solid 1px #bababa;    margin: 10px;"><tr><th style="padding:5px; background:#ddd; border:solid 1px #bababa; color:#493800; font-size: 10px;">Start Time</th><td style="padding:5px; margin:0; background:#fff;">21/11/2013 19:30 UTC</td></tr><tr><th style="padding:5px; background:#ddd; border:solid 1px #bababa; color:#493800; font-size: 10px;">Backup Job</th><td style="padding:5px; margin:0; background:#fff;">Backup</td></tr><tr><th style="padding:5px; background:#ddd; border:solid 1px #bababa; color:#493800; font-size: 10px;">Computer</th><td style="padding:5px; margin:0; background:#fff;">theComputer</td></tr><tr><th style="padding:5px; background:#ddd; border:solid 1px #bababa; color:#493800; font-size: 10px;">Disk</th><td style="padding:5px; margin:0; background:#fff;">theDisk</td></tr><tr><th style="padding:5px; background:#ddd; border:solid 1px #bababa; color:#493800; font-size: 10px;">Username</th><td style="padding:5px; margin:0; background:#fff;">theUsername</td></tr><tr><th style="padding:5px; background:#ddd; border:solid 1px #bababa; color:#493800; font-size: 10px;">Searched</th><td style="padding:5px; margin:0; background:#fff;">112306 (52.5 GB)</td></tr><tr><th style="padding:5px; background:#ddd; borde...

The CSS contains key value pairs such as Computer: Computername, Uploaded: Amountuploaded that I need to extract. I have attempted using HTML Agility Pack but encountered difficulties due to my limited proficiency in using it.

Any assistance on how to efficiently extract this data would be greatly appreciated. Thank you.

Answer №1

http://www.example.com/XML-Parsing-CSharp provides valuable information on parsing XML content using C#. It appears that utilizing .NET's Xml objects is a straightforward approach to parsing.

Familiarize yourself with .NET's Xml Document parsing by starting with this article as a reference point.

Converting the string into an XmlDocument can be achieved simply by executing:

// Code snippet for loading string into XML Document
string xTxt = "<table><tr><th>...</th><td>...</td></tr></table>";
XmlDocument doc = new XmlDocument();
doc.LoadXml("<?xml version=\"1.0\"?><root>" + xTxt + "</root>");
// End of code snippet

string extractedData = null;
XmlNodeList trNodes = doc.SelectNodes("//tr");
foreach (XmlNode node in trNodes)
{
    XmlNode thNode = node.SelectSingleNode("th");
    XmlNode tdNode = node.SelectSingleNode("td");
    extractedData += thNode.InnerText + ':';
    extractedData += tdNode.InnerText + Environment.NewLine;
}
txtInfo.AppendText("nodes.Count = " + nodes.Count + '\n');
txtInfo.AppendText(extractedData);

Note that each data item you need is enclosed within a TR HTML element, with the item name in a TH element and its value in a TD element, making them easy to locate. The code snippet above retrieves all 10 'tr' elements in trNodes.

In the provided example, there is a TextBox named txtInfo utilized to display results. To enhance your implementation, consider avoiding storing results in a string variable. The usage of the t string variable is solely for illustrative purposes on how to transform items. The methods thNode.InnerText and tdNode.InnerText fetch each respective item.

You may opt to create a List of items or design a dedicated class with properties based on the data structure. Alternatively, consider creating a specialized class that handles this processing logic and integrate it into your project. Choose the approach that best suits your requirements. :)

Enjoy coding!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to display AdaptiveCard Json as a BotFramework Message using C# code

I am attempting to incorporate an Adaptive Card json into a message that will be sent to the Bot Framework Channel Emulator. However, I am encountering an issue where the emulator displays the message "Can't render card". The Adaptive Card sample I a ...

Text that spans across multiple lines

I have a multi-line text that I need to adapt to a div. For example: https://i.stack.imgur.com/mtZmf.png Is there a way to adjust the text within the div? Can we prevent the blue spacing after the word "text" using CSS? If I have various texts of differ ...

No JavaScript needed: Create custom overflow/scroll indicators using CSS only

Is there a way to align the content of a box to the left when the box doesn't overflow? I have a scroll indicator created with CSS only, which works well but has this alignment issue. Any suggestions or improvements on the code are welcome :) html ...

Enhance your CSS link in Yii framework 2.0 by incorporating media printing capabilities

While working on Yii framework 2.0, I typically include a CSS file by adding the following code snippet to assets/AppAsset.php: public $css = [ 'css/style.css', ]; Upon inspecting the element in the web browser, I notice the following code ...

Text is not visible when hovering over it

I am facing an issue with the hover effect on my menu element. When I hover over the element, the text does not appear as expected. Even after using z-index to position the text on top, it still doesn't work. Here is a snippet of my code: HTML: < ...

Is there a way to assign a specific color to individual users in a chat?

I have successfully implemented a chat feature using Pusher, but now I want to customize the appearance by changing the color of the username for the logged-in user when they are active in the conversation. Currently, both my username and another user&apos ...

Combine lists with floating elements positioned to the left or right

My HTML includes the following ul tag: <ul style="position:absolute"> <li>list 1</li> <li>list 2</li> <li>list 3</li> <li> list 4 <p>list 4 content goes here</p> ...

Faulty toggle functionality within a JavaScript-created accordion panel

HTML I'm looking to add a FAQ question within the div with the class "section-center" <body> <section class="questions"> <div class="title"> <h2>FAQ SECTION</h2> < ...

Utilize the grid system from Bootstrap to style HTML div elements

I am working on my angular application and need help with styling items in a Bootstrap grid based on the number of elements in an array. Here's what I'm looking to achieve: If there are 5 items in the array, I want to display the first two items ...

Modify the width of the <nz-date-picker> component from Ng-Zorro

Currently using Ng-Zorro for my template styling and working on implementing a date picker that I want to align perfectly with the dropdown menu above it. I would like to adjust the width of the date-picker manually within the template, but after visiting ...

parse website using jsoup redirection

While parsing data from this URL, I encountered an issue with the ajax load process. Despite my efforts to parse the website, I only receive the body element and not the desired response within the ticket_lists. I am unsure how to tackle the redirection on ...

Blurry text can be a common occurrence when applying the transform(-50%,-50%) function to center

I have found a way to center a section using the following code: <div class="clock-section"> <h5 id="clock-title">We will be arriving soon</h5> <hr class="hr" id="cdhr"> </div> Here is ...

Div not centered after translation by 50% on the Y-axis

My HTML and body have a height of 100vh. Inside my body, I have a square that is 100px by 100px. When I apply top: 50% to the div, it moves down 50%. But when I apply translateY(50%) to the div, it does not move down 50%. Why is this? Please note that y ...

Can someone explain why the min-width property is not being respected by the <input> element?

Visit this link for the code The text field in the provided link should only be 10px wide but it is currently displaying a width of 152px. Here is the code snippet: .input { width: 100%; box-sizing: border-box; } .cont { padding: 2px; } .main ...

The @media feature is not functioning properly

I am struggling with getting my media query to function properly on a school project. Despite carefully checking my code, I cannot figure out why it is not making the desired changes when viewed on a mobile device. If anyone has any suggestions or insigh ...

Ways to transfer JavaScript arguments to CSS style

Currently, I am developing a web service using Angular and Spring Boot. In this project, I have implemented cdkDrag functionality to allow users to place images in specific locations within the workspace. My goal is to maintain the placement of these image ...

Employing CSS selectors to target the subsequent element that is accessible

Here is the structure of my HTML: <input type = "checkbox" style = "display:none" id = "select"> <label for = "select" id = 'click'> click </label> <div class = 'next'> </div> I am trying to style t ...

Avoiding the application of a border-right to the final child of a div in CSS

Check out this custom HTML code: <div class="main"> <div class="parent"> <div class="child"> <span></span> <label></label> </div> <div class="child2"> // some html content </div> ...

Manipulate the contents of children divs within a parent div using JavaScript or JQuery

<div id="abc"> <div id="a_b"> abcd </div> <div id="c_d"> xyz </div> </div> I have a challenge where the divs on my page are generated dynamically and their IDs change every time the page loads. When the window i ...

How can I input text into separate tabs using a specific method?

I've been struggling with this issue for a while now and here's the code I have so far: <html> <head> <script src="http://mihaifrentiu.com/wp-content/themes/mf/js/jquery_1.7.1.min.js" type="text/javascript"></scr ...