首页 > 代码库 > xml文件解析
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; } }
xml文件解析
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。