473,394 Members | 2,002 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,394 software developers and data experts.

How to read parts of XML in c# and write it across

375 256MB
Hi,
I have an XML file which has lots of values as below, placing just sample

Expand|Select|Wrap|Line Numbers
  1.     <Entries>
  2.       <Application1>
  3.         <key>12</key>
  4.         <alerts>res12 ### test</alerts>
  5.       </Application1>
  6.       <Application2>
  7.         <key>13</key>
  8.         <alerts>res 13 ### test</alerts>
  9.       </Application2>
  10.  
  11.  
  12.     </Entries>
  13.  
For sample I have showed just two values, I have hundred of such data, which I have parse and throw an entry in the Event viewer.
Event viewer consists of key id and the description (alerts)

I have captured the event viewer part. But I have to split "Application1" in one alert and "Application2" in an another alert.

My program is straight forward
Expand|Select|Wrap|Line Numbers
  1.      XmlTextReader reader = new XmlTextReader(@"C:\Examples\tivolialert\Tivoli.xml");
  2.                 string skey = string.Empty;
  3.                 string salert = string.Empty;
  4.                 int intkey = 0;
  5.                 reader.Read();
  6.                 while (reader.Read())
  7.                 {
  8.  
  9.                     if (reader.Name == "key")
  10.                     {
  11.                         skey = reader.ReadString();
  12.                     }
  13.  
  14.                     if (reader.Name == "Alert")
  15.                     {
  16.                         salert = reader.ReadString();
  17.                         bool result = Int32.TryParse(skey, out intkey);
  18.                         EventLog.WriteEntry("Some source", salert, EventLogEntryType.Error, intkey);
  19.  
  20.                     }
  21.  
  22.                 }
  23.  
  24.                 Console.ReadLine();
  25.             }
  26.  

I have only one hurdle, I need to capture Application wise, i.e. if its Application1 then the source ("Some source") will be different, if its Application2 the source will be different.
How do I figure it out?
Mar 16 '14 #1
1 1143
Luuk
1,047 Expert 1GB
at line#8 (untested)
Expand|Select|Wrap|Line Numbers
  1. if (left(reader.Name,11)=='Application') {
  2.     currentApp=reader.Name
  3. }
  4.  
Now you can pick a value for "Some source" based on the value of currentApp....
Mar 16 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Garrett Kajmowicz | last post by:
I have two implementations of stringstream and they both handle interleaved reads and writes differently. I was hoping that you might be able to shed some light as to the "correct" operation, and...
16
by: ben beroukhim | last post by:
I have huge number of legacy code which use standard files functions. I would like to pass a memory pointer rather than a FILE pointer. I am trying to use FILEs in the code to refer to memory...
2
by: Luis Mendes | last post by:
How can I read and write images to SQL server to a field with the type "image". CanĀ“t make DataBound work. Thank's in advance, Luis
5
by: Sumana | last post by:
Hi All, We developed our project on VC++.Net console application to create image of disk and to write the image We are having problem with reading and writing the sector beyond 6GB Disk or...
2
by: agphoto | last post by:
There is big or problem in open file in read and write mode.. $file = "data.txt"; $fp = fopen($file,"w+"); $line = fgets($fp,"120"); // i need only 1st line to read and upto 120 bytes echo...
23
by: asit dhal | last post by:
hello friends, can anyone explain me how to use read() write() function in C. and also how to read a file from disk and show it on the monitor using onlu read(), write() function ??????
6
by: Per Juul Larsen | last post by:
Hi. My Textfile looks like this Variable 1 Variable 2 Variable 3 Variable 4 On opening the application it will read the textfile, and assign each line of variable to at textfield in VB and...
1
by: Sachin Garg | last post by:
I have a program which opens a fstream in binary input+output mode, creating the file if it doesn't exists. But writing doesn't works after reading, it must be something obvious that I am not aware...
3
by: sriram347 | last post by:
Hi I am a newbie to ASP.NET. I developed a web page (project type is web application) and I keep getting this error. B]Error message : "System.AccessViolation Exception attempted to read or...
2
by: MightyPolo | last post by:
I have a Class which has intPtr to bitmap data. I am greating a Bitmap instance using new Bitmap(my_width, imageHeader.biHeight, stride, pixelFormat, pixelDataHandle); later i flip the bitmap...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...

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.