Document document = NULL;
Documentbuilderfactory factory = documentbuilderfactory. newinstance ();
Try {
Documentbuilder builder = factory. newdocumentbuilder ();
Document = builder. parse (configpath );
Node rootnode = Document. getfirstchild ();
System. Out. println (rootnode. tostring ());
Nodelist logfilelist = rootnode. getchildnodes ();
For (INT I = 1; I <logfilelist. getlength (); I ++ = 2 ){
Node curnode = logfilelist. item (I );
System. Out. println ("Log File" + I + ":" + curnode. tostring ());
Namednodemap map = curnode. getattributes ();
For (Int J = 0; j <map. getlength (); j ++ ){
System. Out. println ("Log File" + I + ": Key:" + map. Item (j). getnodename ());
System. Out. println ("Log File" + I + ": Value:" + map. Item (j). getnodevalue ());
}
Nodelist columns = curnode. getchildnodes ();
For (Int J = 1; j <columns. getlength (); j + = 2 ){
System. Out. println ("column" + J + ":" + columns. Item (j). tostring ());
}
}
} Catch (parserconfigurationexception e ){
E. printstacktrace ();
} Catch (saxexception e ){
E. printstacktrace ();
} Catch (ioexception e ){
E. printstacktrace ();
}
XML file content:
<? XML version = "1.0" encoding = "UTF-8"?>
<Log_mapping>
<LOG_FILE filenamepattern = "ad. + \. log" class = "com.nec.jp. bigm. log. adlogcounter">
<Column name = "date"/>
<Column name = "carrier"/>
<Column name = ""/>
</LOG_FILE>
<LOG_FILE filenamepattern = "access. + \. log" class = "com.nec.jp. bigm. log. adlogcounter">
<Column name = ""/>
<Column name = ""/>
<Column name = ""/>
</LOG_FILE>
</Log_mapping>