xml文件解析

xml文件配置:
<?xml version="1.0" encoding="UTF-8"?> <signatures> <signature> <!-- 签章正文 --> <textLength>1</textLength> <textWidth>53</textWidth> <textHight>87</textHight> <textRadian>88</textRadian> <!-- 签章附文 --> <riderWidth>5</riderWidth> <riderHight>12</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>2</textLength> <textWidth>12</textWidth> <textHight>30</textHight> <textRadian>36</textRadian> <!-- 签章附文 --> <riderWidth>5</riderWidth> <riderHight>13</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>3</textLength> <textWidth>12</textWidth> <textHight>28</textHight> <textRadian>36</textRadian> <!-- 签章附文 --> <riderWidth>5</riderWidth> <riderHight>13</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>4</textLength> <textWidth>12</textWidth> <textHight>28</textHight> <textRadian>34</textRadian> <!-- 签章附文 --> <riderWidth>5</riderWidth> <riderHight>13</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>5</textLength> <textWidth>12</textWidth> <textHight>30</textHight> <textRadian>32</textRadian> <!-- 签章附文 --> <riderWidth>5</riderWidth> <riderHight>13</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>6</textLength> <textWidth>12</textWidth> <textHight>30</textHight> <textRadian>30</textRadian> <!-- 签章附文 --> <riderWidth>5</riderWidth> <riderHight>13</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>7</textLength> <textWidth>11</textWidth> <textHight>30</textHight> <textRadian>28</textRadian> <!-- 签章附文 --> <riderWidth>5</riderWidth> <riderHight>13</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>8</textLength> <textWidth>10</textWidth> <textHight>28</textHight> <textRadian>23</textRadian> <!-- 签章附文 --> <riderWidth>5</riderWidth> <riderHight>13</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>9</textLength> <textWidth>10</textWidth> <textHight>28</textHight> <textRadian>22</textRadian> <!-- 签章附文 --> <riderWidth>5</riderWidth> <riderHight>13</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>10</textLength> <textWidth>8</textWidth> <textHight>26</textHight> <textRadian>19</textRadian> <!-- 签章附文 --> <riderWidth>5</riderWidth> <riderHight>13</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>11</textLength> <textWidth>8</textWidth> <textHight>26</textHight> <textRadian>18</textRadian> <!-- 签章附文 --> <riderWidth>5</riderWidth> <riderHight>13</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>12</textLength> <textWidth>8</textWidth> <textHight>26</textHight> <textRadian>17</textRadian> <!-- 签章附文 --> <riderWidth>5</riderWidth> <riderHight>13</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>13</textLength> <textWidth>8</textWidth> <textHight>26</textHight> <textRadian>17</textRadian> <!-- 签章附文 --> <riderWidth>5</riderWidth> <riderHight>13</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>14</textLength> <textWidth>8</textWidth> <textHight>26</textHight> <textRadian>16</textRadian> <!-- 签章附文 --> <riderWidth>5</riderWidth> <riderHight>13</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>15</textLength> <textWidth>8</textWidth> <textHight>26</textHight> <textRadian>15</textRadian> <!-- 签章附文 --> <riderWidth>5</riderWidth> <riderHight>13</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>16</textLength> <textWidth>7</textWidth> <textHight>25</textHight> <textRadian>14</textRadian> <!-- 签章附文 --> <riderWidth>5</riderWidth> <riderHight>13</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>17</textLength> <textWidth>7</textWidth> <textHight>25</textHight> <textRadian>14</textRadian> <!-- 签章附文 --> <riderWidth>5</riderWidth> <riderHight>13</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>18</textLength> <textWidth>6</textWidth> <textHight>23</textHight> <textRadian>12</textRadian> <!-- 签章附文 --> <riderWidth>5</riderWidth> <riderHight>13</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>19</textLength> <textWidth>6</textWidth> <textHight>23</textHight> <textRadian>12</textRadian> <!-- 签章附文 --> <riderWidth>5</riderWidth> <riderHight>13</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>20</textLength> <textWidth>6</textWidth> <textHight>22</textHight> <textRadian>11</textRadian> <!-- 签章附文 --> <riderWidth>5</riderWidth> <riderHight>13</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>21</textLength> <textWidth>5</textWidth> <textHight>19</textHight> <textRadian>11</textRadian> <!-- 签章附文 --> <riderWidth>5</riderWidth> <riderHight>13</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>22</textLength> <textWidth>5</textWidth> <textHight>19</textHight> <textRadian>11</textRadian> <!-- 签章附文 --> <riderWidth>5</riderWidth> <riderHight>13</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>23</textLength> <textWidth>5</textWidth> <textHight>20</textHight> <textRadian>10</textRadian> <!-- 签章附文 --> <riderWidth>5</riderWidth> <riderHight>13</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>24</textLength> <textWidth>5</textWidth> <textHight>20</textHight> <textRadian>10</textRadian> <!-- 签章附文 --> <riderWidth>5</riderWidth> <riderHight>13</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>25</textLength> <textWidth>5</textWidth> <textHight>21</textHight> <textRadian>10</textRadian> <!-- 签章附文 --> <riderWidth>4</riderWidth> <riderHight>12</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>26</textLength> <textWidth>4</textWidth> <textHight>20</textHight> <textRadian>9</textRadian> <!-- 签章附文 --> <riderWidth>4</riderWidth> <riderHight>12</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>27</textLength> <textWidth>4</textWidth> <textHight>19</textHight> <textRadian>8</textRadian> <!-- 签章附文 --> <riderWidth>4</riderWidth> <riderHight>12</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>28</textLength> <textWidth>4</textWidth> <textHight>19</textHight> <textRadian>8</textRadian> <!-- 签章附文 --> <riderWidth>4</riderWidth> <riderHight>12</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>29</textLength> <textWidth>3</textWidth> <textHight>19</textHight> <textRadian>8</textRadian> <!-- 签章附文 --> <riderWidth>4</riderWidth> <riderHight>12</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>30</textLength> <textWidth>3</textWidth> <textHight>19</textHight> <textRadian>8</textRadian> <!-- 签章附文 --> <riderWidth>4</riderWidth> <riderHight>12</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>31</textLength> <textWidth>3</textWidth> <textHight>19</textHight> <textRadian>8</textRadian> <!-- 签章附文 --> <riderWidth>4</riderWidth> <riderHight>12</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>32</textLength> <textWidth>3</textWidth> <textHight>19</textHight> <textRadian>7</textRadian> <!-- 签章附文 --> <riderWidth>4</riderWidth> <riderHight>12</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>33</textLength> <textWidth>4</textWidth> <textHight>18</textHight> <textRadian>8</textRadian> <!-- 签章附文 --> <riderWidth>4</riderWidth> <riderHight>12</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>34</textLength> <textWidth>4</textWidth> <textHight>17</textHight> <textRadian>7</textRadian> <!-- 签章附文 --> <riderWidth>4</riderWidth> <riderHight>12</riderHight> </signature> <signature> <!-- 签章正文 --> <textLength>35</textLength> <textWidth>4</textWidth> <textHight>19</textHight> <textRadian>7</textRadian> <!-- 签章附文 --> <riderWidth>4</riderWidth> <riderHight>12</riderHight> </signature> </signatures>
dom4j解析:
public static Seal signature(int length){ InputStream inputStream = CircularSeal.class.getClassLoader().getResourceAsStream("signature.xml"); SAXReader sax = new SAXReader(); try { Document doc = (Document) sax.read(inputStream); Element rootNode = doc.getRootElement(); List<Element> list = rootNode.elements(); if(length<=30){ for(Element ele:list){//遍历当前节点的所有属性 String textLength = ele.elementText("textLength"); String len = length+""; if(textLength.equals(len)){ int textWidth = Integer.valueOf(ele.elementText("textWidth")); int textHight = Integer.valueOf(ele.elementText("textHight")); int textRadian = Integer.valueOf(ele.elementText("textRadian")); int riderWidth = Integer.valueOf(ele.elementText("riderWidth")); int riderHight = Integer.valueOf(ele.elementText("riderHight")); Seal seal = new Seal(textWidth,textHight,textRadian,riderWidth,riderHight); return seal; } } }else{ System.out.println("公司名称不合法"); } } catch (DocumentException e) { e.printStackTrace(); } return null; }

实体类:

package test;

import java.util.List;

public class Seal {
	
	int textWidth;
	int textHight;
	int textRadian;
	int riderWidth;
	int riderHight;
	
	public Seal(int textWidth, int textHight, int textRadian, int riderWidth,
			int riderHight) {
		super();
		this.textWidth = textWidth;
		this.textHight = textHight;
		this.textRadian = textRadian;
		this.riderWidth = riderWidth;
		this.riderHight = riderHight;
	}
	public int getTextWidth() {
		return textWidth;
	}
	public void setTextWidth(int textWidth) {
		this.textWidth = textWidth;
	}
	public int getTextHight() {
		return textHight;
	}
	public void setTextHight(int textHight) {
		this.textHight = textHight;
	}
	public int getTextRadian() {
		return textRadian;
	}
	public void setTextRadian(int textRadian) {
		this.textRadian = textRadian;
	}
	public int getRiderWidth() {
		return riderWidth;
	}
	public void setRiderWidth(int riderWidth) {
		this.riderWidth = riderWidth;
	}
	public int getRiderHight() {
		return riderHight;
	}
	public void setRiderHight(int riderHight) {
		this.riderHight = riderHight;
	}
	
	
}

  

转载于:https://www.cnblogs.com/SEVEN-wkq/p/6845864.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值