关闭

xmlbeans XMLSpy 解析xml

284人阅读 评论(0) 收藏 举报

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();
    }
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:2535次
    • 积分:57
    • 等级:
    • 排名:千里之外
    • 原创:3篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章存档