I am trying to parse a XML string using dom4j. But when I try to get the attribute value of any node(element) it return null value only.
This is my file contains XML:
<Event xmlns='http://schemas.microsoft.com/win/2004/08/events/event'>
<System>
<Provider Name='Outlook'/>
<EventID Qualifiers='16384'>63</EventID>
<Level>4</Level>
<Task>0</Task>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime='2015-07-23T13:45:26.000000000Z'/>
<EventRecordID>27487</EventRecordID>
<Channel>Application</Channel>
<Computer>eGLAP0011-PC</Computer>
</System>
<EventData>
<Data>The Exchange web service request GetAppManifests succeeded. </Data>
</EventData>
</Event>
See below my code:
BufferedReader br = null;
try
{
File inputFile = new File("D:\\EventLog\\xml_op.txt");
br = new BufferedReader(new FileReader(inputFile));
String line="",con_line="";
int inc =0;
while((line = br.readLine())!=null)
{
con_line+=line;
}
Document doc=DocumentHelper.parseText(con_line);
Element parent_ele = doc.getRootElement();
for (Iterator i1 = parent_ele.elementIterator("System"); i1.hasNext();)
{
Element Sys = (Element) i1.next();
System.out.println("------------------------------------------------");
System.out.println("Provider--> " + Sys.attributeValue("Name")); //I got null value here
System.out.println("EventID--> " + Sys.elementText("EventID"));
System.out.println("Level--> " + Sys.elementText("Level"));
System.out.println("Task--> " + Sys.elementText("Task"));
System.out.println("Keywords--> " + Sys.elementText("Keywords"));
System.out.println("TimeCreated--> " + Sys.attributeValue("SystemTime"));//I got null value here
System.out.println("EventRecordID--> " + Sys.elementText("EventRecordID"));
System.out.println("Channel--> " + Sys.elementText("Channel"));
System.out.println("Computer--> " + Sys.elementText("Computer"));
System.out.println("------------------------------------------------");
}
}
catch(Exception e)
{
e.printStackTrace();
}
The output of the above code:
------------------------------------------------
Provider--> null
EventID--> 63
Level--> 4
Task--> 0
Keywords--> 0x80000000000000
TimeCreated--> null
EventRecordID--> 27487
Channel--> Application
Computer--> eGLAP0011-PC
------------------------------------------------
In the above output, the value of Provider and Time Created is null, I have searched lot in websites, but I didn't get correct solution for this problem, Please share your ideas. Thanks in advance,
TimeCreatedValue form the file