Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sample to parse XML file

6 views
Skip to first unread message

TMC

unread,
Nov 27, 2009, 11:05:01 AM11/27/09
to
Hello,
I tried to parse an xml file from a SD card. I haven't been able to find a
way. The file is basically:
<aaa>
<bbb ccc="123" ddd="23"/>
<eee fff="235" ggg="11"/>
</aaa>
I tried :
string namefilexml = @"\SD\Param.xml";

System.IO.FileStream xmfile= File.Open(namefilexml ,
FileMode.Open);
using (XmlReader reader = XmlReader.Create(xmfile))
{
....
}

but I don't know how to navigate inside reader (ie read the aaa/bbb[ccc]
value for example).
Can you provide a small example to do this ?
thanks

Jan Kučera

unread,
Nov 27, 2009, 6:12:38 PM11/27/09
to
Hello,
there is no XPath navigator on .NET Micro Framework, so you can't simply
pass "aaa/bbb[ccc]" in and get the value.

XmlReader is quite low level class, where you need to manually walk through
the document and until you come to what you are looking for.

For working with XmlReader, some general info could be found at
http://msdn.microsoft.com/en-us/library/9d83k261.aspx

So it would basically be something like...
reader.ReadStartElement("aaa");
reader.ReadStartElement("bbb");
return reader.GetAttribute("ccc");

(but this does not handle different elements order, in which case you would
use overloads without specifying the element names and testing them
yourself)


Jan

"TMC" <T...@discussions.microsoft.com> wrote in message
news:E49D4F23-EAD3-45C7...@microsoft.com...

TMC

unread,
Nov 28, 2009, 10:48:01 AM11/28/09
to
thanks I'll try that.
By the way, What is the most efficient way to parse html files ?

"Jan Kučera" wrote:

> .
>

Jan Kučera

unread,
Nov 28, 2009, 6:47:49 PM11/28/09
to
Well, HTML parsing, as far as I know, is one of the most difficult and
challenging task in this area, because it is far away from XML and usually
contains tons of errors.

If you are dealing with a XHTML page, then XmlReader might be quite helpful
in cases when the page is valid XML, which usually is. This would be also my
recommendation if you are creating the pages you are going to parse
yourself.

Otherwise depends on why do you need to parse the HTML files. If you are
looking for concrete information in some more or less fixed structure, then
the easiest way might work good and fast enough - plain string search.

Maybe if you could tell us more about your scenario, we could come with some
ideas.

Jan


"TMC" <T...@discussions.microsoft.com> wrote in message

news:FD1B3004-6D3B-4E2E...@microsoft.com...

TMC

unread,
Nov 29, 2009, 10:28:01 AM11/29/09
to
What you wrote sounds good to me. I had this feeling. I will just make plain
text search and hope changes on the server (which I do not manage) will not
affect my search.
Thanks for providing quick response and meaningfull synthesis.
Bye.

"Jan Kučera" wrote:

> .
>

0 new messages