467,075 Members | 997 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,075 developers. It's quick & easy.

Strategy to read part of XML log file?


Strategy to read part of XML log file

Hi,

My log file will contains entries formatted as XML(i use this format since
some time i would like to log entire objects)
I am going to use FileSystemWatcher in order to detect when changes occur
to the file
and now I am facing a problem reading the last added node
I came to the following strategy:

when a new entry will be added i will set a numeric value in it's attribute

<Entry id="100">
Message
</Entry>
<Entry id="101">
Message
</Entry>

Since I know what was the last entry read by my log viewer i can
know excalty what entries should be read

My question is do i have some API which support searching or getting part
of XML document without retriveing it to memory first?

Thanks in advance.
Nov 16 '05 #1
  • viewed: 2671
Share:
5 Replies
I'm not 100% sure you are looking for an XML parser to do this. If you
know newly added items are present at the end, it would be easier to
read the end off of the file using a non XML parser and get the data you
need that way.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Julia" <co********@012.net.il> wrote in message
news:eJ**************@TK2MSFTNGP09.phx.gbl...

Strategy to read part of XML log file

Hi,

My log file will contains entries formatted as XML(i use this format since
some time i would like to log entire objects)
I am going to use FileSystemWatcher in order to detect when changes occur
to the file
and now I am facing a problem reading the last added node
I came to the following strategy:

when a new entry will be added i will set a numeric value in it's attribute

<Entry id="100">
Message
</Entry>
<Entry id="101">
Message
</Entry>

Since I know what was the last entry read by my log viewer i can
know excalty what entries should be read

My question is do i have some API which support searching or getting part
of XML document without retriveing it to memory first?

Thanks in advance.

Nov 16 '05 #2
In case you're not certain the entry is at the end of the file, you could
try using XPathReader, it allows xpath expressions without keeping the
entire file in memory.

http://www.microsoft.com/downloads/d...DisplayLang=en

Yves

"Justin Rogers" <Ju****@games4dotnet.com> wrote in message
news:uF**************@TK2MSFTNGP09.phx.gbl...
I'm not 100% sure you are looking for an XML parser to do this. If you
know newly added items are present at the end, it would be easier to
read the end off of the file using a non XML parser and get the data you
need that way.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Julia" <co********@012.net.il> wrote in message
news:eJ**************@TK2MSFTNGP09.phx.gbl...

Strategy to read part of XML log file

Hi,

My log file will contains entries formatted as XML(i use this format
since
some time i would like to log entire objects)
I am going to use FileSystemWatcher in order to detect when changes
occur
to the file
and now I am facing a problem reading the last added node
I came to the following strategy:

when a new entry will be added i will set a numeric value in it's
attribute

<Entry id="100">
Message
</Entry>
<Entry id="101">
Message
</Entry>

Since I know what was the last entry read by my log viewer i can
know excalty what entries should be read

My question is do i have some API which support searching or getting
part
of XML document without retriveing it to memory first?

Thanks in advance.


Nov 16 '05 #3
Enteries are added to the end of the file,but how can this help me?
i dont know what is the size of the last entry entry
do you mean that i should track the position of the latest entry and use
seek?

Thanks.

"Yves Dhondt" <no@privacy.net> wrote in message
news:en**************@TK2MSFTNGP14.phx.gbl...
In case you're not certain the entry is at the end of the file, you could
try using XPathReader, it allows xpath expressions without keeping the
entire file in memory.

http://www.microsoft.com/downloads/d...DisplayLang=en
Yves

"Justin Rogers" <Ju****@games4dotnet.com> wrote in message
news:uF**************@TK2MSFTNGP09.phx.gbl...
I'm not 100% sure you are looking for an XML parser to do this. If you
know newly added items are present at the end, it would be easier to
read the end off of the file using a non XML parser and get the data you
need that way.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Julia" <co********@012.net.il> wrote in message
news:eJ**************@TK2MSFTNGP09.phx.gbl...

Strategy to read part of XML log file

Hi,

My log file will contains entries formatted as XML(i use this format
since
some time i would like to log entire objects)
I am going to use FileSystemWatcher in order to detect when changes
occur
to the file
and now I am facing a problem reading the last added node
I came to the following strategy:

when a new entry will be added i will set a numeric value in it's
attribute

<Entry id="100">
Message
</Entry>
<Entry id="101">
Message
</Entry>

Since I know what was the last entry read by my log viewer i can
know excalty what entries should be read

My question is do i have some API which support searching or getting
part
of XML document without retriveing it to memory first?

