java类中
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "USAddress", propOrder = { "data" })
public class USAddress {
String getData() {..};
}
xml:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<USAddress xmlns="">
<ServiceName>Send</ServiceName>
<ContactID>20110218102422312</ContactID>
<Data xmlns=""><DataName>DestTermID</DataName><DataValue>12345</DataValue></Data>
</USAddress >
</soapenv:Body>
</soapenv:Envelope>
xml文件放在哪里,让它跟java类关联~这个类USAddress是怎样加载xml的?大侠们帮帮忙!
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "USAddress", propOrder = { "data" })
public class USAddress {
String getData() {..};
}
xml:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<USAddress xmlns="">
<ServiceName>Send</ServiceName>
<ContactID>20110218102422312</ContactID>
<Data xmlns=""><DataName>DestTermID</DataName><DataValue>12345</DataValue></Data>
</USAddress >
</soapenv:Body>
</soapenv:Envelope>
xml文件放在哪里,让它跟java类关联~这个类USAddress是怎样加载xml的?大侠们帮帮忙!
public class Test { /** * @param args * @throws IOException * @throws ParserConfigurationException * @throws SAXException * @throws ClassNotFoundException * @input */ public static void main(String[] args) throws Exception, ParserConfigurationException, SAXException, ClassNotFoundException { DocumentBuilder builder; builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); if (args.length == 0) return; else { InputStream in=null; try {//读取XML文件 String filePath = args[0]; File file = new File(filePath); in = new FileInputStream(file); Document doc=builder.parse(in); Element eRoot = doc.getDocumentElement(); NodeList nl = eRoot.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i); if (!(n instanceof Element)) continue; Element e = (Element) n; System.out.println(e.getNodeName());//取得类名 String className=e.getAttribute("class"); Class cl=Class.forName(className);//创建类实例对象 Object o=cl.newInstance();//动态调用方法 Method m=cl.getMethod("sayHello", String[].class); Object[] ob=new Object[1]; String arg[]=new String[1]; arg[0]="1"; ob[0]=arg; m.invoke(o,ob); } } finally { in.close(); } } }}