1、suite.xml文件
<suite name="phoenixframe_jenkins"> <test name="webUI测试用例"> <classes> <class>org.phoenix.cases.cases.aggregate.TestCase1</class> </classes> </test> <test name="接口测试"> <classes> <class name="org.phoenix.cases.webservice.ContactJieKou" /> </classes> </test> </suite>
2.xmlString
<?xml version="1.0" encoding="utf-8"?> <RSS version="2.0"> <channel> <title>Java Tutorials and Examples 2</title> <language>en-us</language> <item> <title><![CDATA[Java Examples 2]]></title> <link>http://examples.javacodegeeks.com/</link> </item> </channel> </RSS>
3、XmlParserUtil 方法演示
import org.junit.Test; import org.phoenix.api.utils.JsonPaser; import org.phoenix.api.utils.XmlParser; import org.w3c.dom.Node; public class ParserUtil { @Test public void testXmlFileParser(){ System.out.println(XmlParser.getInstance().parserXmlFile("Suite.xml").getChildNames("//*/test").toString()); //输出:[test,test] System.out.println(XmlParser.getInstance().parserXmlFile("Suite.xml").getChildValues("//*/test/classes/*").toString()); //输出:[org.phoenix.cases.cases.aggregate.TestCase1,] Node node = XmlParser.getInstance().parserXmlFile("Suite.xml").getNodeElement("/suite/test[2]"); System.out.println("获取指定节点的属性值:"+node.getAttributes().item(0).getTextContent()); //输出:获取指定节点的属性值:接口测试 Node node2 = XmlParser.getInstance().parserXmlFile("Suite.xml").getNodeElement("/suite/test[1]/*/class"); System.out.println("获取指定节点的值:"+node2.getTextContent()); //输出:获取指定节点的值:org.phoenix.cases.cases.aggregate.TestCase1 } @Test public void testXmlStringParser(){ //xmlString的格式化后的请见标题2 String xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><RSS version=\"2.0\"><channel><title>Java Tutorials and Examples 2</title><language>en-us</language><item><title><![CDATA[Java Examples 2]]></title><link>http://examples.javacodegeeks.com/</link></item></channel></RSS>"; System.out.println(XmlParser.getInstance().parserXmlContent(xmlString).getChildValues("/RSS/*").toString()); //输出:[Java Tutorials and Examples 2en-usJava Examples 2http://examples.javacodegeeks.com/] System.out.println(XmlParser.getInstance().parserXmlContent(xmlString).getChildValues("//*[name() = 'title']").toString()); //输出:[Java Tutorials and Examples 2,Java Examples 2] } }