Xml| News | load | Essence FIRST design a simple XML configuration file config.xml
<?xml version= ' 1.0 ' encoding= ' utf-8 '?>
<test>
<luck title= "Luck Bang Bang Bang" tag= "Luck" application= "dispatch.test" method= "mm" >
</luck>
</test>
The next way to parse XML is to use the Jaxp,dispatch.java
Package dispatch;
public void Startelement (String NamespaceURI,
String LName,//local name
String QName,//qualified name
Attributes attrs)
Throws Saxexception
{
debug//
String Ftag = "LUCK";
////////
String ename = lName; Element name
if ("". Equals (ename)) ename = QName; Namespaceaware = False
if (attrs!= null) {
for (int i = 0; i < attrs.getlength (); i++) {
if (Ftag.equals (Attrs.getvalue (i))) {
System.out.println (Loader.loader) (Attrs.getvalue (i+1), Attrs.getvalue (i+2), "The It???");
Break
}//if equals
}//for I
}//if!null
}
public static void Main (String argv[]) {
Dispatch get = new dispatch ();
Get.execute ();
}
}
One more dynamic loading method Dynamicloader.java
Package dispatch;
Import java.lang.*;
Import java.lang.reflect.*;
public class dynamicloader{
Public Dynamicloader () {
}
public string Loader (string appname,string mthname,string ctn) {
String restr = "";
Class Torun = null;
try{
Torun = Class.forName (appName);
Method Ftogo = Torun.getdeclaredmethod (mthname,new class[]{string.class});
Restr = Ftogo.invoke (Torun.newinstance (), New Object[]{ctn}). toString ();
}catch (Exception e) {
SYSTEM.OUT.PRINTLN ("Loader:" +e+ "|") +mthname+ "|" +appname+ "|" +CTN);
}
return restr;
}
}
A small debug script, just to return the parameter Test.java
Package dispatch;
public class test{
public string mm (string str) {
return str;
}
}
Parsing an XML file requires a system plus JAXP, JAXR, JAXM, JAXRPC, and a specific look at the SAX documentation. I'm not going to go into the details here.
This one can run, just too slow, with colleagues using the same principle. propertier file way is slower than like, depressed ~
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.