APISonar


org.nutz.lang.Xmls.xml

> org > nutz > lang > Xmls > xml
org APIs nutz APIs lang APIs Xmls APIs xml APIs

Example 1
public void testAsMap() {
        String xmlStr = "<root><name>wendal</name><age>29</age><skills><java>good</java><lua>ok</lua></skills></root>";
        Document doc = Xmls.xml(new ByteArrayInputStream(xmlStr.getBytes()));
        Element root = doc.getDocumentElement();
        Map<String, Object> map = Xmls.asMap(root);

        assertEquals("wendal", map.get("name").toString());
    }
Example 2
public void test_dup_as_list() {
        String xmlStr = "<root><user><pet><name>wendal</name></pet><pet><name>zozoh</name></pet></user></root>";
        Document doc = Xmls.xml(new ByteArrayInputStream(xmlStr.getBytes()));
        Element root = doc.getDocumentElement();
        NutMap map = Xmls.asMap(root, true, true);
        System.out.println(map);
        NutMap user = map.getAs("user", NutMap.class);
        Object pets = user.get("pet");
        assertTrue(pets instanceof Collection || pets.getClass().isArray());
    }