473,480 Members | 3,135 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Basic XmlTextReader question

I shall make a make a function that will read an XML file, looking for
elements like this

<context id="A1">
<period>
<instant>2001-01-01</instant>
</period>
</context>

or this

<context id="A2">
<period>
<startDate>2001-01-01</startDate>
<endDate>2001-12-31</endDate>
</period>
</context>

Here's the code I've written so far:

static string[] GetContext(string id)
{
XmlTextReader r = new XmlTextReader(file_document);
string[] period = new string[2];

while(r.Read())
{
if(r.IsStartElement("context", NS_XBRL) &&
r.GetAttribute("id") == id)
{
// ?
}
}
}

After I have found the <context> element, what is the right way to
proceed to get the dates? I know I can step forward by using r.Read()
but I'll probably just get lost that way, and it doesn't seem so
robust. I'd like to say "step forward to the <period> element". Maybe
XmlTextReader is the wrong tool for this, but I hope to avoid loading
the whole file at once.

Thanks!

Gustaf

Nov 12 '05 #1
1 1187
"Gustaf Liljegren" <gu**************@bredband.net> writes:
proceed to get the dates? I know I can step forward by using r.Read()
but I'll probably just get lost that way, and it doesn't seem so
robust. I'd like to say "step forward to the <period> element". Maybe
XmlTextReader is the wrong tool for this, but I hope to avoid loading
the whole file at once.


What's wrong withe a pair of Read() and checking the Name property
of the reader?

--
Lawrence
"Avevo Halo, poi e` arrivata la mia fidanzata."
Nov 12 '05 #2

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

Similar topics

4
11340
by: Andy Neilson | last post by:
I've run across a strange behaviour with XmlSerializer that I'm unable to explain. I came across this while trying to use XmlSerializer to deserialize from a the details of a SoapException. This...
5
9181
by: Geoff Bennett | last post by:
While parsing an XML document, my TextReader instance skips nodes. For example, in this fragment: <Person Sex="Male" FirstHomeBuyer="No" YearsInCurrentProfession="14"> <RelatedEntityRef...
7
4873
by: SQLScott | last post by:
I have a Web Service in which I am trying to pass an XMLDocument as a parameter to one of the methods. I would like to use the XMLTextReader to read the XML but I am getting the following error: ...
3
3743
by: Newton | last post by:
Hi, I receive XML document from input and I would like to read it several times... My declaration is XmlTextReader XMLInputReader = new XmlTextReader(fileImport.PostedFile.InputStream); I...
1
2232
by: SHC | last post by:
Hi all, I did the "Build" on the attached code in my VC++ .NET 2003 - Windows XP Pro PC. On the c:\ screen, I got the following: Microsoft Development Environment An unhandled exception of type...
1
275
by: Raed Sawalha | last post by:
I have the following XML i do the following to extract the name information XmlTextReader Reader = new XmlTextReader("C:\\names.xml"); while(tempReader.Read() ) { if(tempReader.Name.ToLower()...
1
1270
by: Nick | last post by:
Hi All, if i have the following code: StringReader stringReader = new StringReader(c_XML); XmlTextReader xmlReader = new XmlTextReader(stringReader); If I call 'xmlReader.Close();' I take it...
5
2260
by: hangaround | last post by:
What does these codes mean as following? #pragma push_macro("new") #undef new
2
4046
by: =?Utf-8?B?TWlzY2hh?= | last post by:
It is my understanding that I can create an XmlTextReader from a variety of sources, including a stream object. I am developing a web application that reads some data from an Xml file. Everything...
0
7061
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7110
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5367
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4503
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3011
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
210
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.