eclipse emf 读写xml文件
来源:互联网 发布:java 文本内容相似度 编辑:程序博客网 时间:2024/06/09 22:40
import java.io.IOException;import java.util.Collections;import java.util.Map;import org.eclipse.emf.ecore.resource.Resource;import org.eclipse.emf.ecore.resource.ResourceSet;import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;import org.eclipse.emf.common.util.URI;import yxy.Bag;import yxy.YxyFactory;import yxy.YxyPackage;public class DriverWrite {public static void main(String[] args) {YxyPackage.eINSTANCE.eClass();Bag bag_caoch = YxyFactory.eINSTANCE.createBag();bag_caoch.setBrand("Caoch");Bag bag_mk = YxyFactory.eINSTANCE.createBag();bag_mk.setBrand("Michael Kors");// 注册XML扩展Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;Map<String, Object> m = reg.getExtensionToFactoryMap();m.put("xml", new XMIResourceFactoryImpl());ResourceSet resSet = new ResourceSetImpl();Resource resource = resSet.createResource(URI.createURI("My2.xml"));System.out.println(resource);resource.getContents().add(bag_caoch);resource.getContents().add(bag_mk);try {resource.save(Collections.EMPTY_MAP);} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}
My2.xml就会生成在项目的目录下
import java.util.Map;import org.eclipse.emf.common.util.URI;import org.eclipse.emf.ecore.resource.Resource;import org.eclipse.emf.ecore.resource.ResourceSet;import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;import yxy.Bag;import yxy.YxyPackage;public class DriverRead {public static void main(String[] args) {// TODO Auto-generated method stubYxyPackage.eINSTANCE.eClass();// 注册XML扩展Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;Map<String, Object> m = reg.getExtensionToFactoryMap();m.put("xml", new XMIResourceFactoryImpl());// 创建一个资源ResourceSet resSet = new ResourceSetImpl();Resource resource = resSet.getResource(URI.createURI("My2.xml"), true);Bag bag_caoch = (Bag) resource.getContents().get(0);Bag bag_mk = (Bag) resource.getContents().get(1);System.out.println(bag_caoch.getBrand());System.out.println(bag_mk.getBrand());}}
<?xml version="1.0" encoding="ASCII"?><xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:yxy="http://yxy.csz.com"> <yxy:Bag brand="Caoch"/> <yxy:Bag brand="Michael Kors"/></xmi:XMI>
0 0
- eclipse emf 读写xml文件
- Eclipse 中的EMF框架
- 读写XML文件
- 读写XML文件
- c#读写xml文件
- c#读写xml文件
- c#读写xml文件
- DOM 读写XML文件
- 读写XML文件
- C#读写xml文件
- 读写Xml文件
- c#读写xml文件
- javascript读写XML文件
- VC读写XML文件
- VC读写XML文件
- C#读写xml文件
- c# 读写xml文件
- C#读写xml文件
- android SDK 国内镜像
- 文件处理
- C++第二次作业
- 正则表达式
- 玩转微信2次开发1_交互通信api.php(微擎版)
- eclipse emf 读写xml文件
- c语言函数指针
- codeforces 652E
- redis运维常用命令
- mysql-5.6.17-W64的安装部署和启动
- C++精进篇(九)之―继承及经典示例
- 大话设计模式—装饰模式
- C++精进篇(十)之―封装、继承、多态及访问权限详解
- 继承、实现、依赖、关联、聚合、组合的联系与区别