Java Code Examples for org.xml.sax.ext.Attributes2Impl#setAttributes()
The following examples show how to use
org.xml.sax.ext.Attributes2Impl#setAttributes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Attributes2ImplTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Test public void test03() { System.out.println("===in test03()==="); Attributes2Impl impl1 = new Attributes2Impl(); impl1.addAttribute("http://www.cars.com/xml", "attr1", "Qname1", "type", "value"); impl1.addAttribute("http://www.cars.com/xml", "attr2", "Qname2", "type", "value"); impl1.addAttribute("http://www.cars.com/xml", "attr3", "Qname3", "type", "value"); Attributes2Impl impl2 = new Attributes2Impl(impl1); Attributes2Impl impl3 = new Attributes2Impl(); impl3.setAttributes(impl1); Assert.assertTrue(impl1.getQName(0).equals(impl2.getQName(0))); Assert.assertTrue(impl1.getQName(0).equals(impl3.getQName(0))); Assert.assertTrue(impl1.getQName(1).equals(impl2.getQName(1))); Assert.assertTrue(impl1.getQName(1).equals(impl3.getQName(1))); Assert.assertTrue(impl1.getQName(2).equals(impl2.getQName(2))); Assert.assertTrue(impl1.getQName(2).equals(impl3.getQName(2))); }
Example 2
Source File: MyDefaultHandler2.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { super.startElement(uri, localName, qName, attributes); if (qName.equals("toy")) { Attributes2Impl impl = new Attributes2Impl(); impl.setAttributes(attributes); System.out.println("\ntoy id=" + impl.getValue("id")); } else if (qName.equals("price") || qName.equals("name")) { System.out.print(" " + qName + " : "); currentValue = new StringBuffer(); } }
Example 3
Source File: Attributes2ImplTest.java From j2objc with Apache License 2.0 | 4 votes |
public void testSetAttributes() { // Ordinary case with Attributes2Impl Attributes2Impl attrs = new Attributes2Impl(); attrs.addAttribute("", "", "john", "string", "doe"); attrs.setAttributes(empty); assertEquals(0, attrs.getLength()); attrs.setAttributes(multi); for (int i = 0; i < multi.getLength(); i++) { assertEquals(multi.getURI(i), attrs.getURI(i)); assertEquals(multi.getLocalName(i), attrs.getLocalName(i)); assertEquals(multi.getQName(i), attrs.getQName(i)); assertEquals(multi.getType(i), attrs.getType(i)); assertEquals(multi.getValue(i), attrs.getValue(i)); assertEquals(multi.isDeclared(i), attrs.isDeclared(i)); assertEquals(multi.isSpecified(i), attrs.isSpecified(i)); } attrs.setAttributes(empty); assertEquals(0, attrs.getLength()); // Ordinary case with AttributesImpl attrs.setAttributes(new AttributesImpl(multi)); assertEquals(multi.getLength(), attrs.getLength()); for (int i = 0; i < multi.getLength(); i++) { assertEquals(multi.getURI(i), attrs.getURI(i)); assertEquals(multi.getLocalName(i), attrs.getLocalName(i)); assertEquals(multi.getQName(i), attrs.getQName(i)); assertEquals(multi.getType(i), attrs.getType(i)); assertEquals(multi.getValue(i), attrs.getValue(i)); assertEquals(true, attrs.isDeclared(i)); assertEquals(true, attrs.isSpecified(i)); } // Special case with CDATA attrs.setAttributes(new AttributesImpl(cdata)); assertEquals(1, attrs.getLength()); assertEquals(false, attrs.isDeclared(0)); assertEquals(true, attrs.isSpecified(0)); // null case try { attrs.setAttributes(null); fail("NullPointerException expected"); } catch (NullPointerException e) { // Expected } }