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

Resolve Bootstrap 4 responsive table header alignment glitch

Utilizing the d-none and d-md-block classes on a responsive table to hide certain columns at smaller screen sizes has been successful overall. However, there is one issue - the hidden columns seem to be slightly misaligned with the rest of the table. Despi ...

What is the best way to restrict the length and number of lines in a textarea based on pixel dimensions?

I am looking to create a textarea where people can select different fonts, such as "sans-serif" and "serif", to type in text. I plan to have buttons labeled "sans-serif" and "serif" that will change the font of the textarea when clicked. However, there ar ...

When the button on the custom keyboard is pressed in XAMARIN, trigger a satisfying clicking

I came across this Objective C solution on how to achieve a particular task, but I am struggling with adapting it to C# (Xamarin). In Objective C, the UIInputViewAudioFeedback is an interface, but in C#, there seems to be no interface called UIInputViewAud ...

Strange error in SignalR occurring in connection with the System.Net.Http.WebRequestHandler type

After successfully creating a server SignalR application, I was able to access the JavaScript code template at http://localhost:11914/signalr/hubs. The client application is a .NET 4.6.2 web API developed using the latest Visual Studio 2017 RC template. W ...

Learn how to efficiently apply styles to multiple objects within an array using the material-ui library

Currently, I'm utilizing the functional component of React.js. Within this component, I have an array of objects that contain specific styles. const data = [ { id: 1, color: '#000' }, { ...

Having trouble getting the carousel slider to function properly on meteor?

I am currently working on my portfolio page using Meteor, and I want to include a carousel slider gallery. The problem I'm facing is that while the first gallery works fine, the second one does not load correctly and just displays a list of pictures. ...

Border only at the bottom of the outline

I need help creating a bottom outline border when the cursor hovers over an image. I prefer to use this inner border style to avoid any layout issues with a traditional border-bottom. Below is my current code, which includes outline margins: .img-lightbox ...

Position an HTML canvas at the very top of the webpage

Can someone help me figure out how to align a canvas element to the very top (0, 0) of a webpage? I attempted using margin: 0; padding: 0px;, but it didn't work. There always seems to be some white space at the top that I can't eliminate. ...

Guide on organizing items into rows with 3 columns through iteration

Click on the provided JSFiddle link to view a dropdown menu that filters items into categories. Each item is stored as an object in an array for its respective category. Currently, all items are displayed in one column and I want to divide them into three ...

How to implement a Django block for loading CSS files

I have multiple pages and I need to load unique CSS for each page. I am using this method for all static files. In the head of my index.html file, I have the following code: {% block css %} {% endblock %} However, in my contact.html file, I have the fol ...

Bootstrap 4 radio buttons are not aligning properly with the padding

There seems to be an issue with the alignment of Bootstrap 4 custom radio buttons and my left padding. Here is a snippet: https://i.sstatic.net/vWTNo.png This is part of the code for displaying an item <div class="p-4"> <ul class="d-flex ...

Tips for generating an input element using JavaScript without the need for it to have the ":valid" attribute for styling with CSS

My simple input in HTML/CSS works perfectly, but when I tried to automate the process by writing a JavaScript function to create multiple inputs, I encountered an issue. The input created with JavaScript is already considered valid (from a CSS ":valid" sta ...

The styles applied to the Angular 5 Component host element are not being reflected correctly in jsPlumb

As a beginner in Angular >2 development, I am excited to build my first application from scratch. One of the features I'm trying to implement is drawing flow charts using jsPlumb. However, I have encountered an issue where the connectors are not be ...

Styling QSpinBoxes in QColorDialog without affecting QAbstractSpinBox styling with QSS

To give our Qt desktop application a stylish look, I have been utilizing Jorgen-VikingGod's impressive QSS framework as a foundation. Unfortunately, we encountered a hurdle when it came to usability on a dated tablet device running Windows. The tiny s ...

What is the correct way to load a column of images without affecting the readability of the text alongside them? (see image below)

https://i.stack.imgur.com/rBL50.png Whenever my page loads, there is a card with a vertical list of images. Due to the loading time of the images, the text appears first and gets squished as shown in the provided screenshot. Is there a way for the text to ...

The React modal window stubbornly refuses to close

import c from '../Profile.module.css'; import { useState } from 'react'; import { createPortal } from 'react-dom'; import Modal from '../Modal/Modal'; const TransactionItem = (props) => { const modalRoot = ...

Angular Tutorial: Modifying the CSS transform property of HTML elements within a component directly

Currently, I'm in the process of developing an analog clock for a project using Angular. My challenge is figuring out how to dynamically update the sec/min/hour handlers on the clock based on the current time by manipulating the style.transform prope ...

How to Prevent Scrolling When Modal is in Use on Full Page JS

I am trying to achieve the functionality where when the modal is open, I want to prevent full-page scrolling in JavaScript. The issue arises when I open the modal and try to scroll, it ends up moving the content that's behind the modal, which is actua ...

Adjust the active carousel item to 0 within onsen-ui (displaying a list of carousel items in a sliding menu)

In my sliding menu, each menu item contains a carousel with two items. I am trying to make the first carousel item show after closing and reopening the menu, or by clicking a button outside of the list on the menu page. This is my current setup: <ons- ...

What's the trick to making a column that's 2/3 wide in a 34grid layout?

Is it possible to use the 34 Responsive Grid system to create a column that takes up two-thirds of the full width? Although the Grid System has equal columns settings, I'm curious how to combine or merge two columns together? <div class="containe ...