1 /* 2 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 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 package org.xml.sax.ptests; 24 25 import java.io.File; 26 import javax.xml.parsers.SAXParser; 27 import javax.xml.parsers.SAXParserFactory; 28 import jaxp.library.JAXPFileBaseTest; 29 import static jaxp.library.JAXPTestUtilities.USER_DIR; 30 import static jaxp.library.JAXPTestUtilities.compareWithGold; 31 import static org.testng.Assert.assertTrue; 32 import org.testng.annotations.Test; 33 import static org.xml.sax.ptests.SAXTestConst.GOLDEN_DIR; 34 import static org.xml.sax.ptests.SAXTestConst.XML_DIR; 35 36 /** 37 * This tests the Attributes interface. Here the startElement() callback of 38 * ContentHandler has Attributes as one of its arguments. Attributes 39 * pertaining to an element are taken into this argument and various methods 40 * of Attributes interfaces are tested. This program uses Namespace processing 41 * with namespaces in XML file. This program does not use Validation 42 */ 43 public class AttributesNSTest extends JAXPFileBaseTest { 44 /** 45 * Test for Attribute Interface's setter/getter. 46 * 47 * @throws Exception If any errors occur. 48 */ 49 @Test 50 public void testcase01() throws Exception { 51 String outputFile = USER_DIR + "AttributesNS.out"; 52 String goldFile = GOLDEN_DIR + "AttributesNSGF.out"; 53 String xmlFile = XML_DIR + "namespace1.xml"; 54 SAXParserFactory spf = SAXParserFactory.newInstance(); 55 spf.setNamespaceAware(true); 56 // http://www.saxproject.com/?selected=namespaces namespace-prefixes 57 //set to false to supress xmlns attributes 58 spf.setFeature("http://xml.org/sax/features/namespace-prefixes", 59 false); 60 SAXParser saxParser = spf.newSAXParser(); 61 MyAttrCHandler myAttrCHandler = new MyAttrCHandler(outputFile); 62 saxParser.parse(new File(xmlFile), myAttrCHandler); 63 myAttrCHandler.flushAndClose(); 64 assertTrue(compareWithGold(goldFile, outputFile)); 65 } 66 }