mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-14 18:03:44 +00:00
8051536: Convert JAXP function tests: javax.xml.parsers to jtreg(testng) tests
Reviewed-by: lancea, joehw
This commit is contained in:
parent
2104d1b262
commit
b82fd80a36
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.xml.parsers.ptests;
|
||||
|
||||
import static jaxp.library.JAXPTestUtilities.FILE_SEP;
|
||||
import static jaxp.library.JAXPTestUtilities.USER_DIR;
|
||||
import static jaxp.library.JAXPTestUtilities.compareWithGold;
|
||||
import static jaxp.library.JAXPTestUtilities.failUnexpected;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.TransformerFactoryConfigurationError;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.sax.SAXResult;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* This tests DocumentBuilderFactory for namespace processing and no-namespace
|
||||
* processing.
|
||||
*/
|
||||
public class DBFNamespaceTest {
|
||||
|
||||
/**
|
||||
* Provide input for the cases that supporting namespace or not.
|
||||
*/
|
||||
@DataProvider(name = "input-provider")
|
||||
public Object[][] getInput() {
|
||||
DocumentBuilderFactory dbf1 = DocumentBuilderFactory.newInstance();
|
||||
String outputfile1 = USER_DIR + FILE_SEP + "dbfnstest01.out";
|
||||
String goldfile1 = TestUtils.GOLDEN_DIR + FILE_SEP + "dbfnstest01GF.out";
|
||||
|
||||
DocumentBuilderFactory dbf2 = DocumentBuilderFactory.newInstance();
|
||||
dbf2.setNamespaceAware(true);
|
||||
String outputfile2 = USER_DIR + FILE_SEP + "dbfnstest02.out";
|
||||
String goldfile2 = TestUtils.GOLDEN_DIR + FILE_SEP + "dbfnstest02GF.out";
|
||||
return new Object[][] { { dbf1, outputfile1, goldfile1 }, { dbf2, outputfile2, goldfile2 } };
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to parse and transform a document without supporting namespace and
|
||||
* with supporting namespace.
|
||||
*/
|
||||
@Test(dataProvider = "input-provider")
|
||||
public void testNamespaceTest(DocumentBuilderFactory dbf, String outputfile, String goldfile) {
|
||||
try {
|
||||
Document doc = dbf.newDocumentBuilder().parse(new File(TestUtils.XML_DIR, "namespace1.xml"));
|
||||
dummyTransform(doc, outputfile);
|
||||
assertTrue(compareWithGold(goldfile, outputfile));
|
||||
} catch (SAXException | IOException | ParserConfigurationException | TransformerFactoryConfigurationError | TransformerException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method transforms a Node without any xsl file and uses SAXResult to
|
||||
* invoke the callbacks through a ContentHandler. If namespace processing is
|
||||
* not chosen, namespaceURI in callbacks should be an empty string otherwise
|
||||
* it should be namespaceURI.
|
||||
*
|
||||
* @throws TransformerFactoryConfigurationError
|
||||
* @throws TransformerException
|
||||
* @throws IOException
|
||||
*/
|
||||
private void dummyTransform(Document document, String fileName) throws TransformerFactoryConfigurationError, TransformerException, IOException {
|
||||
DOMSource domSource = new DOMSource(document);
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
File file = new File(fileName);
|
||||
System.out.println("The fileName is " + file.getAbsolutePath());
|
||||
transformer.transform(domSource, new SAXResult(MyCHandler.newInstance(file)));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,451 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.xml.parsers.ptests;
|
||||
|
||||
import static jaxp.library.JAXPTestUtilities.FILE_SEP;
|
||||
import static jaxp.library.JAXPTestUtilities.failUnexpected;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
/**
|
||||
* This checks the methods of DocumentBuilderFactoryImpl
|
||||
*/
|
||||
public class DocumentBuilderFactory01 {
|
||||
/**
|
||||
* Testcase to test the default functionality of schema support method.
|
||||
*/
|
||||
@Test
|
||||
public void testCheckSchemaSupport1() {
|
||||
try {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
dbf.setValidating(true);
|
||||
dbf.setNamespaceAware(true);
|
||||
dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
|
||||
MyErrorHandler eh = MyErrorHandler.newInstance();
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
db.setErrorHandler(eh);
|
||||
Document doc = db.parse(new File(TestUtils.XML_DIR, "test.xml"));
|
||||
assertFalse(eh.errorOccured);
|
||||
} catch (ParserConfigurationException | SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the default functionality of schema support method. In
|
||||
* this case the schema source property is set.
|
||||
*/
|
||||
@Test
|
||||
public void testCheckSchemaSupport2() {
|
||||
try {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
dbf.setValidating(true);
|
||||
dbf.setNamespaceAware(true);
|
||||
dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
|
||||
dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", new InputSource(new FileInputStream(
|
||||
new File(TestUtils.XML_DIR, "test.xsd"))));
|
||||
MyErrorHandler eh = MyErrorHandler.newInstance();
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
db.setErrorHandler(eh);
|
||||
Document doc = db.parse(new File(TestUtils.XML_DIR, "test1.xml"));
|
||||
assertFalse(eh.errorOccured);
|
||||
} catch (IllegalArgumentException | ParserConfigurationException | SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the default functionality of schema support method. In
|
||||
* this case the schema source property is set.
|
||||
*/
|
||||
@Test
|
||||
public void testCheckSchemaSupport3() {
|
||||
try {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
spf.setNamespaceAware(true);
|
||||
spf.setValidating(true);
|
||||
spf.setNamespaceAware(true);
|
||||
SAXParser sp = spf.newSAXParser();
|
||||
sp.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
|
||||
sp.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource",
|
||||
new InputSource(new FileInputStream(new File(TestUtils.XML_DIR, "test.xsd"))));
|
||||
DefaultHandler dh = new DefaultHandler();
|
||||
sp.parse(new File(TestUtils.XML_DIR, "test1.xml"), dh);
|
||||
} catch (ParserConfigurationException | SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the default functionality of newInstance method. To test
|
||||
* the isCoalescing method and setCoalescing This checks to see if the CDATA
|
||||
* and text nodes got combined In that case it will print "<xml>This
|
||||
* is not parsed</xml> yet".
|
||||
*/
|
||||
@Test
|
||||
public void testCheckDocumentBuilderFactory02() {
|
||||
try {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
dbf.setCoalescing(true);
|
||||
DocumentBuilder docBuilder = dbf.newDocumentBuilder();
|
||||
Document doc = docBuilder.parse(new File(TestUtils.XML_DIR, "DocumentBuilderFactory01.xml"));
|
||||
Element e = (Element) doc.getElementsByTagName("html").item(0);
|
||||
NodeList nl = e.getChildNodes();
|
||||
assertEquals(nl.item(0).getNodeValue().trim(), "<xml>This is not parsed</xml> yet");
|
||||
} catch (IOException | SAXException | ParserConfigurationException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the isIgnoringComments. By default it is false.
|
||||
*/
|
||||
@Test
|
||||
public void testCheckDocumentBuilderFactory03() {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
assertFalse(dbf.isIgnoringComments());
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the isValidating. By default it is false, set it to true
|
||||
* and then use a document which is not valid. It should throw a warning or
|
||||
* an error at least. The test passes in case retval 0 is set in the error
|
||||
* method .
|
||||
*/
|
||||
@Test
|
||||
public void testCheckDocumentBuilderFactory04() {
|
||||
try {
|
||||
MyErrorHandler eh = MyErrorHandler.newInstance();
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
dbf.setValidating(true);
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
db.setErrorHandler(eh);
|
||||
Document doc = db.parse(new File(TestUtils.XML_DIR, "DocumentBuilderFactory05.xml"));
|
||||
assertTrue(eh.errorOccured);
|
||||
} catch (ParserConfigurationException | IOException | SAXException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the setValidating. By default it is false, use a
|
||||
* document which is not valid. It should not throw a warning or an error.
|
||||
* The test passes in case the retval equals 1 .
|
||||
*/
|
||||
@Test
|
||||
public void testCheckDocumentBuilderFactory16() {
|
||||
try {
|
||||
MyErrorHandler eh = MyErrorHandler.newInstance();
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
db.setErrorHandler(eh);
|
||||
Document doc = db.parse(new File(TestUtils.XML_DIR, "DocumentBuilderFactory05.xml"));
|
||||
assertFalse(eh.errorOccured);
|
||||
} catch (ParserConfigurationException | IOException | SAXException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the setValidating. By default it is false, use a
|
||||
* document which is valid. It should not throw a warning or an error. The
|
||||
* test passes in case the retval equals 1.
|
||||
*/
|
||||
@Test
|
||||
public void testCheckDocumentBuilderFactory17() {
|
||||
try {
|
||||
MyErrorHandler eh = MyErrorHandler.newInstance();
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
db.setErrorHandler(eh);
|
||||
Document doc = db.parse(new File(TestUtils.XML_DIR, "DocumentBuilderFactory04.xml"));
|
||||
assertFalse(eh.errorOccured);
|
||||
} catch (ParserConfigurationException | IOException | SAXException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* To test the isExpandEntityReferences. By default it is true.
|
||||
*/
|
||||
@Test
|
||||
public void testCheckDocumentBuilderFactory05() {
|
||||
try {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder docBuilder = dbf.newDocumentBuilder();
|
||||
Document doc = docBuilder.parse(new FileInputStream(new File(TestUtils.XML_DIR, "DocumentBuilderFactory02.xml")));
|
||||
Element e = (Element) doc.getElementsByTagName("title").item(0);
|
||||
NodeList nl = e.getChildNodes();
|
||||
assertTrue(dbf.isExpandEntityReferences());
|
||||
assertEquals(nl.item(0).getNodeValue().trim().charAt(0), 'W');
|
||||
} catch (ParserConfigurationException | IOException | SAXException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the default functionality of setValidating method. The
|
||||
* xml file has a DTD which has namespaces defined. The parser takes care to
|
||||
* check if the namespaces using elements and defined attributes are there
|
||||
* or not.
|
||||
*/
|
||||
@Test
|
||||
public void testCheckDocumentBuilderFactory06() {
|
||||
try {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
dbf.setValidating(true);
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
MyErrorHandler eh = MyErrorHandler.newInstance();
|
||||
db.setErrorHandler(eh);
|
||||
Document doc = db.parse(new File(TestUtils.XML_DIR, "DocumentBuilderFactory04.xml"));
|
||||
assertTrue(doc instanceof Document);
|
||||
assertFalse(eh.errorOccured);
|
||||
} catch (ParserConfigurationException | IOException | SAXException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the setExpandEntityReferences.
|
||||
*/
|
||||
@Test
|
||||
public void testCheckDocumentBuilderFactory07() {
|
||||
try {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
dbf.setExpandEntityReferences(true);
|
||||
DocumentBuilder docBuilder = dbf.newDocumentBuilder();
|
||||
Document doc = docBuilder.parse(new FileInputStream(new File(TestUtils.XML_DIR, "DocumentBuilderFactory02.xml")));
|
||||
Element e = (Element) doc.getElementsByTagName("title").item(0);
|
||||
NodeList nl = e.getChildNodes();
|
||||
assertTrue(dbf.isExpandEntityReferences());
|
||||
assertEquals(nl.item(0).getNodeValue().trim().charAt(0), 'W');
|
||||
} catch (ParserConfigurationException | IOException | SAXException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the setExpandEntityReferences.
|
||||
*/
|
||||
@Test
|
||||
public void testCheckDocumentBuilderFactory08() {
|
||||
try {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
dbf.setExpandEntityReferences(false);
|
||||
DocumentBuilder docBuilder = dbf.newDocumentBuilder();
|
||||
Document doc = docBuilder.parse(new FileInputStream(new File(TestUtils.XML_DIR, "DocumentBuilderFactory02.xml")));
|
||||
Element e = (Element) doc.getElementsByTagName("title").item(0);
|
||||
NodeList nl = e.getChildNodes();
|
||||
assertNull(nl.item(0).getNodeValue());
|
||||
} catch (ParserConfigurationException | IOException | SAXException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the setIgnoringComments. By default it is set to false.
|
||||
* explicitly setting it to false, it recognizes the comment which is in
|
||||
* Element Node Hence the Element's child node is not null.
|
||||
*/
|
||||
@Test
|
||||
public void testCheckDocumentBuilderFactory09() {
|
||||
try {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
dbf.setIgnoringComments(false);
|
||||
DocumentBuilder docBuilder = dbf.newDocumentBuilder();
|
||||
Document doc = docBuilder.parse(new FileInputStream(new File(TestUtils.XML_DIR, "DocumentBuilderFactory07.xml")));
|
||||
Element e = (Element) doc.getElementsByTagName("body").item(0);
|
||||
NodeList nl = e.getChildNodes();
|
||||
assertNotNull(nl.item(0).getNodeValue());
|
||||
} catch (ParserConfigurationException | IOException | SAXException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This tests for the parse(InputSource).
|
||||
*/
|
||||
@Test
|
||||
public void testCheckDocumentBuilderFactory10() {
|
||||
try {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder docBuilder = dbf.newDocumentBuilder();
|
||||
Document doc = docBuilder.parse(new InputSource(new BufferedReader(new FileReader(new File(TestUtils.XML_DIR, "DocumentBuilderFactory07.xml")))));
|
||||
assertTrue(doc instanceof Document);
|
||||
} catch (IllegalArgumentException | ParserConfigurationException | IOException | SAXException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This tests for the parse InputStream with SystemID as a second parameter.
|
||||
*/
|
||||
@Test
|
||||
public void testCheckDocumentBuilderFactory11() {
|
||||
try {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder docBuilder = dbf.newDocumentBuilder();
|
||||
Document doc = docBuilder.parse(new FileInputStream(new File(TestUtils.XML_DIR, "dbf10import.xsl")), new File(TestUtils.XML_DIR).toURI()
|
||||
.toASCIIString());
|
||||
assertTrue(doc instanceof Document);
|
||||
} catch (IllegalArgumentException | ParserConfigurationException | IOException | SAXException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This tests for the parse InputStream with empty SystemID as a second
|
||||
* parameter.
|
||||
*/
|
||||
@Test
|
||||
public void testCheckDocumentBuilderFactory12() {
|
||||
try {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder docBuilder = dbf.newDocumentBuilder();
|
||||
Document doc = docBuilder.parse(new FileInputStream(new File(TestUtils.XML_DIR, "dbf10import.xsl")), " ");
|
||||
assertTrue(doc instanceof Document);
|
||||
} catch (IllegalArgumentException | ParserConfigurationException | IOException | SAXException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This tests for the parse(uri).
|
||||
*/
|
||||
@Test
|
||||
public void testCheckDocumentBuilderFactory13() {
|
||||
try {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder docBuilder = dbf.newDocumentBuilder();
|
||||
Document doc = docBuilder.parse(new File(TestUtils.XML_DIR + FILE_SEP + "dbf10import.xsl").toURI().toASCIIString());
|
||||
assertTrue(doc instanceof Document);
|
||||
} catch (IllegalArgumentException | ParserConfigurationException | IOException | SAXException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This tests for the parse (uri) with empty string as parameter should
|
||||
* throw Sax Exception.
|
||||
*
|
||||
* @throws SAXException
|
||||
* If any parse errors occur.
|
||||
*/
|
||||
@Test(expectedExceptions = SAXException.class)
|
||||
public void testCheckDocumentBuilderFactory14() throws SAXException {
|
||||
try {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder docBuilder = dbf.newDocumentBuilder();
|
||||
docBuilder.parse("");
|
||||
} catch (ParserConfigurationException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This tests for the parse (uri) with null uri as parameter should throw
|
||||
* IllegalArgumentException.
|
||||
*
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testCheckDocumentBuilderFactory15() {
|
||||
try {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder docBuilder = dbf.newDocumentBuilder();
|
||||
String uri = null;
|
||||
docBuilder.parse(uri);
|
||||
} catch (ParserConfigurationException | SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the setIgnoringComments. By default it is set to false,
|
||||
* setting this to true, It does not recognize the comment, Here the
|
||||
* nodelist has a length 0 because the ignoring comments is true.
|
||||
*/
|
||||
@Test
|
||||
public void testCheckIgnoringComments() {
|
||||
try {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
dbf.setIgnoringComments(true);
|
||||
DocumentBuilder docBuilder = dbf.newDocumentBuilder();
|
||||
Document doc = docBuilder.parse(new FileInputStream(new File(TestUtils.XML_DIR, "DocumentBuilderFactory08.xml")));
|
||||
Element e = (Element) doc.getElementsByTagName("body").item(0);
|
||||
NodeList nl = e.getChildNodes();
|
||||
assertEquals(nl.getLength(), 0);
|
||||
} catch (ParserConfigurationException | SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the default behaviour of setIgnoringComments. By default
|
||||
* it is set to false, this is similar to case 9 but not setIgnoringComments
|
||||
* explicitly, it does not recognize the comment.
|
||||
*/
|
||||
@Test
|
||||
public void testCheckIgnoringComments1() {
|
||||
try {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder docBuilder = dbf.newDocumentBuilder();
|
||||
Document doc = docBuilder.parse(new FileInputStream(new File(TestUtils.XML_DIR, "DocumentBuilderFactory07.xml")));
|
||||
Element e = (Element) doc.getElementsByTagName("body").item(0);
|
||||
NodeList nl = e.getChildNodes();
|
||||
assertFalse(dbf.isIgnoringComments());
|
||||
assertNotNull(nl.item(0).getNodeValue());
|
||||
} catch (ParserConfigurationException | SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.xml.parsers.ptests;
|
||||
|
||||
import static jaxp.library.JAXPTestUtilities.FILE_SEP;
|
||||
import static jaxp.library.JAXPTestUtilities.USER_DIR;
|
||||
import static jaxp.library.JAXPTestUtilities.compareWithGold;
|
||||
import static jaxp.library.JAXPTestUtilities.failUnexpected;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.sax.SAXResult;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* This tests the setIgnoringElementWhitespace and setIgnoringComments of
|
||||
* DocumentBuilderFactory
|
||||
*/
|
||||
public class DocumentBuilderFactory02 {
|
||||
|
||||
/**
|
||||
* This testcase tests for the isIgnoringElementContentWhitespace and the
|
||||
* setIgnoringElementContentWhitespace. The xml file has all kinds of
|
||||
* whitespace,tab and newline characters, it uses the MyNSContentHandler
|
||||
* which does not invoke the characters callback when this
|
||||
* setIgnoringElementContentWhitespace is set to true.
|
||||
*/
|
||||
@Test
|
||||
public void testCheckElementContentWhitespace() {
|
||||
try {
|
||||
String goldFile = TestUtils.GOLDEN_DIR + FILE_SEP + "dbfactory02GF.out";
|
||||
String outputFile = USER_DIR + FILE_SEP + "dbfactory02.out";
|
||||
MyErrorHandler eh = MyErrorHandler.newInstance();
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
dbf.setValidating(true);
|
||||
assertFalse(dbf.isIgnoringElementContentWhitespace());
|
||||
dbf.setIgnoringElementContentWhitespace(true);
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
db.setErrorHandler(eh);
|
||||
Document doc = db.parse(new File(TestUtils.XML_DIR, "DocumentBuilderFactory06.xml"));
|
||||
assertFalse(eh.errorOccured);
|
||||
DOMSource domSource = new DOMSource(doc);
|
||||
TransformerFactory tfactory = TransformerFactory.newInstance();
|
||||
Transformer transformer = tfactory.newTransformer();
|
||||
SAXResult saxResult = new SAXResult();
|
||||
saxResult.setHandler(MyCHandler.newInstance(new File(outputFile)));
|
||||
transformer.transform(domSource, saxResult);
|
||||
assertTrue(compareWithGold(goldFile, outputFile));
|
||||
} catch (ParserConfigurationException | SAXException | IOException | TransformerException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.xml.parsers.ptests;
|
||||
|
||||
import static jaxp.library.JAXPTestUtilities.FILE_SEP;
|
||||
import static jaxp.library.JAXPTestUtilities.failUnexpected;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.EntityResolver;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* This checks for the methods of DocumentBuilder
|
||||
*/
|
||||
public class DocumentBuilderImpl01 implements EntityResolver {
|
||||
|
||||
/**
|
||||
* Provide DocumentBuilder.
|
||||
*
|
||||
* @throws ParserConfigurationException
|
||||
*/
|
||||
@DataProvider(name = "builder-provider")
|
||||
public Object[][] getBuilder() throws ParserConfigurationException {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder docBuilder = dbf.newDocumentBuilder();
|
||||
return new Object[][] { { docBuilder } };
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the default functionality of isValidation method. Expect
|
||||
* to return false because not setting the validation.
|
||||
*/
|
||||
@Test(dataProvider = "builder-provider")
|
||||
public void testCheckDocumentBuilderImpl01(DocumentBuilder docBuilder) {
|
||||
assertFalse(docBuilder.isValidating());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the default functionality of isNamespaceAware method.
|
||||
*/
|
||||
@Test(dataProvider = "builder-provider")
|
||||
public void testCheckDocumentBuilderImpl02(DocumentBuilder docBuilder) {
|
||||
assertFalse(docBuilder.isNamespaceAware());
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the parse(InputStream).
|
||||
*/
|
||||
@Test(dataProvider = "builder-provider")
|
||||
public void testCheckDocumentBuilderImpl04(DocumentBuilder docBuilder) {
|
||||
try {
|
||||
Document doc = docBuilder.parse(new FileInputStream(new File(TestUtils.XML_DIR, "DocumentBuilderImpl01.xml")));
|
||||
} catch (SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the parse(File).
|
||||
*/
|
||||
@Test(dataProvider = "builder-provider")
|
||||
public void testCheckDocumentBuilderImpl05(DocumentBuilder docBuilder) {
|
||||
try {
|
||||
Document doc = docBuilder.parse(new File(TestUtils.XML_DIR, "DocumentBuilderImpl01.xml"));
|
||||
} catch (SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the parse(InputStream,systemId).
|
||||
*/
|
||||
@Test(dataProvider = "builder-provider")
|
||||
public void testCheckDocumentBuilderImpl06(DocumentBuilder docBuilder) {
|
||||
try {
|
||||
Document doc = docBuilder.parse(new FileInputStream(new File(TestUtils.XML_DIR, "DocumentBuilderImpl02.xml")), new File(TestUtils.XML_DIR).toURI()
|
||||
.toASCIIString() + FILE_SEP);
|
||||
} catch (SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the setEntityResolver.
|
||||
*/
|
||||
@Test(dataProvider = "builder-provider")
|
||||
public void testCheckDocumentBuilderImpl07(DocumentBuilder docBuilder) {
|
||||
docBuilder.setEntityResolver(this);
|
||||
resolveEntity("publicId", "http://www.myhost.com/today");
|
||||
}
|
||||
|
||||
public InputSource resolveEntity(String publicId, String systemId) {
|
||||
if (systemId.equals("http://www.myhost.com/today"))
|
||||
return new InputSource(systemId);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.xml.parsers.ptests;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.FactoryConfigurationError;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
import org.testng.annotations.AfterTest;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Class containing the test cases for SAXParserFactory/DocumentBuilderFactory
|
||||
* newInstance methods.
|
||||
*/
|
||||
public class FactoryConfErrorTest {
|
||||
|
||||
/**
|
||||
* Set properties DocumentBuilderFactory and SAXParserFactory to invalid
|
||||
* value before any test run.
|
||||
*/
|
||||
@BeforeTest
|
||||
public void setup() {
|
||||
System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "xx");
|
||||
System.setProperty("javax.xml.parsers.SAXParserFactory", "xx");
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore properties DocumentBuilderFactory and SAXParserFactory to default
|
||||
* value after all tests run.
|
||||
*/
|
||||
@AfterTest
|
||||
public void cleanup() {
|
||||
System.clearProperty("javax.xml.parsers.DocumentBuilderFactory");
|
||||
System.clearProperty("javax.xml.parsers.SAXParserFactory");
|
||||
}
|
||||
|
||||
/**
|
||||
* To test exception thrown if javax.xml.parsers.SAXParserFactory property
|
||||
* is invalid.
|
||||
*/
|
||||
@Test(expectedExceptions = FactoryConfigurationError.class)
|
||||
public void testNewInstance01() {
|
||||
SAXParserFactory.newInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* To test exeception thrown if javax.xml.parsers.DocumentBuilderFactory is
|
||||
* invalid.
|
||||
*/
|
||||
@Test(expectedExceptions = FactoryConfigurationError.class)
|
||||
public void testNewInstance02() {
|
||||
DocumentBuilderFactory.newInstance();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,268 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.xml.parsers.ptests;
|
||||
|
||||
import static jaxp.library.JAXPTestUtilities.failUnexpected;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXNotRecognizedException;
|
||||
import org.xml.sax.SAXNotSupportedException;
|
||||
|
||||
/**
|
||||
* Class containing the test cases for SAXParserFactory API
|
||||
*/
|
||||
public class SAXParserFactTest {
|
||||
|
||||
private static final String NAMESPACES = "http://xml.org/sax/features/namespaces";
|
||||
private static final String NAMESPACE_PREFIXES = "http://xml.org/sax/features/namespace-prefixes";
|
||||
private static final String STRING_INTERNING = "http://xml.org/sax/features/string-interning";
|
||||
private static final String VALIDATION = "http://xml.org/sax/features/validation";
|
||||
private static final String EXTERNAL_G_ENTITIES = "http://xml.org/sax/features/external-general-entities";
|
||||
private static final String EXTERNAL_P_ENTITIES = "http://xml.org/sax/features/external-parameter-entities";
|
||||
|
||||
/**
|
||||
* Testcase to test if newSAXParser() method returns SAXParser.
|
||||
*/
|
||||
@Test
|
||||
public void testParser01() {
|
||||
try {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
SAXParser saxparser = spf.newSAXParser();
|
||||
} catch (ParserConfigurationException | SAXException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the default functionality (No validation) of the parser.
|
||||
*/
|
||||
@Test
|
||||
public void testValidate01() {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
assertFalse(spf.isValidating());
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the functionality of setValidating and isvalidating
|
||||
* methods.
|
||||
*/
|
||||
@Test
|
||||
public void testValidate02() {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
spf.setValidating(true);
|
||||
assertTrue(spf.isValidating());
|
||||
}
|
||||
|
||||
/**
|
||||
* Parser should not be namespaceaware by default.
|
||||
*/
|
||||
@Test
|
||||
public void testNamespace01() {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
assertFalse(spf.isNamespaceAware());
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the functionality of setNamespaceAware and
|
||||
* isNamespaceAware methods.
|
||||
*/
|
||||
@Test
|
||||
public void testNamespace02() {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
spf.setNamespaceAware(true);
|
||||
assertTrue(spf.isNamespaceAware());
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the functionality of setNamespaceAware and getFeature()
|
||||
* methods for namespaces property.
|
||||
*/
|
||||
@Test
|
||||
public void testFeature01() {
|
||||
try {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
assertFalse(spf.getFeature(NAMESPACES));
|
||||
|
||||
spf.setNamespaceAware(true);
|
||||
assertTrue(spf.getFeature(NAMESPACES));
|
||||
} catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the functionality of setFeature and getFeature methods
|
||||
* for namespaces property.
|
||||
*/
|
||||
@Test
|
||||
public void testFeature02() {
|
||||
try {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
|
||||
spf.setFeature(NAMESPACES, true);
|
||||
assertTrue(spf.getFeature(NAMESPACES));
|
||||
|
||||
spf.setFeature(NAMESPACES, false);
|
||||
assertFalse(spf.getFeature(NAMESPACES));
|
||||
} catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the functionality of setFeature and getFeature methods
|
||||
* for namespace-prefixes property.
|
||||
*/
|
||||
@Test
|
||||
public void testFeature03() {
|
||||
try {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
|
||||
spf.setFeature(NAMESPACE_PREFIXES, true);
|
||||
assertTrue(spf.getFeature(NAMESPACE_PREFIXES));
|
||||
|
||||
spf.setFeature(NAMESPACE_PREFIXES, false);
|
||||
assertFalse(spf.getFeature(NAMESPACE_PREFIXES));
|
||||
} catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the functionality of getFeature method for
|
||||
* string-interning property.
|
||||
*/
|
||||
@Test
|
||||
public void testFeature04() {
|
||||
try {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
assertTrue(spf.getFeature(STRING_INTERNING));
|
||||
} catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the functionality of getFeature and setValidating
|
||||
* methods for validation property.
|
||||
*/
|
||||
@Test
|
||||
public void testFeature05() {
|
||||
try {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
assertFalse(spf.getFeature(VALIDATION));
|
||||
spf.setValidating(true);
|
||||
assertTrue(spf.getFeature(VALIDATION));
|
||||
} catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the functionality of setFeature and getFeature methods
|
||||
* for validation property.
|
||||
*/
|
||||
@Test
|
||||
public void testFeature06() {
|
||||
try {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
|
||||
spf.setFeature(VALIDATION, true);
|
||||
assertTrue(spf.getFeature(VALIDATION));
|
||||
|
||||
spf.setFeature(VALIDATION, false);
|
||||
assertFalse(spf.getFeature(VALIDATION));
|
||||
} catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the functionality of getFeature method for
|
||||
* external-general-entities property.
|
||||
*/
|
||||
@Test
|
||||
public void testFeature07() {
|
||||
try {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
assertTrue(spf.getFeature(EXTERNAL_G_ENTITIES));
|
||||
} catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the functionality of setFeature and getFeature methods
|
||||
* for external-general-entities property.
|
||||
*/
|
||||
@Test
|
||||
public void testFeature08() {
|
||||
try {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
spf.setFeature(EXTERNAL_G_ENTITIES, false);
|
||||
assertFalse(spf.getFeature(EXTERNAL_G_ENTITIES));
|
||||
} catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the functionality of getFeature method for
|
||||
* external-parameter-entities property.
|
||||
*/
|
||||
@Test
|
||||
public void testFeature09() {
|
||||
try {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
assertTrue(spf.getFeature(EXTERNAL_P_ENTITIES));
|
||||
} catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the functionality of setFeature method for
|
||||
* external-parameter-entitie property.
|
||||
*/
|
||||
@Test
|
||||
public void testFeature10() {
|
||||
try {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
spf.setFeature(EXTERNAL_P_ENTITIES, false);
|
||||
} catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,559 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.xml.parsers.ptests;
|
||||
|
||||
import static jaxp.library.JAXPTestUtilities.failUnexpected;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.xml.sax.HandlerBase;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
/**
|
||||
* Class contains the test cases for SAXParser API
|
||||
*/
|
||||
public class SAXParserTest {
|
||||
|
||||
/**
|
||||
* Provide SAXParser.
|
||||
*
|
||||
* @throws SAXException
|
||||
* @throws ParserConfigurationException
|
||||
*/
|
||||
@DataProvider(name = "parser-provider")
|
||||
public Object[][] getParser() throws ParserConfigurationException, SAXException {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
SAXParser saxparser = spf.newSAXParser();
|
||||
return new Object[][] { { saxparser } };
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case with FileInputStream null, parsing should fail and throw
|
||||
* IllegalArgumentException.
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
|
||||
public void testParse01(SAXParser saxparser) throws IllegalArgumentException {
|
||||
try {
|
||||
FileInputStream instream = null;
|
||||
HandlerBase handler = new HandlerBase();
|
||||
saxparser.parse(instream, handler);
|
||||
} catch (SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with an error in xml file, parsing should fail and throw
|
||||
* SAXException.
|
||||
*
|
||||
* @throws SAXException
|
||||
*/
|
||||
@Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
|
||||
public void testParse02(SAXParser saxparser) throws SAXException {
|
||||
try {
|
||||
HandlerBase handler = new HandlerBase();
|
||||
FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "invalid.xml"));
|
||||
saxparser.parse(instream, handler);
|
||||
} catch (IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with a valid in xml file, parser should parse the xml document.
|
||||
*/
|
||||
@Test(dataProvider = "parser-provider")
|
||||
public void testParse03(SAXParser saxparser) {
|
||||
try {
|
||||
HandlerBase handler = new HandlerBase();
|
||||
saxparser.parse(new File(TestUtils.XML_DIR, "parsertest.xml"), handler);
|
||||
} catch (IOException | SAXException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with valid input stream, parser should parse the xml document
|
||||
* successfully.
|
||||
*/
|
||||
@Test(dataProvider = "parser-provider")
|
||||
public void testParse04(SAXParser saxparser) {
|
||||
try {
|
||||
HandlerBase handler = new HandlerBase();
|
||||
FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "correct.xml"));
|
||||
saxparser.parse(instream, handler);
|
||||
} catch (SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with valid input source, parser should parse the xml document
|
||||
* successfully.
|
||||
*/
|
||||
@Test(dataProvider = "parser-provider")
|
||||
public void testParse05(SAXParser saxparser) {
|
||||
try {
|
||||
HandlerBase handler = new HandlerBase();
|
||||
FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "parsertest.xml"));
|
||||
saxparser.parse(instream, handler, new File(TestUtils.XML_DIR).toURI().toASCIIString());
|
||||
} catch (SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with uri null, parsing should fail and throw
|
||||
* IllegalArgumentException.
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
|
||||
public void testParse07(SAXParser saxparser) throws IllegalArgumentException {
|
||||
try {
|
||||
String uri = null;
|
||||
HandlerBase handler = new HandlerBase();
|
||||
saxparser.parse(uri, handler);
|
||||
} catch (SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with non-existant uri, parsing should fail and throw
|
||||
* IOException.
|
||||
*
|
||||
* @throws SAXException
|
||||
* @throws IOException
|
||||
*/
|
||||
@Test(expectedExceptions = { SAXException.class, IOException.class }, dataProvider = "parser-provider")
|
||||
public void testParse08(SAXParser saxparser) throws SAXException, IOException {
|
||||
String uri = " ";
|
||||
|
||||
HandlerBase handler = new HandlerBase();
|
||||
saxparser.parse(uri, handler);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with proper uri, parser should parse successfully.
|
||||
*/
|
||||
@Test(dataProvider = "parser-provider")
|
||||
public void testParse09(SAXParser saxparser) {
|
||||
try {
|
||||
File file = new File(TestUtils.XML_DIR, "correct.xml");
|
||||
HandlerBase handler = new HandlerBase();
|
||||
saxparser.parse(file.toURI().toASCIIString(), handler);
|
||||
} catch (SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with File null, parsing should fail and throw
|
||||
* IllegalArgumentException.
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
|
||||
public void testParse10(SAXParser saxparser) throws IllegalArgumentException {
|
||||
try {
|
||||
File file = null;
|
||||
HandlerBase handler = new HandlerBase();
|
||||
saxparser.parse(file, handler);
|
||||
} catch (SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with empty string as File, parsing should fail and throw
|
||||
* SAXException.
|
||||
*
|
||||
* @throws SAXException
|
||||
*/
|
||||
@Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
|
||||
public void testParse11(SAXParser saxparser) throws SAXException {
|
||||
try {
|
||||
HandlerBase handler = new HandlerBase();
|
||||
File file = new File("");
|
||||
saxparser.parse(file, handler);
|
||||
} catch (IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with xml file that has errors parsing should fail and throw
|
||||
* SAXException.
|
||||
*
|
||||
* @throws SAXException
|
||||
*/
|
||||
@Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
|
||||
public void testParse12(SAXParser saxparser) throws SAXException {
|
||||
try {
|
||||
HandlerBase handler = new HandlerBase();
|
||||
File file = new File(TestUtils.XML_DIR, "valid.xml");
|
||||
saxparser.parse(file, handler);
|
||||
} catch (IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with xml file that has no errors Parser should successfully
|
||||
* parse the xml document.
|
||||
*/
|
||||
@Test(dataProvider = "parser-provider")
|
||||
public void testParse13(SAXParser saxparser) {
|
||||
try {
|
||||
HandlerBase handler = new HandlerBase();
|
||||
File file = new File(TestUtils.XML_DIR, "correct.xml");
|
||||
saxparser.parse(file, handler);
|
||||
} catch (SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with input source null, parsing should fail and throw
|
||||
* IllegalArgumentException.
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
|
||||
public void testParse14(SAXParser saxparser) throws IllegalArgumentException {
|
||||
try {
|
||||
InputSource is = null;
|
||||
HandlerBase handler = new HandlerBase();
|
||||
saxparser.parse(is, handler);
|
||||
} catch (SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with input source attached an invaild xml, parsing should fail
|
||||
* and throw SAXException.
|
||||
*
|
||||
* @throws SAXException
|
||||
*/
|
||||
@Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
|
||||
public void testParse15(SAXParser saxparser) throws SAXException {
|
||||
try {
|
||||
HandlerBase handler = new HandlerBase();
|
||||
FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "invalid.xml"));
|
||||
InputSource is = new InputSource(instream);
|
||||
saxparser.parse(is, handler);
|
||||
} catch (IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with input source attached an vaild xml, parser should
|
||||
* successfully parse the xml document.
|
||||
*/
|
||||
@Test(dataProvider = "parser-provider")
|
||||
public void testParse16(SAXParser saxparser) {
|
||||
try {
|
||||
HandlerBase handler = new HandlerBase();
|
||||
FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "correct.xml"));
|
||||
InputSource is = new InputSource(instream);
|
||||
saxparser.parse(is, handler);
|
||||
} catch (SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with FileInputStream null, parsing should fail and throw
|
||||
* IllegalArgumentException.
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
|
||||
public void testParse17(SAXParser saxparser) throws IllegalArgumentException {
|
||||
try {
|
||||
FileInputStream instream = null;
|
||||
DefaultHandler handler = new DefaultHandler();
|
||||
saxparser.parse(instream, handler);
|
||||
} catch (SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with an error in xml file, parsing should fail and throw
|
||||
* SAXException.
|
||||
*
|
||||
* @throws SAXException
|
||||
*/
|
||||
@Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
|
||||
public void testParse18(SAXParser saxparser) throws SAXException {
|
||||
try {
|
||||
DefaultHandler handler = new DefaultHandler();
|
||||
FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "invalid.xml"));
|
||||
saxparser.parse(instream, handler);
|
||||
} catch (IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with valid input stream, parser should parse the xml document
|
||||
* successfully.
|
||||
*/
|
||||
@Test(dataProvider = "parser-provider")
|
||||
public void testParse19(SAXParser saxparser) {
|
||||
try {
|
||||
DefaultHandler handler = new DefaultHandler();
|
||||
saxparser.parse(new File(TestUtils.XML_DIR, "parsertest.xml"), handler);
|
||||
} catch (IOException | SAXException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with valid input stream, parser should parse the xml document
|
||||
* successfully.
|
||||
*/
|
||||
@Test(dataProvider = "parser-provider")
|
||||
public void testParse20(SAXParser saxparser) {
|
||||
try {
|
||||
DefaultHandler handler = new DefaultHandler();
|
||||
FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "correct.xml"));
|
||||
saxparser.parse(instream, handler);
|
||||
} catch (SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with valid input source, parser should parse the xml document
|
||||
* successfully.
|
||||
*/
|
||||
@Test(dataProvider = "parser-provider")
|
||||
public void testParse21(SAXParser saxparser) {
|
||||
try {
|
||||
DefaultHandler handler = new DefaultHandler();
|
||||
FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "parsertest.xml"));
|
||||
saxparser.parse(instream, handler, new File(TestUtils.XML_DIR).toURI().toASCIIString());
|
||||
} catch (SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with uri null, parsing should fail and throw
|
||||
* IllegalArgumentException.
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
|
||||
public void testParse23(SAXParser saxparser) throws IllegalArgumentException {
|
||||
try {
|
||||
String uri = null;
|
||||
DefaultHandler handler = new DefaultHandler();
|
||||
saxparser.parse(uri, handler);
|
||||
} catch (SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with non-existant uri, parsing should fail and throw
|
||||
* SAXException or IOException.
|
||||
*
|
||||
* @throws SAXException
|
||||
* @throws IOException
|
||||
*/
|
||||
@Test(expectedExceptions = { SAXException.class, IOException.class }, dataProvider = "parser-provider")
|
||||
public void testParse24(SAXParser saxparser) throws SAXException, IOException {
|
||||
String uri = " ";
|
||||
DefaultHandler handler = new DefaultHandler();
|
||||
saxparser.parse(uri, handler);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with proper uri, parser should parse successfully.
|
||||
*/
|
||||
@Test(dataProvider = "parser-provider")
|
||||
public void testParse25(SAXParser saxparser) {
|
||||
try {
|
||||
File file = new File(TestUtils.XML_DIR, "correct.xml");
|
||||
|
||||
DefaultHandler handler = new DefaultHandler();
|
||||
saxparser.parse(file.toURI().toASCIIString(), handler);
|
||||
} catch (SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with File null, parsing should fail and throw
|
||||
* IllegalArgumentException.
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
|
||||
public void testParse26(SAXParser saxparser) throws IllegalArgumentException {
|
||||
try {
|
||||
DefaultHandler handler = new DefaultHandler();
|
||||
saxparser.parse((File) null, handler);
|
||||
} catch (SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with empty string as File, parsing should fail and throw
|
||||
* SAXException.
|
||||
*
|
||||
* @throws SAXException
|
||||
*/
|
||||
@Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
|
||||
public void testParse27(SAXParser saxparser) throws SAXException {
|
||||
try {
|
||||
DefaultHandler handler = new DefaultHandler();
|
||||
File file = new File("");
|
||||
saxparser.parse(file, handler);
|
||||
} catch (IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with xml file that has errors, parsing should fail and throw
|
||||
* SAXException.
|
||||
*
|
||||
* @throws SAXException
|
||||
*/
|
||||
@Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
|
||||
public void testParse28(SAXParser saxparser) throws SAXException {
|
||||
try {
|
||||
DefaultHandler handler = new DefaultHandler();
|
||||
File file = new File(TestUtils.XML_DIR, "valid.xml");
|
||||
saxparser.parse(file, handler);
|
||||
} catch (IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with xml file that has no errors, parser should successfully
|
||||
* parse the xml document.
|
||||
*/
|
||||
@Test(dataProvider = "parser-provider")
|
||||
public void testParse29(SAXParser saxparser) {
|
||||
try {
|
||||
DefaultHandler handler = new DefaultHandler();
|
||||
File file = new File(TestUtils.XML_DIR, "correct.xml");
|
||||
saxparser.parse(file, handler);
|
||||
} catch (SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with input source null, parsing should fail and throw
|
||||
* IllegalArgumentException.
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
|
||||
public void testParse30(SAXParser saxparser) throws IllegalArgumentException {
|
||||
try {
|
||||
InputSource is = null;
|
||||
DefaultHandler handler = new DefaultHandler();
|
||||
saxparser.parse(is, handler);
|
||||
} catch (SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase with an invalid xml file, parser should throw SAXException.
|
||||
*
|
||||
* @throws SAXException
|
||||
*/
|
||||
@Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
|
||||
public void testParse31(SAXParser saxparser) throws SAXException {
|
||||
try {
|
||||
DefaultHandler handler = new DefaultHandler();
|
||||
FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "invalid.xml"));
|
||||
InputSource is = new InputSource(instream);
|
||||
saxparser.parse(is, handler);
|
||||
} catch (IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case to parse an xml file that not use namespaces.
|
||||
*/
|
||||
@Test(dataProvider = "parser-provider")
|
||||
public void testParse32(SAXParser saxparser) {
|
||||
try {
|
||||
DefaultHandler handler = new DefaultHandler();
|
||||
FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "correct.xml"));
|
||||
InputSource is = new InputSource(instream);
|
||||
saxparser.parse(is, handler);
|
||||
} catch (SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case to parse an xml file that uses namespaces.
|
||||
*/
|
||||
@Test
|
||||
public void testParse33() {
|
||||
try {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
spf.setNamespaceAware(true);
|
||||
SAXParser saxparser = spf.newSAXParser();
|
||||
HandlerBase handler = new HandlerBase();
|
||||
FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "ns4.xml"));
|
||||
saxparser.parse(instream, handler);
|
||||
} catch (ParserConfigurationException | SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,283 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.xml.parsers.ptests;
|
||||
|
||||
import static jaxp.library.JAXPTestUtilities.failUnexpected;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import javax.xml.parsers.FactoryConfigurationError;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.xml.sax.Parser;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXNotRecognizedException;
|
||||
import org.xml.sax.SAXNotSupportedException;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.ext.DeclHandler;
|
||||
import org.xml.sax.ext.LexicalHandler;
|
||||
|
||||
/**
|
||||
* Class contains the test cases for SAXParser API
|
||||
*/
|
||||
public class SAXParserTest02 {
|
||||
final String DOM_NODE = "http://xml.org/sax/properties/dom-node";
|
||||
final String XML_STRING = "http://xml.org/sax/properties/xml-string";
|
||||
final String DECL_HANDLER = "http://xml.org/sax/properties/declaration-handler";
|
||||
final String LEXICAL_HANDLER = "http://xml.org/sax/properties/lexical-handler";
|
||||
|
||||
/**
|
||||
* Provide SAXParser.
|
||||
*
|
||||
* @throws SAXException
|
||||
* @throws ParserConfigurationException
|
||||
*/
|
||||
@DataProvider(name = "parser-provider")
|
||||
public Object[][] getParser() throws ParserConfigurationException, SAXException {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
SAXParser saxparser = spf.newSAXParser();
|
||||
return new Object[][] { { saxparser } };
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the default functionality (No validation) of the parser.
|
||||
*/
|
||||
@Test(dataProvider = "parser-provider")
|
||||
public void testValidate01(SAXParser saxparser) {
|
||||
try {
|
||||
assertFalse(saxparser.isValidating());
|
||||
} catch (FactoryConfigurationError e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Testcase to test the functionality of setValidating and isvalidating
|
||||
* methods.
|
||||
*/
|
||||
@Test
|
||||
public void testValidate02() {
|
||||
try {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
spf.setValidating(true);
|
||||
spf.newSAXParser();
|
||||
assertTrue(spf.isValidating());
|
||||
} catch (FactoryConfigurationError | ParserConfigurationException | SAXException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case to test isNamespaceAware() method. By default, namespaces are
|
||||
* not supported.
|
||||
*/
|
||||
@Test(dataProvider = "parser-provider")
|
||||
public void testNamespace01(SAXParser saxparser) {
|
||||
try {
|
||||
assertFalse(saxparser.isNamespaceAware());
|
||||
} catch (FactoryConfigurationError e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case to test setnamespaceAware() method.
|
||||
*/
|
||||
@Test
|
||||
public void testNamespace02() {
|
||||
try {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
spf.setNamespaceAware(true);
|
||||
SAXParser saxparser = spf.newSAXParser();
|
||||
assertTrue(saxparser.isNamespaceAware());
|
||||
} catch (FactoryConfigurationError | ParserConfigurationException | SAXException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case to test if the getParser() method returns instance of Parser.
|
||||
*/
|
||||
@Test(dataProvider = "parser-provider")
|
||||
public void testParser01(SAXParser saxparser) {
|
||||
try {
|
||||
Parser parser = saxparser.getParser();
|
||||
} catch (FactoryConfigurationError | SAXException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case to test if the getXMLReader() method returns instance of
|
||||
* XMLReader.
|
||||
*/
|
||||
@Test(dataProvider = "parser-provider")
|
||||
public void testXmlReader01(SAXParser saxparser) {
|
||||
try {
|
||||
XMLReader xmlReader = saxparser.getXMLReader();
|
||||
} catch (FactoryConfigurationError | SAXException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the xml-string property is not supported.
|
||||
*
|
||||
* @throws SAXNotSupportedException
|
||||
*/
|
||||
@Test(expectedExceptions = SAXNotSupportedException.class, dataProvider = "parser-provider")
|
||||
public void testProperty01(SAXParser saxparser) throws SAXNotSupportedException {
|
||||
try {
|
||||
Object object = saxparser.getProperty(XML_STRING);
|
||||
} catch (SAXNotRecognizedException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the dom-node property is not supported.
|
||||
*
|
||||
* @throws SAXNotSupportedException
|
||||
*/
|
||||
@Test(expectedExceptions = SAXNotSupportedException.class, dataProvider = "parser-provider")
|
||||
public void testProperty02(SAXParser saxparser) throws SAXNotSupportedException {
|
||||
try {
|
||||
Object object = saxparser.getProperty(DOM_NODE);
|
||||
} catch (SAXNotRecognizedException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the default lexical-handler not exists.
|
||||
*/
|
||||
@Test(dataProvider = "parser-provider")
|
||||
public void testProperty03(SAXParser saxparser) {
|
||||
try {
|
||||
assertNull(saxparser.getProperty(LEXICAL_HANDLER));
|
||||
} catch (SAXException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the default declaration-handler not exists.
|
||||
*/
|
||||
@Test(dataProvider = "parser-provider")
|
||||
public void testProperty04(SAXParser saxparser) {
|
||||
|
||||
try {
|
||||
assertNull(saxparser.getProperty(DECL_HANDLER));
|
||||
} catch (SAXException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to set and get the lexical-handler.
|
||||
*/
|
||||
@Test(dataProvider = "parser-provider")
|
||||
public void testProperty05(SAXParser saxparser) {
|
||||
try {
|
||||
MyLexicalHandler myLexicalHandler = new MyLexicalHandler();
|
||||
saxparser.setProperty(LEXICAL_HANDLER, myLexicalHandler);
|
||||
Object object = saxparser.getProperty(LEXICAL_HANDLER);
|
||||
assertTrue(object instanceof LexicalHandler);
|
||||
} catch (SAXException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to set and get the declaration-handler.
|
||||
*/
|
||||
@Test(dataProvider = "parser-provider")
|
||||
public void testProperty06(SAXParser saxparser) {
|
||||
try {
|
||||
MyDeclHandler myDeclHandler = new MyDeclHandler();
|
||||
saxparser.setProperty(DECL_HANDLER, myDeclHandler);
|
||||
Object object = saxparser.getProperty(DECL_HANDLER);
|
||||
assertTrue(object instanceof DeclHandler);
|
||||
} catch (SAXException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Customized LexicalHandler used for test.
|
||||
*/
|
||||
private class MyLexicalHandler implements LexicalHandler {
|
||||
|
||||
public void comment(char[] ch, int start, int length) {
|
||||
}
|
||||
|
||||
public void endCDATA() {
|
||||
}
|
||||
|
||||
public void endDTD() {
|
||||
}
|
||||
|
||||
public void endEntity(String name) {
|
||||
}
|
||||
|
||||
public void startCDATA() {
|
||||
}
|
||||
|
||||
public void startDTD(String name, String publicId, String systemId) {
|
||||
}
|
||||
|
||||
public void startEntity(String name) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Customized DeclHandler used for test.
|
||||
*/
|
||||
private class MyDeclHandler implements DeclHandler {
|
||||
|
||||
public void attributeDecl(String eName, String aName, String type, String valueDefault, String value) {
|
||||
}
|
||||
|
||||
public void elementDecl(String name, String model) {
|
||||
}
|
||||
|
||||
public void externalEntityDecl(String name, String publicId, String systemId) {
|
||||
}
|
||||
|
||||
public void internalEntityDecl(String name, String value) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.xml.parsers.ptests;
|
||||
|
||||
import static jaxp.library.JAXPTestUtilities.failUnexpected;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* Class contains the test cases for SAXParser API
|
||||
*/
|
||||
public class SAXParserTest03 {
|
||||
|
||||
/**
|
||||
* Provide SAXParserFactory.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@DataProvider(name = "input-provider")
|
||||
public Object[][] getFactory() {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
spf.setValidating(true);
|
||||
MyErrorHandler handler = MyErrorHandler.newInstance();
|
||||
return new Object[][] { { spf, handler } };
|
||||
}
|
||||
|
||||
/**
|
||||
* parsertest.xml holds a valid document. This method tests the validating
|
||||
* parser.
|
||||
*/
|
||||
@Test(dataProvider = "input-provider")
|
||||
public void testParseValidate01(SAXParserFactory spf, MyErrorHandler handler) {
|
||||
try {
|
||||
SAXParser saxparser = spf.newSAXParser();
|
||||
saxparser.parse(new File(TestUtils.XML_DIR, "parsertest.xml"), handler);
|
||||
assertFalse(handler.errorOccured);
|
||||
} catch (ParserConfigurationException | SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* validns.xml holds a valid document with XML namespaces in it. This method
|
||||
* tests the Validating parser with namespace processing on.
|
||||
*/
|
||||
@Test(dataProvider = "input-provider")
|
||||
public void testParseValidate02(SAXParserFactory spf, MyErrorHandler handler) {
|
||||
try {
|
||||
spf.setNamespaceAware(true);
|
||||
SAXParser saxparser = spf.newSAXParser();
|
||||
saxparser.parse(new File(TestUtils.XML_DIR, "validns.xml"), handler);
|
||||
assertFalse(handler.errorOccured);
|
||||
} catch (ParserConfigurationException | SAXException | IOException e) {
|
||||
failUnexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* invalidns.xml holds an invalid document with XML namespaces in it. This
|
||||
* method tests the validating parser with namespace processing on. It
|
||||
* should throw validation error.
|
||||
*/
|
||||
@Test(dataProvider = "input-provider")
|
||||
public void testParseValidate03(SAXParserFactory spf, MyErrorHandler handler) {
|
||||
try {
|
||||
spf.setNamespaceAware(true);
|
||||
SAXParser saxparser = spf.newSAXParser();
|
||||
saxparser.parse(new File(TestUtils.XML_DIR, "invalidns.xml"), handler);
|
||||
failUnexpected(new RuntimeException());
|
||||
} catch (ParserConfigurationException | SAXException | IOException e) {
|
||||
if (e instanceof SAXException) {
|
||||
assertTrue(handler.errorOccured);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,200 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package javax.xml.parsers.ptests;
|
||||
|
||||
import static jaxp.library.JAXPTestUtilities.ERROR_MSG_HEADER;
|
||||
import static jaxp.library.JAXPTestUtilities.FILE_SEP;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.Locator;
|
||||
import org.xml.sax.SAXParseException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
import org.xml.sax.helpers.LocatorImpl;
|
||||
|
||||
/**
|
||||
* Utility interface which includes final variables of xml, golden file
|
||||
* directories.
|
||||
*/
|
||||
interface TestUtils {
|
||||
final String XML_DIR = System.getProperty("test.src", ".") + FILE_SEP + "javax/xml/parsers/xmlfiles";
|
||||
final String GOLDEN_DIR = XML_DIR + FILE_SEP + "out";
|
||||
}
|
||||
|
||||
/**
|
||||
* Customized DefaultHandler which writes output document when methods are
|
||||
* called by Transformer. Test may use output document to compare with golden
|
||||
* file for verification.
|
||||
*/
|
||||
class MyCHandler extends DefaultHandler {
|
||||
|
||||
private final BufferedWriter bWriter;
|
||||
private final Locator locator = new LocatorImpl();
|
||||
|
||||
private MyCHandler(File file) throws IOException {
|
||||
bWriter = new BufferedWriter(new FileWriter(file));
|
||||
}
|
||||
|
||||
public static MyCHandler newInstance(File file) throws IOException {
|
||||
MyCHandler handler = new MyCHandler(file);
|
||||
return handler;
|
||||
}
|
||||
|
||||
public void characters(char[] ch, int start, int length) {
|
||||
String s = new String(ch, start, length);
|
||||
String str = String.format("characters...length is:%d\n<%s>", s.length(), s);
|
||||
try {
|
||||
bWriter.write(str, 0, str.length());
|
||||
bWriter.newLine();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(ERROR_MSG_HEADER, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void endDocument() {
|
||||
String str = "endDocument...";
|
||||
try {
|
||||
bWriter.write(str, 0, str.length());
|
||||
bWriter.newLine();
|
||||
bWriter.flush();
|
||||
bWriter.close();
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(ERROR_MSG_HEADER, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void endElement(String namespaceURI, String localName, String qName) {
|
||||
String str = String.format("endElement...\nnamespaceURI: <%s> localName: <%s> qName: <%s>", namespaceURI, localName, qName);
|
||||
try {
|
||||
bWriter.write(str, 0, str.length());
|
||||
bWriter.newLine();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(ERROR_MSG_HEADER, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void endPrefixMapping(String prefix) {
|
||||
String str = String.format("endPrefixMapping...\nprefix: <%s>", prefix);
|
||||
try {
|
||||
bWriter.write(str, 0, str.length());
|
||||
bWriter.newLine();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(ERROR_MSG_HEADER, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void ignorableWhitespace(char[] ch, int start, int length) {
|
||||
String s = new String(ch, start, length);
|
||||
String str = String.format("ignorableWhitespace...\n%s ignorable white space string length: %d", s, s.length());
|
||||
try {
|
||||
bWriter.write(str, 0, str.length());
|
||||
bWriter.newLine();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(ERROR_MSG_HEADER, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void processingInstruction(String target, String data) {
|
||||
String str = String.format("processingInstruction...target:<%s> data: <%s>", target, data);
|
||||
try {
|
||||
bWriter.write(str, 0, str.length());
|
||||
bWriter.newLine();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(ERROR_MSG_HEADER, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void skippedEntity(String name) {
|
||||
String str = String.format("skippedEntity...\nname: <%s>", name);
|
||||
try {
|
||||
bWriter.write(str, 0, str.length());
|
||||
bWriter.newLine();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(ERROR_MSG_HEADER, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void startDocument() {
|
||||
String str = "startDocument...";
|
||||
try {
|
||||
bWriter.write(str, 0, str.length());
|
||||
bWriter.newLine();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(ERROR_MSG_HEADER, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) {
|
||||
String str = String.format("startElement...\nnamespaceURI: <%s> localName: <%s> qName: <%s> Number of Attributes: <%d> Line# <%d>", namespaceURI,
|
||||
localName, qName, atts.getLength(), locator.getLineNumber());
|
||||
try {
|
||||
bWriter.write(str, 0, str.length());
|
||||
bWriter.newLine();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(ERROR_MSG_HEADER, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void startPrefixMapping(String prefix, String uri) {
|
||||
String str = String.format("startPrefixMapping...\nprefix: <%s> uri: <%s>", prefix, uri);
|
||||
try {
|
||||
bWriter.write(str, 0, str.length());
|
||||
bWriter.newLine();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(ERROR_MSG_HEADER, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Customized DefaultHandler used for SAXParseException testing.
|
||||
*/
|
||||
class MyErrorHandler extends DefaultHandler {
|
||||
boolean errorOccured = false;
|
||||
|
||||
private MyErrorHandler() {
|
||||
}
|
||||
|
||||
public static MyErrorHandler newInstance() {
|
||||
return new MyErrorHandler();
|
||||
}
|
||||
|
||||
public void error(SAXParseException e) {
|
||||
errorOccured = true;
|
||||
}
|
||||
|
||||
public void warning(SAXParseException e) {
|
||||
errorOccured = true;
|
||||
}
|
||||
|
||||
public void fatalError(SAXParseException e) {
|
||||
errorOccured = true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0"?>
|
||||
<html>
|
||||
<![CDATA[ <xml>This is not parsed</xml>]]> yet
|
||||
</html>
|
||||
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE document [
|
||||
<!ENTITY ws "Wiliam SHAkespeare">
|
||||
<!ELEMENT document (title)>
|
||||
<!ELEMENT title (#PCDATA)>
|
||||
]>
|
||||
<document>
|
||||
<title>&ws;</title>
|
||||
</document>
|
||||
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE document [
|
||||
<!ENTITY ws "Wiliam SHAkespeare">
|
||||
<!ELEMENT document (name)>
|
||||
<!ELEMENT title (#PCDATA)>
|
||||
]>
|
||||
<document>
|
||||
<title>&ws;</title>
|
||||
</document>
|
||||
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE note [
|
||||
<!ELEMENT note (#PCDATA|to|ar:from|br:from|heading|body)*>
|
||||
<!ELEMENT to (#PCDATA)>
|
||||
<!ELEMENT ar:from (#PCDATA)>
|
||||
<!ELEMENT br:from (#PCDATA)>
|
||||
<!ELEMENT heading (#PCDATA)>
|
||||
<!ELEMENT body (#PCDATA)>
|
||||
<!ATTLIST note xmlns:ar CDATA #IMPLIED>
|
||||
<!ATTLIST note xmlns:br CDATA #IMPLIED>
|
||||
]>
|
||||
<note xmlns:ar="http://www.xml.com/books">
|
||||
xmlns:br="http://www.abc.com">
|
||||
<to>Tove</to>
|
||||
<ar:from>Jani</ar:from>
|
||||
<br:from>Next</br:from>
|
||||
<heading>Reminder</heading>
|
||||
<body> weekend!</body>
|
||||
</note>
|
||||
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE note [
|
||||
<!ELEMENT note (to,from,heading,body)>
|
||||
<!ELEMENT to (#PCDATA)>
|
||||
<!ELEMENT from (#PCDATA)>
|
||||
<!ELEMENT heading (#PCDATA)>
|
||||
<!ELEMENT body (#PCDATA)>
|
||||
]>
|
||||
<note xmlns:ar="http://www.xml.com/books">
|
||||
xmlns:br="http://www.abc.com">
|
||||
<to>Tove</to>
|
||||
<ar:from>Jani</ar:from>
|
||||
<br:from>Next</br:from>
|
||||
<heading>Reminder</heading>
|
||||
<body> weekend!</body>
|
||||
</note>
|
||||
@ -0,0 +1,29 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE note [
|
||||
<!ELEMENT note (#PCDATA|to|with|ar:from|br:from|heading|body)*>
|
||||
<!ELEMENT to (sender)>
|
||||
<!ELEMENT sender (#PCDATA)>
|
||||
<!ELEMENT with (message)>
|
||||
<!ELEMENT message (#PCDATA)>
|
||||
<!ELEMENT ar:from (tab)>
|
||||
<!ELEMENT tab (#PCDATA)>
|
||||
<!ELEMENT br:from (#PCDATA)>
|
||||
<!ELEMENT heading (#PCDATA)>
|
||||
<!ELEMENT body (#PCDATA)>
|
||||
<!ATTLIST note xmlns:ar CDATA #IMPLIED>
|
||||
<!ATTLIST note xmlns:br CDATA #IMPLIED>
|
||||
]>
|
||||
<note xmlns:ar="http://www.xml.com/books"
|
||||
xmlns:br="http://www.abc.com">
|
||||
<to>
|
||||
|
||||
<!--This is with whitespace-->
|
||||
<sender>John</sender>
|
||||
|
||||
</to>
|
||||
<with> <message>with whitespace</message> </with>
|
||||
<ar:from> <tab>Jani</tab></ar:from>
|
||||
<br:from>Next</br:from>
|
||||
<heading>Reminder</heading>
|
||||
<body> weekend!</body>
|
||||
</note>
|
||||
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE note [
|
||||
<!ELEMENT note (to|heading|body)*>
|
||||
<!ELEMENT body (#PCDATA)>
|
||||
]>
|
||||
<note>
|
||||
<to>Tove</to>
|
||||
<body><!--hello--></body>
|
||||
</note>
|
||||
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0"?>
|
||||
<note>
|
||||
<to>Tove</to>
|
||||
<body><!--hello--></body>
|
||||
</note>
|
||||
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0"?>
|
||||
<html>
|
||||
<![CDATA[ <xml>This is not parsed</xml>]]> yet
|
||||
</html>
|
||||
@ -0,0 +1,12 @@
|
||||
<!ELEMENT document ANY>
|
||||
<!ELEMENT title (#PCDATA)>
|
||||
<!ELEMENT publisher (#PCDATA)>
|
||||
<!ELEMENT book (#PCDATA)>
|
||||
<!ELEMENT bookurn (#PCDATA)>
|
||||
<!ATTLIST book price CDATA "$100">
|
||||
<!ATTLIST book author CDATA "Herold">
|
||||
<!ATTLIST book number ID #REQUIRED>
|
||||
<!ATTLIST bookurn xmlns CDATA "10">
|
||||
<!ATTLIST bookurn xmlns:isbn CDATA "10">
|
||||
<!ENTITY w "William">
|
||||
<!ENTITY s "Shakespeare">
|
||||
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" standalone="no"?>
|
||||
<!DOCTYPE document SYSTEM "DocumentBuilderImpl02.dtd">
|
||||
<document>
|
||||
|
||||
Publishers of the Music of New York Women Composers
|
||||
|
||||
<title>The Publishers </title>
|
||||
|
||||
<publisher>
|
||||
Alfred Publishing
|
||||
&w;
|
||||
15535 Morrison
|
||||
South Oaks CA 91403
|
||||
</publisher>
|
||||
|
||||
<book price="$100" author = "Herold" number = "no_11">
|
||||
eXtensible Markup Language
|
||||
</book>
|
||||
|
||||
<bookurn xmlns='urn:loc.gov:books'
|
||||
xmlns:isbn='urn:ISBN:0-395-36341-6'/>
|
||||
|
||||
|
||||
Publishers are not noted in report by time.
|
||||
|
||||
</document>
|
||||
|
||||
|
||||
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" standalone="yes"?>
|
||||
<document>
|
||||
Publishers of the Music of New York Women Composers
|
||||
|
||||
<title>The Publishers </title>
|
||||
|
||||
<publisher>
|
||||
Alfred Publishing
|
||||
15535 Morrison
|
||||
South Oaks CA 91403
|
||||
</publisher>
|
||||
|
||||
<book price="$100" author = "Herold" number = "no_11">
|
||||
eXtensible Markup Language
|
||||
</book>
|
||||
|
||||
<bookurn xmlns='urn:loc.gov:books'
|
||||
xmlns:isbn='urn:ISBN:0-395-36341-6'/>
|
||||
<xmlns:pages />
|
||||
|
||||
Publishers are not noted in report by time.
|
||||
|
||||
</document>
|
||||
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" standalone="yes" ?>
|
||||
<cities>
|
||||
<city name="Paris" country="France"/>
|
||||
<city name="Roma" country="Italia"/>
|
||||
<city name="Nice" country="France"/>
|
||||
<city name="Madrid" country="Espana"/>
|
||||
<city name="Milano" country="Italia"/>
|
||||
<city name="Firenze" country="Italia"/>
|
||||
<city name="Napoli" country="Italia"/>
|
||||
<city name="Lyon" country="France"/>
|
||||
<city name="Barcelona" country="Espana"/>
|
||||
</cities>
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" ?>
|
||||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
||||
<xsl:output method="xml" indent="yes"/>
|
||||
<xsl:template match="/">
|
||||
<xsl:variable name="unique-countries"
|
||||
select="/cities
|
||||
/city[not(@country=preceding-sibling::city/@country)]
|
||||
/@country"
|
||||
/>
|
||||
<countries>
|
||||
<xsl:for-each select="$unique-countries">
|
||||
<country name="{.}">
|
||||
<xsl:for-each select="//city[@country=current()]">
|
||||
<city><xsl:value-of select="@name"/></city>
|
||||
</xsl:for-each>
|
||||
</country>
|
||||
</xsl:for-each>
|
||||
</countries>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" ?>
|
||||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
||||
<xsl:import href="temp/cities.xsl"/>
|
||||
</xsl:stylesheet>
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" ?>
|
||||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
||||
<xsl:include href="temp/cities.xsl"/>
|
||||
</xsl:stylesheet>
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
<!ELEMENT document ANY>
|
||||
<!ELEMENT title (#PCDATA)>
|
||||
<!ELEMENT publisher (#PCDATA)>
|
||||
<!ELEMENT book (#PCDATA)>
|
||||
<!ELEMENT bookurn (#PCDATA)>
|
||||
<!ELEMENT xmlns:pages (#PCDATA)>
|
||||
<!ATTLIST book price CDATA "$100">
|
||||
<!ATTLIST book author CDATA "Herold">
|
||||
<!ATTLIST book number ID #REQUIRED>
|
||||
<!ATTLIST bookurn xmlns CDATA "10">
|
||||
<!ATTLIST bookurn xmlns:isbn CDATA "10">
|
||||
<!ENTITY mkm "I am Krishna">
|
||||
<!ENTITY km "I am KrishnaMohan">
|
||||
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" standalone="yes"?>
|
||||
<document>
|
||||
Publishers of the Music of New York Women Composers
|
||||
|
||||
<title>The Publishers </title>
|
||||
|
||||
<publisher>
|
||||
Alfred Publishing
|
||||
&mkm;
|
||||
15535 Morrison
|
||||
South Oaks CA 91403
|
||||
</publisher>
|
||||
|
||||
<book price="$100" author = "Herold" number = "no_11">
|
||||
eXtensible Markup Language
|
||||
</book>
|
||||
|
||||
<bookurn xmlns='urn:loc.gov:books'
|
||||
xmlns:isbn='urn:ISBN:0-395-36341-6'/>
|
||||
<xmlns:pages />
|
||||
|
||||
Publishers are not noted in report by time.
|
||||
|
||||
</document>
|
||||
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE book [
|
||||
<!ELEMENT book (#PCDATA | ar:rating | fr:rating | zr:rating)* >
|
||||
<!ATTLIST ar:rating
|
||||
xmlns:ar CDATA #FIXED "http://www.amazon.com/">
|
||||
<!ATTLIST fr:rating
|
||||
xmlns:fr CDATA #FIXED "http://www.fatbrain.com/">
|
||||
<!ELEMENT ar:rating (#PCDATA)>
|
||||
<!ELEMENT fr:rating (#PCDATA)>
|
||||
<!ELEMENT zr:rating (#PCDATA)>
|
||||
]>
|
||||
<book>
|
||||
<ar:rating>4star</ar:rating>
|
||||
<fr:rating>3star</fr:rating>
|
||||
<zr:rating>2star</zr:rating>
|
||||
</book>
|
||||
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
<html xmlns="http://www.w3.org/TR/REC-html40"
|
||||
xmlns:b="urn:BooksAreUs.org:BookInfo">
|
||||
<head>
|
||||
<title>Typography</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<p> Welcome to the world of typography! Here is a book that you may find useful.</p>
|
||||
<b:title style="font-family: sans-serif;">Digital Typography</b:title>
|
||||
<b:author>Donald Knuth</b:author>
|
||||
<?netscape http://www.hotmail.com?>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@ -0,0 +1,8 @@
|
||||
<section><title>Book-Signing Event</title>
|
||||
<signing>
|
||||
<author title="Mr" name="Vikram Seth" />
|
||||
<book title="A Suitable Boy" price="$22.95" /></signing>
|
||||
<signing>
|
||||
<author title="Dr" name="Oliver Sacks" />
|
||||
<book title="The Island of the Color-Blind" price="$12.95" /></signing>
|
||||
</section>
|
||||
@ -0,0 +1,83 @@
|
||||
startDocument...
|
||||
startPrefixMapping...
|
||||
prefix: <ar> uri: <http://www.xml.com/books>
|
||||
startPrefixMapping...
|
||||
prefix: <br> uri: <http://www.abc.com>
|
||||
startElement...
|
||||
namespaceURI: <> localName: <note> qName: <note> Number of Attributes: <2> Line# <0>
|
||||
characters...length is:1
|
||||
<
|
||||
>
|
||||
startElement...
|
||||
namespaceURI: <> localName: <to> qName: <to> Number of Attributes: <0> Line# <0>
|
||||
startElement...
|
||||
namespaceURI: <> localName: <sender> qName: <sender> Number of Attributes: <0> Line# <0>
|
||||
characters...length is:4
|
||||
<John>
|
||||
endElement...
|
||||
namespaceURI: <> localName: <sender> qName: <sender>
|
||||
endElement...
|
||||
namespaceURI: <> localName: <to> qName: <to>
|
||||
characters...length is:1
|
||||
<
|
||||
>
|
||||
startElement...
|
||||
namespaceURI: <> localName: <with> qName: <with> Number of Attributes: <0> Line# <0>
|
||||
startElement...
|
||||
namespaceURI: <> localName: <message> qName: <message> Number of Attributes: <0> Line# <0>
|
||||
characters...length is:15
|
||||
<with whitespace>
|
||||
endElement...
|
||||
namespaceURI: <> localName: <message> qName: <message>
|
||||
endElement...
|
||||
namespaceURI: <> localName: <with> qName: <with>
|
||||
characters...length is:1
|
||||
<
|
||||
>
|
||||
startElement...
|
||||
namespaceURI: <http://www.xml.com/books> localName: <from> qName: <ar:from> Number of Attributes: <0> Line# <0>
|
||||
startElement...
|
||||
namespaceURI: <> localName: <tab> qName: <tab> Number of Attributes: <0> Line# <0>
|
||||
characters...length is:4
|
||||
<Jani>
|
||||
endElement...
|
||||
namespaceURI: <> localName: <tab> qName: <tab>
|
||||
endElement...
|
||||
namespaceURI: <http://www.xml.com/books> localName: <from> qName: <ar:from>
|
||||
characters...length is:1
|
||||
<
|
||||
>
|
||||
startElement...
|
||||
namespaceURI: <http://www.abc.com> localName: <from> qName: <br:from> Number of Attributes: <0> Line# <0>
|
||||
characters...length is:4
|
||||
<Next>
|
||||
endElement...
|
||||
namespaceURI: <http://www.abc.com> localName: <from> qName: <br:from>
|
||||
characters...length is:1
|
||||
<
|
||||
>
|
||||
startElement...
|
||||
namespaceURI: <> localName: <heading> qName: <heading> Number of Attributes: <0> Line# <0>
|
||||
characters...length is:8
|
||||
<Reminder>
|
||||
endElement...
|
||||
namespaceURI: <> localName: <heading> qName: <heading>
|
||||
characters...length is:1
|
||||
<
|
||||
>
|
||||
startElement...
|
||||
namespaceURI: <> localName: <body> qName: <body> Number of Attributes: <0> Line# <0>
|
||||
characters...length is:9
|
||||
< weekend!>
|
||||
endElement...
|
||||
namespaceURI: <> localName: <body> qName: <body>
|
||||
characters...length is:1
|
||||
<
|
||||
>
|
||||
endElement...
|
||||
namespaceURI: <> localName: <note> qName: <note>
|
||||
endPrefixMapping...
|
||||
prefix: <br>
|
||||
endPrefixMapping...
|
||||
prefix: <ar>
|
||||
endDocument...
|
||||
@ -0,0 +1,79 @@
|
||||
startDocument...
|
||||
startPrefixMapping...
|
||||
prefix: <> uri: <http://www.w3.org/TR/REC-html40>
|
||||
startPrefixMapping...
|
||||
prefix: <b> uri: <urn:BooksAreUs.org:BookInfo>
|
||||
startElement...
|
||||
namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <html> qName: <html> Number of Attributes: <2> Line# <0>
|
||||
characters...length is:3
|
||||
<
|
||||
>
|
||||
startElement...
|
||||
namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <head> qName: <head> Number of Attributes: <0> Line# <0>
|
||||
characters...length is:5
|
||||
<
|
||||
>
|
||||
startElement...
|
||||
namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <title> qName: <title> Number of Attributes: <0> Line# <0>
|
||||
characters...length is:10
|
||||
<Typography>
|
||||
endElement...
|
||||
namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <title> qName: <title>
|
||||
characters...length is:3
|
||||
<
|
||||
>
|
||||
endElement...
|
||||
namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <head> qName: <head>
|
||||
characters...length is:4
|
||||
<
|
||||
|
||||
>
|
||||
startElement...
|
||||
namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <body> qName: <body> Number of Attributes: <0> Line# <0>
|
||||
characters...length is:5
|
||||
<
|
||||
>
|
||||
startElement...
|
||||
namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <p> qName: <p> Number of Attributes: <0> Line# <0>
|
||||
characters...length is:77
|
||||
< Welcome to the world of typography! Here is a book that you may find useful.>
|
||||
endElement...
|
||||
namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <p> qName: <p>
|
||||
characters...length is:5
|
||||
<
|
||||
>
|
||||
startElement...
|
||||
namespaceURI: <urn:BooksAreUs.org:BookInfo> localName: <title> qName: <b:title> Number of Attributes: <1> Line# <0>
|
||||
characters...length is:18
|
||||
<Digital Typography>
|
||||
endElement...
|
||||
namespaceURI: <urn:BooksAreUs.org:BookInfo> localName: <title> qName: <b:title>
|
||||
characters...length is:6
|
||||
<
|
||||
>
|
||||
startElement...
|
||||
namespaceURI: <urn:BooksAreUs.org:BookInfo> localName: <author> qName: <b:author> Number of Attributes: <0> Line# <0>
|
||||
characters...length is:12
|
||||
<Donald Knuth>
|
||||
endElement...
|
||||
namespaceURI: <urn:BooksAreUs.org:BookInfo> localName: <author> qName: <b:author>
|
||||
characters...length is:5
|
||||
<
|
||||
>
|
||||
processingInstruction...target:<netscape> data: <http://www.hotmail.com>
|
||||
characters...length is:3
|
||||
<
|
||||
>
|
||||
endElement...
|
||||
namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <body> qName: <body>
|
||||
characters...length is:2
|
||||
<
|
||||
|
||||
>
|
||||
endElement...
|
||||
namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <html> qName: <html>
|
||||
endPrefixMapping...
|
||||
prefix: <b>
|
||||
endPrefixMapping...
|
||||
prefix: <>
|
||||
endDocument...
|
||||
@ -0,0 +1,79 @@
|
||||
startDocument...
|
||||
startPrefixMapping...
|
||||
prefix: <> uri: <http://www.w3.org/TR/REC-html40>
|
||||
startPrefixMapping...
|
||||
prefix: <b> uri: <urn:BooksAreUs.org:BookInfo>
|
||||
startElement...
|
||||
namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <html> qName: <html> Number of Attributes: <2> Line# <0>
|
||||
characters...length is:3
|
||||
<
|
||||
>
|
||||
startElement...
|
||||
namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <head> qName: <head> Number of Attributes: <0> Line# <0>
|
||||
characters...length is:5
|
||||
<
|
||||
>
|
||||
startElement...
|
||||
namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <title> qName: <title> Number of Attributes: <0> Line# <0>
|
||||
characters...length is:10
|
||||
<Typography>
|
||||
endElement...
|
||||
namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <title> qName: <title>
|
||||
characters...length is:3
|
||||
<
|
||||
>
|
||||
endElement...
|
||||
namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <head> qName: <head>
|
||||
characters...length is:4
|
||||
<
|
||||
|
||||
>
|
||||
startElement...
|
||||
namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <body> qName: <body> Number of Attributes: <0> Line# <0>
|
||||
characters...length is:5
|
||||
<
|
||||
>
|
||||
startElement...
|
||||
namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <p> qName: <p> Number of Attributes: <0> Line# <0>
|
||||
characters...length is:77
|
||||
< Welcome to the world of typography! Here is a book that you may find useful.>
|
||||
endElement...
|
||||
namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <p> qName: <p>
|
||||
characters...length is:5
|
||||
<
|
||||
>
|
||||
startElement...
|
||||
namespaceURI: <urn:BooksAreUs.org:BookInfo> localName: <title> qName: <b:title> Number of Attributes: <1> Line# <0>
|
||||
characters...length is:18
|
||||
<Digital Typography>
|
||||
endElement...
|
||||
namespaceURI: <urn:BooksAreUs.org:BookInfo> localName: <title> qName: <b:title>
|
||||
characters...length is:6
|
||||
<
|
||||
>
|
||||
startElement...
|
||||
namespaceURI: <urn:BooksAreUs.org:BookInfo> localName: <author> qName: <b:author> Number of Attributes: <0> Line# <0>
|
||||
characters...length is:12
|
||||
<Donald Knuth>
|
||||
endElement...
|
||||
namespaceURI: <urn:BooksAreUs.org:BookInfo> localName: <author> qName: <b:author>
|
||||
characters...length is:5
|
||||
<
|
||||
>
|
||||
processingInstruction...target:<netscape> data: <http://www.hotmail.com>
|
||||
characters...length is:3
|
||||
<
|
||||
>
|
||||
endElement...
|
||||
namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <body> qName: <body>
|
||||
characters...length is:2
|
||||
<
|
||||
|
||||
>
|
||||
endElement...
|
||||
namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <html> qName: <html>
|
||||
endPrefixMapping...
|
||||
prefix: <b>
|
||||
endPrefixMapping...
|
||||
prefix: <>
|
||||
endDocument...
|
||||
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" standalone="no"?>
|
||||
<!DOCTYPE document SYSTEM "firstdtd.dtd">
|
||||
<document>
|
||||
Publishers of the Music of New York Women Composers
|
||||
|
||||
<title>The Publishers </title>
|
||||
|
||||
<publisher>
|
||||
Alfred Publishing
|
||||
&mkm;
|
||||
15535 Morrison
|
||||
South Oaks CA 91403
|
||||
</publisher>
|
||||
|
||||
<book price="$100" author = "Herold" number = "no_11">
|
||||
eXtensible Markup Language
|
||||
</book>
|
||||
|
||||
<bookurn xmlns='urn:loc.gov:books'
|
||||
xmlns:isbn='urn:ISBN:0-395-36341-6'/>
|
||||
<xmlns:pages />
|
||||
|
||||
Publishers are not noted in report by time.
|
||||
|
||||
</document>
|
||||
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<contact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test.xsd">
|
||||
<name> John </name>
|
||||
<phone>444-121-3434</phone>
|
||||
</contact>
|
||||
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
<xs:element name="contact">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="name" type="xs:string"/>
|
||||
<xs:element name="phone" type="xs:string"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<contact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="junk.xsd">
|
||||
<name> John </name>
|
||||
<phone>444-121-3434</phone>
|
||||
</contact>
|
||||
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" standalone="yes"?>
|
||||
<document>
|
||||
Publishers of the Music of New York Women Composers
|
||||
|
||||
<title>The Publishers </title>
|
||||
|
||||
<publisher>
|
||||
Alfred Publishing
|
||||
&mkm;
|
||||
15535 Morrison
|
||||
South Oaks CA 91403
|
||||
</publisher>
|
||||
|
||||
<book price="$100" author = "Herold" number = "no_11">
|
||||
eXtensible Markup Language
|
||||
</book>
|
||||
|
||||
<bookurn xmlns='urn:loc.gov:books'
|
||||
xmlns:isbn='urn:ISBN:0-395-36341-6'/>
|
||||
<xmlns:pages />
|
||||
|
||||
Publishers are not noted in report by time.
|
||||
|
||||
</document>
|
||||
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE book [
|
||||
<!ELEMENT book (#PCDATA| ar:rating| fr:rating)* >
|
||||
<!ATTLIST ar:rating
|
||||
xmlns:ar CDATA #FIXED "http://www.amazon.com/">
|
||||
<!ATTLIST fr:rating
|
||||
xmlns:fr CDATA #FIXED "http://www.fatbrain.com/">
|
||||
<!ELEMENT ar:rating (#PCDATA)>
|
||||
<!ELEMENT fr:rating (#PCDATA)>
|
||||
]>
|
||||
<book>
|
||||
<ar:rating>4star</ar:rating>
|
||||
<fr:rating>3star</fr:rating>
|
||||
</book>
|
||||
Loading…
x
Reference in New Issue
Block a user