commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Juza1 <fcr...@id.ethz.ch>
Subject digester newby question/problem
Date Thu, 12 Mar 2009 15:27:44 GMT

Hi to all,

I'm new to digester and I have the following problem:

I have such an XML File to parse:

<?xml version='1.0' encoding='UTF-8'?>
<OAI-PMH xmlns='http://www.openarchives.org/OAI/2.0/'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
  xsi:schemaLocation='http://www.openarchives.org/OAI/2.0/
http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd'>
  <responseDate>2009-03-12T14:00:14Z</responseDate>
  <request verb="ListRecords" metadataPrefix="oai_dc"
set="2009">http://url.url.org/abc.asp</request>
  <ListRecords>
    <record>
      <header>
        <identifier>oai:oai.ethz.ch:e-collection/005583701</identifier>
        <datestamp>2008-12-08</datestamp>
        <setSpec>2009</setSpec>
      </header>
      <metadata>
        <oai_dc:dc
xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/
http://www.openarchives.org/OAI/2.0/oai_dc.xsd"
xmlns="http://purl.org/dc/elements/1.1/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/">
	        <title>Universita?res Wissen teilen Forschende im Dialog   
</title>
        	<creator>Ru?egger, Hans-Ulrich </creator>
        	<type>text</type>
        	<publisher>Zu?richvdf Hochschulverlag an der ETH
Zu?rich</publisher>
        	<date>2009</date>
        	<language>ger</language>
        	<subject>Wissenschaft</subject>
        	<subject>Forschung</subject>
        	<subject>Kooperation</subject>
        	<subject>Wissenstransfer</subject>
        	<identifier>http://url.url.url.org/blabla</identifier>
        	<identifier>http://url.url.url.org/blabla.pdf</identifier>
        	<identifier></identifier>
        </oai_dc:dc>
      </metadata>
    </record>
    ...other records
  </ListRecords>
</OAI-PMH>

Then I wrote my parser:

...
    public ListRecordsParser(InputStream response) throws IOException,
SAXException
    {
        // instantiate Digester and disable XML validation
        Digester digester = new Digester();
        digester.setValidating(false);
        
        // instantiate ListRecords class
        digester.addObjectCreate("OAI-PMH/ListRecords", ListRecords.class );
        
        // instantiate Record class
        digester.addObjectCreate("OAI-PMH/ListRecords/record", Record.class
);
                
        // instantiate Header class
        digester.addObjectCreate("OAI-PMH/ListRecords/record/header",
Header.class );
        digester.addBeanPropertySetter(
"OAI-PMH/ListRecords/record/header/identifier", "identifier" );
        digester.addBeanPropertySetter(
"OAI-PMH/ListRecords/record/header/datestamp", "datestamp" );
        digester.addBeanPropertySetter(
"OAI-PMH/ListRecords/record/header/setSpec", "setSpec" );
        
        digester.addSetNext( "OAI-PMH/ListRecords/record", "setHeader" );
        
        // instantiate MetaData class
        digester.addObjectCreate("OAI-PMH/ListRecords/record/metadata",
MetaData.class );
        digester.addBeanPropertySetter(
"OAI-PMH/ListRecords/record/metadata/title", "title" );
        digester.addBeanPropertySetter(
"OAI-PMH/ListRecords/record/metadata/creator", "creator" );
        digester.addBeanPropertySetter(
"OAI-PMH/ListRecords/record/metadata/publisher", "publisher" );
        
        digester.addSetNext( "OAI-PMH/ListRecords/record", "setMetaData" );

        digester.addSetNext( "OAI-PMH/ListRecords/record", "addRecord" );
        
        // now that rules and actions are configured, start the parsing
process
        ListRecords lr = (ListRecords)digester.parse(response);
...


The problem is that when I run it I get:

2009-03-12 16:01:41,431 [main] ERROR
org.apache.commons.digester.Digester(org.apache.commons.digester.Digester.fatalError(Digester.java:1765))

- Parse Fatal Error at line -1 column -1: Premature end of file.
org.xml.sax.SAXParseException: Premature end of file.
	at
org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown
Source)
	at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
	at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
	at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
	at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown
Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
	at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
	at org.apache.commons.digester.Digester.parse(Digester.java:1887)
	at ethz.oai.helper.ListRecordsParser.<init>(ListRecordsParser.java:59)
	at ethz.oai.MetaDataCollector.getDocumentsData(MetaDataCollector.java:129)
	at
ethz.test.MetaDataCollectorTest.testGetMetaData(MetaDataCollectorTest.java:57)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at
org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
	at
org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
	at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
	at
org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
	at
org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
	at
org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
	at
org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
	at
org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
	at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
	at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
	at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
	at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


What's the problem? Shoul I define the entire XML structure in my parser?

Thanx a lot for the help

Juza
-- 
View this message in context: http://www.nabble.com/digester-newby-question-problem-tp22478258p22478258.html
Sent from the Commons - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message