public void cData(SimplePath path, String cdata) { if ("Huhu".equals(cdata)) { if (!path.matches( new Item[] { new Item("root"), new Item("sub"), new Item("element"), new Item("element", "http://www.floreysoft.de") })) { fail("CDATA is in wrong path"); } } }
public void startElement( SimplePath path, String name, AttributesImpl attributes, String leadingCDdata) { // checking path if (!path.matchsAny(new String[] {"response", "mixed", "text", "b"})) { fail("matchesAny(String[]) does not work"); } List list = new ArrayList(); list.add(new SimplePath("response")); list.add(new SimplePath("mixed")); list.add(new SimplePath("text")); list.add(new SimplePath("b")); if (!path.matchsAny(list)) { fail("matchesAny(Collection) does not work"); } if (!path.matchsAny( new String[] {"/response", "/response/mixed", "/response/text", "/response/mixed/b"})) { fail("absolute paths do not seem to work"); } if (!path.matchsAny( new String[] {"response", "response/mixed", "response/text", "mixed/b"})) { fail("relative paths do not seem to work"); } // checking attribute if (path.matches("/response")) { String state = ConversionHelpers.getString(attributes.getValue("state"), "error"); boolean b = ConversionHelpers.getBoolean(attributes.getValue("boolean"), false); int i = ConversionHelpers.getInt(attributes.getValue("int"), 4711); long l = ConversionHelpers.getLong(attributes.getValue("long"), 1L); assertEquals(state, "ok"); assertEquals(b, true); assertEquals(i, -100); assertEquals(l, 4676767676L); // this is actually not there String notThere = ConversionHelpers.getString(attributes.getValue("notThere"), "is not there"); assertEquals(notThere, "is not there"); assertEquals(attributes.getLength(), 5); assertEquals(attributes.getValue(0), "ok"); assertEquals(attributes.getType("ns:olli"), "CDATA"); // these should be enough... } }
public void startElement( SimplePath path, String name, AttributesImpl attributes, String leadingCDdata) { boolean matchesRoot = path.matches(new Item("root")) && path.matches(Item.ITEM_ANY); boolean matchesOlli = path.matches(new Item("element")) && path.matches(new Item("element", "http://www.zeigermann.de")); boolean matchesDaniel = path.matches( new Item[] { new Item("root"), Item.ITEM_ANY, Item.ITEM_ANY, new Item("element", "http://www.floreysoft.de") }, false); boolean matchesSub = path.matches(new Item("sub")); boolean matchesFromStart = path.matchesFromRoot(new Item[] {new Item("root")}); if (matchesFromStart && !matchesRoot && !matchesOlli && !matchesDaniel && !matchesSub) { fail("Item matching does not work"); } }