读取xml节点信息

这段代码展示了如何使用Java和DOM4J库解析XML文件,读取`mxGraphModel`中的`source`和`mxCell`节点信息。程序定义了SourceXml、Location和MxcellXml类来存储节点数据,并提供了读取首节点、上一个节点、下一个节点的源信息及其ID的方法。
摘要由CSDN通过智能技术生成
package com.mxgraph.readXml;

public class SourceXml {
	
	private String name;
	private String title;
	private String type;
	private String property;
	private String id;
	
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getProperty() {
		return property;
	}
	public void setProperty(String property) {
		this.property = property;
	}
	
	

}

package com.mxgraph.readXml;public class Location {private String nodeName; private double width; private double height; private double valueX; private double valueY; public String getNodeName() { return nodeName; } public void setNodeName(String nodeName) { this.nodeName = nodeName; } public double getWidth() { return width; } public void setWidth(double width) { this.width = width; } public double getHeight() { return height; } public void setHeight(double height) { this.height = height; } public double getValueX() { return valueX; } public void setValueX(double valueX) { this.valueX = valueX; } public double getValueY() { return valueY; } public void setValueY(double valueY) { this.valueY = valueY; } @Override public String toString() { return "Location [height=" + height + ", nodeName=" + nodeName + ", valueX=" + valueX + ", valueY=" + valueY + ", width=" + width + "]"; } }
package com.mxgraph.readXml;
	
	public class MxcellXml {
		
		private String id;
		private String edge;
		private String parent;
		private String source;
		private String target;
		public String getId() {
			return id;
		}
		public void setId(String id) {
			this.id = id;
		}
		public String getEdge() {
			return edge;
		}
		public void setEdge(String edge) {
			this.edge = edge;
		}
		public String getParent() {
			return parent;
		}
		public void setParent(String parent) {
			this.parent = parent;
		}
		public String getSource() {
			return source;
		}
		public void setSource(String source) {
			this.source = source;
		}
		public String getTarget() {
			return target;
		}
		public void setTarget(String target) {
			this.target = target;
		}
	
		
		
	}

package com.mxgraph.readXml;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class MxgrapReadXml {  
  
    public static Map<String, SourceXml> maps;  
    static {  
        maps = new HashMap<String, SourceXml>();  
    }  
  
    public static void main(String[] args) {  
    	Map<String, SourceXml> readSource=   readSource("mxgraphnew.xml");  
    	Map<String, MxcellXml> readMxcell=   readMxcell("mxgraphnew.xml");  
    	ArrayList<String> firstNode=firstNode("mxgraphnew.xml");  
    	Map<String, SourceXml> firstSource=firstSource("mxgraphnew.xml");
    	ArrayList<String> lastNode=lastNode("mxgraphnew.xml", "7");
    	Map<String, SourceXml> lastSource=lastSource("mxgraphnew.xml", "7");
    	ArrayList<String> nextNode=nextNode("mxgraphnew.xml", "3");
    	Map<String, SourceXml> nextSource=nextSource("mxgraphnew.xml", "3");
    	
    	
    	System.out.println("首节点id");
    	//首节点id点
    	for(String s:firstNode) {
    		System.out.print(s+",");
    	}
    	System.out.println();
    	System.out.println();
    	System.out.println("上一个节id");
    	//上一个节id
    	for(String s:lastNode) {
    		System.out.print(s+",");
    	}
    	System.out.println();
    	System.out.println();
    	System.out.println("mxcell实例");
    	//mxcell实例化
    	for(String s:readMxcell.keySet()) {
    		MxcellXml mxcellXml=readMxcell.get(s);
    		System.out.println(s+","+mxcellXml.getTarget());
  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

那个id是什么东西

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值