17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package stream.XMLStreamReaderTest; 25 26 import java.util.Iterator; 27 28 import javax.xml.stream.XMLEventReader; 29 import javax.xml.stream.XMLInputFactory; 30 import javax.xml.stream.XMLOutputFactory; 31 import javax.xml.stream.XMLStreamConstants; 32 import javax.xml.stream.XMLStreamReader; 33 import javax.xml.stream.events.StartElement; 34 import javax.xml.stream.events.XMLEvent; 35 36 import org.testng.Assert; 37 import org.testng.annotations.Test; 38 39 /* 40 * @summary Test StAX parses namespace and attribute. 41 */ 42 public class DefaultAttributeTest { 43 44 private static final String INPUT_FILE = "ExternalDTD.xml"; 45 46 @Test 47 public void testStreamReader() { 48 XMLInputFactory ifac = XMLInputFactory.newInstance(); 49 XMLOutputFactory ofac = XMLOutputFactory.newInstance(); 50 51 try { 52 ifac.setProperty(ifac.IS_REPLACING_ENTITY_REFERENCES, new Boolean(false)); 53 54 XMLStreamReader re = ifac.createXMLStreamReader(this.getClass().getResource(INPUT_FILE).toExternalForm(), 55 this.getClass().getResourceAsStream(INPUT_FILE)); 56 57 while (re.hasNext()) { 58 int event = re.next(); 59 if (event == XMLStreamConstants.START_ELEMENT && re.getLocalName().equals("bookurn")) { 60 Assert.assertTrue(re.getAttributeCount() == 0, "No attributes are expected for <bookurn> "); 61 Assert.assertTrue(re.getNamespaceCount() == 2, "Two namespaces are expected for <bookurn> "); | 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package stream.XMLStreamReaderTest; 25 26 import java.util.Iterator; 27 28 import javax.xml.stream.XMLEventReader; 29 import javax.xml.stream.XMLInputFactory; 30 import javax.xml.stream.XMLOutputFactory; 31 import javax.xml.stream.XMLStreamConstants; 32 import javax.xml.stream.XMLStreamReader; 33 import javax.xml.stream.events.StartElement; 34 import javax.xml.stream.events.XMLEvent; 35 36 import org.testng.Assert; 37 import org.testng.annotations.Listeners; 38 import org.testng.annotations.Test; 39 40 /* 41 * @summary Test StAX parses namespace and attribute. 42 */ 43 @Listeners({jaxp.library.FilePolicy.class}) 44 public class DefaultAttributeTest { 45 46 private static final String INPUT_FILE = "ExternalDTD.xml"; 47 48 @Test 49 public void testStreamReader() { 50 XMLInputFactory ifac = XMLInputFactory.newInstance(); 51 XMLOutputFactory ofac = XMLOutputFactory.newInstance(); 52 53 try { 54 ifac.setProperty(ifac.IS_REPLACING_ENTITY_REFERENCES, new Boolean(false)); 55 56 XMLStreamReader re = ifac.createXMLStreamReader(this.getClass().getResource(INPUT_FILE).toExternalForm(), 57 this.getClass().getResourceAsStream(INPUT_FILE)); 58 59 while (re.hasNext()) { 60 int event = re.next(); 61 if (event == XMLStreamConstants.START_ELEMENT && re.getLocalName().equals("bookurn")) { 62 Assert.assertTrue(re.getAttributeCount() == 0, "No attributes are expected for <bookurn> "); 63 Assert.assertTrue(re.getNamespaceCount() == 2, "Two namespaces are expected for <bookurn> "); |