Java 类org.newdawn.slick.util.xml.XMLParser 实例源码

项目:EvenWurse    文件:GuiWurstMainMenu.java   
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();
}
项目:trashjam2017    文件:XMLTest.java   
/**
 * 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
    }
}
项目:Progetto-C    文件:XMLTest.java   
/**
 * 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
    }
}
项目:BaseClient    文件:XMLTest.java   
/**
 * 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
    }
}
项目:GPVM    文件:XMLTest.java   
/**
 * 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
    }
}
项目:SpaceStationAlpha    文件:XMLTest.java   
/**
 * 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
    }
}
项目:cretion    文件:XMLTest.java   
/**
 * 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
    }
}
项目:slick2d-maven    文件:XMLTest.java   
/**
 * 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
    }
}