I have one requirement of parsing an existing .xml file.
I need to read the existing .xml file, parse some tags inside it and dump the same to a new .xml file.The original .xml files are generated as and when required basis inside a directory.I need to check if a new files comes inside the directory if it comes (old files will be there in side the directory and they will not be purged), then parse the .xml file and generate the new one.
As a sample I have attached the original .xml file in
Original_xmldirectory
and the converted one into
Converted_Xmldirectory
inside the attached folder.
Please note that the equipment number information is not present in the above .xml file.
This needs to be fetched from Matching equipment no. from an .xlsx file (where equipment no field is mapped with SSNAME.device.devicename.pointtype column in .xlsx file as attached).
The we need to read the existing .xml file and read "SSNAME.device.devicename.pointtype" information from
<triggerdata>High Warning.abcd.Region.xy2.SSNAME.device.devicename.pointtype=40.00 status=real tag,
search in the equipment_map.xlsx sheet and find the equipment no. from the same.
This equipment no. needs to be tagged under <equipment_number>1234567890.
The <state> tag to be removed from the converted .xml file.
Now we need to separate the following information from,
<triggerdata>High Warning.abcd.Region.xy2.SSNAME.device.devicename.pointtype=40.00 status=real
and segregate the information as below.
<Substation>SSNAME</Substation>
<DeviceType>device</DeviceType>
<Device>devicename</Device>.
Finally the information is to be dumped to a new .xml file in the following location.
c:\converted_xml\ .
So lastly the new .xml file will look as follows.
<Event>
<Equipment_Number>1234567890</Equipment_Number>
<AlarmText>High Warning</Alarmtext>
<StartDate>5/26/2017 5:10:00 PM</StartDate>
<EndDate>5/26/2017 5:14:30 PM</EndDate>
<Substation>SSNAME</Substation>
<DeviceType>device</DeviceType>
<Device>devicename</Device>.
</Event>
Can anyone help me out in this regard?
The Original xml file is as follows.
<?xml version="1.0"?>
-<Email>
<To>abcd@pqrst.com</To>
<Cc/>
<Bcc/>
<Subject>HighAlarm</Subject>
<Message>HighAlarmtarun</Message>
<Event>
<State>High Warning</State>
<StartDate>5/26/2017 5:10:00 PM</StartDate>
<EndDate>5/26/2017 5:14:30 PM</EndDate>
<TriggerData>High Warning.abcd.Region.xy2.SSNAME1.device1.devicename1.pointtype1=40.00 status=real </TriggerData>
</Event>
The above file needs to be converted to,
<Event>
<Equipment_Number>1234567890</Equipment_Number>
<AlarmText>High Warning</Alarmtext>
<StartDate>5/26/2017 5:10:00 PM</StartDate>
<EndDate>5/26/2017 5:14:30 PM</EndDate>
<Substation>SSNAME1</Substation>
<DeviceType>device1</DeviceType>
<Device>devicename1</Device>.
</Event>
----------------------------------------------
The
equipment_map.xlsx
file contains the following details.
SL. No Equipment Name Equipment ID
1 SSNAME1.device1.devicename1.pointtype1 1234567890
2 SSNAME2.device2.devicename2.pointtype2 11213141516
3 SSNAME3.device3.devicename3.pointtype3 17181920212223
Another .xml file contains the following information as generated and the third and so on.
--------------------------------------------------------
2nd one,
<?xml version="1.0"?>
-<Email>
<To>abcd@pqrst.com</To>
<Cc/>
<Bcc/>
<Subject>HighAlarm</Subject>
<Message>HighAlarmtarun</Message>
<Event>
<State>High Warning</State>
<StartDate>5/26/2017 5:20:00 PM</StartDate>
<EndDate>5/26/2017 5:25:30 PM</EndDate>
<TriggerData>High Warning.abcd.Region.xy2.SSNAME2.device2.devicename2.pointtype2=40.00 status=Good </TriggerData>
</Event>
the third one .............................
-----------------------------------------------------------------------------
I can not attached the directory.But the directory fills up with new xml files when they are auto generated by some application as and when some event occurs in the system.<event> tag depicts the event.
What I have tried:
Tried to read a file using the xmlreader class.