Thanks in advance.



Nov 16 '05 #4
Well, for the XPathReader you can use an expression to grab all
entries without your Id attribute set. This still requires immense
processing of the file. My proposal would be to open the file,
seek from the end (see SeekOrigin), read your buffer, and convert
it to a string, 4K or so would be nice. Then do a LastIndexOf for
your <Entry and you've found your entry... You can continue
reading buffers and prepending the data to your string if the
record is larger than a single read buffer.

Note, I do this sort of thing all the time, being a huge performance
advocate. While the higher level design would call for a pre-canned
class like a full blown XML reader, I tend to circumvent anything
that will require me to read and process large portions of the file.

--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Julia" <co********@012.net.il> wrote in message
news:OW**************@TK2MSFTNGP11.phx.gbl...
Enteries are added to the end of the file,but how can this help me?
i dont know what is the size of the last entry entry
do you mean that i should track the position of the latest entry and use
seek?

Thanks.

"Yves Dhondt" <no@privacy.net> wrote in message
news:en**************@TK2MSFTNGP14.phx.gbl...
In case you're not certain the entry is at the end of the file, you could
try using XPathReader, it allows xpath expressions without keeping the
entire file in memory.

http://www.microsoft.com/downloads/d...DisplayLang=en

Yves

"Justin Rogers" <Ju****@games4dotnet.com> wrote in message
news:uF**************@TK2MSFTNGP09.phx.gbl...
> I'm not 100% sure you are looking for an XML parser to do this. If you
> know newly added items are present at the end, it would be easier to
> read the end off of the file using a non XML parser and get the data you
> need that way.
>
>
> --
> Justin Rogers
> DigiTec Web Consultants, LLC.
> Blog: http://weblogs.asp.net/justin_rogers
>
> "Julia" <co********@012.net.il> wrote in message
> news:eJ**************@TK2MSFTNGP09.phx.gbl...
>>
>> Strategy to read part of XML log file
>>
>> Hi,
>>
>> My log file will contains entries formatted as XML(i use this format
>> since
>> some time i would like to log entire objects)
>> I am going to use FileSystemWatcher in order to detect when changes
>> occur
>> to the file
>> and now I am facing a problem reading the last added node
>> I came to the following strategy:
>>
>> when a new entry will be added i will set a numeric value in it's
>> attribute
>>
>> <Entry id="100">
>> Message
>> </Entry>
>> <Entry id="101">
>> Message
>> </Entry>
>>
>> Since I know what was the last entry read by my log viewer i can
>> know excalty what entries should be read
>>
>> My question is do i have some API which support searching or getting
>> part
>> of XML document without retriveing it to memory first?
>>
>> Thanks in advance.
>>
>>
>
>



Nov 16 '05 #5
Ok that seems good as long as I can search anode with specific attribute
I will try it

Thanks

"Yves Dhondt" <no@privacy.net> wrote in message
news:en**************@TK2MSFTNGP14.phx.gbl...
In case you're not certain the entry is at the end of the file, you could
try using XPathReader, it allows xpath expressions without keeping the
entire file in memory.

http://www.microsoft.com/downloads/d...DisplayLang=en
Yves

"Justin Rogers" <Ju****@games4dotnet.com> wrote in message
news:uF**************@TK2MSFTNGP09.phx.gbl...
I'm not 100% sure you are looking for an XML parser to do this. If you
know newly added items are present at the end, it would be easier to
read the end off of the file using a non XML parser and get the data you
need that way.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Julia" <co********@012.net.il> wrote in message
news:eJ**************@TK2MSFTNGP09.phx.gbl...

Strategy to read part of XML log file

Hi,

My log file will contains entries formatted as XML(i use this format
since
some time i would like to log entire objects)
I am going to use FileSystemWatcher in order to detect when changes
occur
to the file
and now I am facing a problem reading the last added node
I came to the following strategy:

when a new entry will be added i will set a numeric value in it's
attribute

<Entry id="100">
Message
</Entry>
<Entry id="101">
Message
</Entry>

Since I know what was the last entry read by my log viewer i can
know excalty what entries should be read

My question is do i have some API which support searching or getting
part
of XML document without retriveing it to memory first?

Thanks in advance.



Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by ajsiegel@optonline.net | last post: by
3 posts views Thread by Bob | last post: by
6 posts views Thread by Daniel Santa Cruz | last post: by
7 posts views Thread by Ryan | last post: by
25 posts views Thread by marcin.rzeznicki@gmail.com | last post: by
2 posts views Thread by Joey | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.