473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Parse XML

Im new to c#
what's the easiest way to parse short xml files?

<html><head><title>Title of the
page</title><script></script></head><body>BODY</body></html>

and save it to an object for access later?

Class HtmlFile
{
public string Title
public string SciptType
public string SciptSrc
public string Body
}

XmlNodeReader seems very confusing

Sami

Aug 5 '08 #1
3 2089
On Aug 5, 3:46*pm, "Sami" <sam...@ymail.comwrote:
Im new to c#
what's the easiest way to parse short xml files?

<html><head><title>Title of the
page</title><script></script></head><body>BODY</body></html>

and save it to an object for access later?

Class HtmlFile
{
public string Title
public string SciptType
public string SciptSrc
public string Body

}

XmlNodeReader seems very confusing
The two basic methods of loading an XML file from my experiance is 1)
use the DOM (Document Object Model) which uses the XmlDocument object
to load the file, and the SelectSingleNode method to get the value of
a single node, and 2) use the XmlSerializer class.
Aug 5 '08 #2
if it's not too much trouble could someone provide a sample on how to do
this?

thank you
Sami
<za***@construction-imaging.comwrote in message
news:02**********************************@26g2000h sk.googlegroups.com...
On Aug 5, 3:46 pm, "Sami" <sam...@ymail.comwrote:
Im new to c#
what's the easiest way to parse short xml files?

<html><head><title>Title of the
page</title><script></script></head><body>BODY</body></html>

and save it to an object for access later?

Class HtmlFile
{
public string Title
public string SciptType
public string SciptSrc
public string Body

}

XmlNodeReader seems very confusing
The two basic methods of loading an XML file from my experiance is 1)
use the DOM (Document Object Model) which uses the XmlDocument object
to load the file, and the SelectSingleNode method to get the value of
a single node, and 2) use the XmlSerializer class.

Aug 5 '08 #3
if it's not too much trouble could someone provide a sample on how to do
this?
Using Linq to Xml:

static void Main(string[] args) {
string xml = "<html><head><title>Title of the page</
title><script></script></head><body>BODY</body></html>";
HtmlFile hf = new HtmlFile(xml);
}

class HtmlFile {
public string Title;
public string Script;
public string Body;
// ...

public HtmlFile(string xml) {
XElement e = XElement.Parse(xml);

if (e.Element("head") != null) {
Title =
(string)e.Element("head").Element("title");
Script =
(string)e.Element("head").Element("script");
}
Body = (string)e.Element("body");
// ...
}
Aug 5 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Ram Laxman | last post by:
Hi all, I have a text file which have data in CSV format. "empno","phonenumber","wardnumber" 12345,2234353,1000202 12326,2243653,1000098 Iam a beginner of C/C++ programming. I don't know how to...
24
by: | last post by:
Hi, I need to read a big CSV file, where different fields should be converted to different types, such as int, double, datetime, SqlMoney, etc. I have an array, which describes the fields and...
3
by: Jon Davis | last post by:
The date string: "Thu, 17 Jul 2003 12:35:18 PST" The problem: // this fails on PST DateTime myDate = DateTime.Parse("Thu, 17 Jul 2003 12:35:18 PST"); Help? Jon
3
by: Mark | last post by:
How do you parse a currency string to a decimal? I'd like to avoid having to parse the number out, removing the $ manually. That sounds like a hack. There are times that this string will be...
14
by: Jon Davis | last post by:
I have put my users through so much crap with this bug it is an absolute shame. I have a product that reads/writes RSS 2.0 documents, among other things. The RSS 2.0 spec mandates an en-US style...
3
by: Bob Rundle | last post by:
I would like to get something like this to work... Type t = FindMyType(); // might be int, float, double, etc string s = "1233"; object v = t.Parse(s); This doesn't work of couse, Parse is...
3
by: Slonocode | last post by:
I have some textboxes bound to an access db. I wanted to format the textboxes that displayed currency and date info so I did the following: Dim WithEvents oBidAmt As Binding oBidAmt = New...
5
by: js | last post by:
I have a textbox contains text in the format of "yyyy/MM/dd hh:mm:ss". I need to parse the text using System.DateTime.Parse() function with custom format. I got an error using the following code. ...
2
by: Samuel R. Neff | last post by:
I'm using a quasi open-source project and am running into an exception in double.Parse which is effectively this: double.Parse(double.MinValue.ToString()) System.OverflowException: Value was...
3
by: Peter Duniho | last post by:
I'm sure there's a good explanation for this, but I can't figure it out. I tried using DateTime.Parse() with a custom DateTimeFormatInfo instance, in which I'd replaced the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.