ASF Bugzilla – Attachment 15995 Details for
Bug 36127
validation with xerces 2.7.1
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Example reproducing the problem
Sax.java (text/plain), 3.33 KB, created by
Florent BENOIT
on 2005-08-10 17:30:45 UTC
(
hide
)
Description:
Example reproducing the problem
Filename:
MIME Type:
Creator:
Florent BENOIT
Created:
2005-08-10 17:30:45 UTC
Size:
3.33 KB
patch
obsolete
>/** > * Test for Sax Parsing > */ >package sax; > >import java.io.BufferedReader; >import java.io.Reader; >import java.io.StringReader; > >import javax.xml.parsers.SAXParser; >import javax.xml.parsers.SAXParserFactory; > >import org.xml.sax.InputSource; >import org.xml.sax.SAXException; >import org.xml.sax.SAXParseException; >import org.xml.sax.XMLReader; >import org.xml.sax.helpers.DefaultHandler; > >public class Sax extends DefaultHandler { > > /** > * DEBUG Mode > */ > private static boolean DEBUG = false; > > public void start(boolean tomcatMode) throws Exception { > SAXParserFactory factory = SAXParserFactory.newInstance(); > factory.setNamespaceAware(true); > if (tomcatMode) { > System.out.println("Using Tomcat method :"); > factory.setFeature("http://xml.org/sax/features/validation", true); > } else { > System.out.println("Using other method :"); > factory.setValidating(true); > } > > // Get parser > SAXParser saxParser = factory.newSAXParser(); > XMLReader xmlReader = saxParser.getXMLReader(); > > System.out.println(" -> Validating mode of sax parser = " + saxParser.isValidating()); > > // redirect error to ourself > xmlReader.setErrorHandler(this); > > // get a document > BufferedReader br = new BufferedReader(getSample()); > if (DEBUG) { > System.out.println(" -> Parsing content = "); > } > StringBuffer sb = new StringBuffer(); > String line; > > while ((line = br.readLine()) != null) { > sb.append(line); > sb.append("\n"); > } > if (DEBUG) { > System.out.println(sb.toString()); > System.out.println(" -> Staring parsing and expect exception..."); > } > try { > saxParser.parse(new InputSource(getSample()), this); > System.out.println(" -> No exception !! failure"); > } catch (Exception e) { > System.out.println(" -> Expected exception !! success"); > e.printStackTrace(); > } > if (DEBUG) { > System.out.println("--> Parsing done."); > } > > } > > /** > * @param args > */ > public static void main(String[] args) throws Exception { > Sax sax = new Sax(); > // like it is done in Tomcat > sax.start(true); > > // like it is done in Digester and many others > sax.start(false); > } > > /** > * XML sample > */ > private Reader getSample() { > StringBuffer sb = new StringBuffer(); > sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); > sb.append("<!DOCTYPE title [\n"); > sb.append("<!ELEMENT item1 (#PCDATA)>\n"); > sb.append("<!ELEMENT item2 (#PCDATA)>\n"); > sb.append("<!ELEMENT title (item1 , item2)>\n"); > sb.append("] >\n"); > > sb.append("<title>\n"); > sb.append("<item1>Missing item2 !!!!</item1>\n"); > sb.append("</title>\n"); > > return new StringReader(sb.toString()); > } > > // Methods not important for the test > > public Sax() { > > } > > public void error(SAXParseException e) throws SAXException { > throw e; > } > > public void fatalError(SAXParseException e) throws SAXException { > throw e; > } > > public void warning(SAXParseException e) throws SAXException { > System.err.println("Warning : " + e); > } > >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 36127
: 15995 |
15996