本文整理汇总了Java中org.newdawn.slick.util.xml.XMLParser类的典型用法代码示例。如果您正苦于以下问题:Java XMLParser类的具体用法?Java XMLParser怎么用?Java XMLParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XMLParser类属于org.newdawn.slick.util.xml包,在下文中一共展示了XMLParser类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: downloadWurstNews
import org.newdawn.slick.util.xml.XMLParser; //导入依赖的package包/类
private void downloadWurstNews() {
new Thread(() -> {
try {
HttpsURLConnection connection =
(HttpsURLConnection) new URL("https://www.wurst-client.tk/news/feed.xml").openConnection();
connection.connect();
XMLElement xml = new XMLParser().parse("", connection.getInputStream());
news = xml.getChildrenByName("channel").get(0).getChildrenByName("item");
} catch (Exception e) {
e.printStackTrace();
}
}).start();
}
开发者ID:null-dev,项目名称:EvenWurse,代码行数:14,代码来源:GuiWurstMainMenu.java
示例2: main
import org.newdawn.slick.util.xml.XMLParser; //导入依赖的package包/类
/**
* Simple test for the XML parsing API
*
* @param argv The arguments given to the test
* @throws SlickException Indicates a failure
*/
public static void main(String[] argv) throws SlickException {
XMLParser parser = new XMLParser();
XMLElement root = parser.parse("testdata/test.xml");
assertEquals(root.getName(), "testRoot");
System.out.println(root);
assertNotNull(root.getChildrenByName("simple").get(0).getContent());
System.out.println(root.getChildrenByName("simple").get(0).getContent());
XMLElement parent = root.getChildrenByName("parent").get(0);
assertEquals(parent.getChildrenByName("grandchild").size(),0);
assertEquals(parent.getChildrenByName("child").size(),2);
assertEquals(parent.getChildrenByName("child").get(0).getChildren().size(),2);
XMLElement child = parent.getChildrenByName("child").get(0).getChildren().get(0);
String name = child.getAttribute("name");
String test = child.getAttribute("nothere","defaultValue");
int age = child.getIntAttribute("age");
assertEquals(name, "bob");
assertEquals(test, "defaultValue");
assertEquals(age, 1);
XMLElement other = root.getChildrenByName("other").get(0);
float x = (float) other.getDoubleAttribute("x");
float y = (float) other.getDoubleAttribute("y", 1.0f);
float z = (float) other.getDoubleAttribute("z", 83.0f);
assertEquals(x, 5.3f);
assertEquals(y, 5.4f);
assertEquals(z, 83.0f);
try {
z = (float) other.getDoubleAttribute("z");
fail("Attribute z as a double should fail");
} catch (SlickException e) {
// expect exception
}
}
开发者ID:j-dong,项目名称:trashjam2017,代码行数:48,代码来源:XMLTest.java
注:本文中的org.newdawn.slick.util.xml.XMLParser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论