首页 > 代码库 > Xstream annotion xml to java for selenium test

Xstream annotion xml to java for selenium test

package com.dao;import java.util.ArrayList;import java.util.List;import com.thoughtworks.xstream.annotations.XStreamAlias;import com.thoughtworks.xstream.annotations.XStreamImplicit;@XStreamAlias("html")public class Html {public Head head;public Body body;public class Head {public String meta;public String link;public String title;}public class Body {public Table table;public class Table {public Tbody tbody;public String thead;public class Tbody {@XStreamImplicit(itemFieldName="tr")public List<Tr> trs;public class Tr {@XStreamImplicit(itemFieldName="td")public List<String> tds;}}}}}
package com.DatasourceRead;import java.io.FileInputStream;import java.io.IOException;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.io.StringReader;import com.dao.Html;import com.thoughtworks.xstream.XStream;import com.thoughtworks.xstream.io.xml.DomDriver;import com.thoughtworks.xstream.io.xml.Xpp3DomDriver;public class Test {        private XStream xStream = null;        private ObjectOutputStream  out = null;        private ObjectInputStream in = null;                public void init() {        xStream = new XStream();    }        public static Html changeToBean() throws IOException{          System.out.println("in");        XStream stream=new XStream(new Xpp3DomDriver());          stream.processAnnotations(Html.class);        return (Html) stream.fromXML(new FileInputStream("E:\\workspace\\Selenuim\\test.html"));//我这里用的是绝对路径 }    }        public static void main(String[] args) throws IOException {        Html t = changeToBean();        System.out.println(t.body.table.tbody.trs.get(1).tds.get(2));    }}
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head profile="http://selenium-ide.openqa.org/profiles/test-case"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><link rel="selenium.base" href="http://www.baidu.com/" /><title>test</title></head><body><table cellpadding="1" cellspacing="1" border="1"><thead><tr><td rowspan="1" colspan="3">test</td></tr></thead><tbody><tr>    <td>open</td>    <td>/index.php?tn=monline_5_dg</td>    <td></td></tr><tr>    <td>type</td>    <td>id=kw</td>    <td>ll</td></tr><tr>    <td>click</td>    <td>id=su</td>    <td></td></tr><tr>    <td>waitForPageToLoad</td>    <td></td>    <td></td></tr><tr>    <td>click</td>    <td>id=kw</td>    <td></td></tr><tr>    <td>waitForPageToLoad</td>    <td></td>    <td></td></tr><tr>    <td>click</td>    <td>link=LL_百度百科</td>    <td></td></tr><tr>    <td>click</td>    <td>link=建筑图纸标注</td>    <td></td></tr><tr>    <td>click</td>    <td>link=网络概念</td>    <td></td></tr><tr>    <td>click</td>    <td>link=Love Live</td>    <td></td></tr><tr>    <td>click</td>    <td>link=网络概念</td>    <td></td></tr></tbody></table></body></html>

 

Xstream annotion xml to java for selenium test