xmlbeans解析XML文件全流程+Altova XMLSpy破解

前端之家收集整理的这篇文章主要介绍了xmlbeans解析XML文件全流程+Altova XMLSpy破解前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

xmlbeans解析XML详细介绍的说明很多,官方也有很多参考,不多废话,主要流程如下:

1. 下载 xmlbean 文件 官方或者直接点击

2. 根据XML生成Schema(XML文件的结构和元素约束文件),可使用工具Altova XMLSpy进行生成.破解版下载地址点我.

3.使用 SPY打开XML,依次选择DTD/Schema->Generate DTD/Schema->W3C Schema->输入名称,得到MRO.xsd文件.

4. 编写.xsdconfig文件.主要作用提供给xmlbean生成命名使用.mewasure.xsdconfig

<xb:config xmlns:xb="http://xml.apache.org/xmlbeans/2004/02/xbean/config"> 
 <xb:namespace> 
 <xb:package>measure.xmlbean</xb:package> 
 </xb:namespace>
</xb:config>


 

4. 拷贝mro.xsd,原始XML文件,mewasure.xsdconfig文件至xmlbean\bin目录下.记得配置JAVAJDK环境变量

5. 执行scomp -out measureXmlBean.jar MRO.xsdmewasure.xsdconfig

6. 复制生成JAR文件至工程,eclipse引用JAR.

7.java使用方法如下

读:

try {
			File xmlFile = new File(path);
			BulkPmMrDataFileDocument doc = BulkPmMrDataFileDocument.Factory.parse(xmlFile);
			FileHeader customers = doc.getBulkPmMrDataFile().getFileHeader();
			ENodeB enb = doc.getBulkPmMrDataFile().getENodeB();
			Measurement[] measurement = enb.getMeasurementArray();
			for (int i = 0; i < measurement.length; i++) {
				Measurement customer = measurement[i];
				println("id:" + i);
				println("getSmr ID:" + customer.getSmr());
				println("getObjectArray name:" + customer.getObjectArray()[0].getId());

			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}


写:

public void createCustomer() {
    try {
        // Create Document
        CustomersDocument doc = CustomersDocument.Factory.newInstance();
        // Add new customer
        CustomerType customer = doc.addNewCustomers().addNewCustomer();
        // set customer info
        customer.setId(3);

        // Add new address
        AddressType address = customer.addNewAddress();
        // Add new PrimaryAddress
        PrimaryAddressType primaryAddress = address.addNewPrimaryAddress();
        primaryAddress.setPostalCode("350106");


        // Add new BillingAddress
        BillingAddressType billingAddress = address.addNewBillingAddress();
        billingAddress.setReceiver("Ms Danielle");
        File xmlFile = new File(filename);
        doc.save(xmlFile);
        } catch (Exception ex) {
                ex.printStackTrace();
        }

  }
    
   main .
    public static void main(String[] args) {
    String filename = "F://JavaTest//Eclipse//XMLBean//xml//customers_new.xml";
        CustomerXMLBean customerXMLBean = new CustomerXMLBean(filename);
        customerXMLBean.createCustomer();
    }



到此全完已经介绍完成.


关于spy破解简单说下:

1. 屏蔽验证.C:\WINDOWS\system32\drivers\etc\hosts加入.
127.0.0.1 altova.com #XMLspy
127.0.0.1 www.altova.com #XMLspy
127.0.0.1 link.altova.com #XMLspy
2. 安装,复制patch到安装目录.点击应用补丁
3. 启动注册,注册码如下
Name:www.shijieweb.cn Company:shijieweb Key-code:PM92JW3-HJMTA8C-P2H3C53-579CT11-PCCYT91-X8D0LM1-PWY8U42

原文链接:https://www.f2er.com/xml/296616.html

猜你在找的XML相关文章