Altova XMLSpy 把xml解析成xsd文件
下载xmlbeans 注意:jar 配置path
scomp -src src -out XmlBean.jar 88.xsd -compiler "C:/Program Files/Java/jdk1.6.0/bin/javac" 88.xsdconfig
新建项目 导xmlb里的jar 加上刚生成的jar
写一个类似的类
import java.io.File;
import java.io.UnsupportedEncodingException;
import sample.xmlbean.*;
import sample.xmlbean.CardItemDocument.CardItem;
import sample.xmlbean.ProductItemDocument.ProductItem;
import sample.xmlbean.TotalMenuDocument.TotalMenu;
import org.apache.xmlbeans.XmlOptions;
public class bean {
private String filename = null;
public bean(String filename) {
super();
this.filename = filename;
}
public void Reader() {
try {
File xmlFile = new File(filename);
TotalMenuDocument doc = TotalMenuDocument.Factory.parse(xmlFile);
ProductItem [] productItem = doc.getTotalMenu().getProductItemArray();
for (int i = 0; i < productItem.length; i++) {
ProductItem ProductItem = productItem[i];
println("Customer#" + i);
println("Customer ID:" + ProductItem.getRechargeURL());
println("Customer ID:" + ProductItem.getKeyWord());
println("Customer ID:" + ProductItem.getLetterCode());
println("Customer ID:" + ProductItem.getProductID());
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void println(String str) {
try {
str=new String(str.getBytes("GB2312"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(str);
}
public static void main(String[] args) {
String filename = "D://QQProductListService.xml";
bean bean = new bean(filename);
bean.Reader();
}
}