db-ddlutils-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Laurent ROCHE <laurent_ro...@yahoo.com>
Subject Re : Could not parse xml data
Date Mon, 19 Nov 2007 11:14:58 GMT
Hi,

First error seems strange indeed, why don't you define a target in a build.xml, thi way you
will only need to run ant with the target name and have all your ant task in one file (which
I have found convenient).
Running the task will be like:
> ant import-derby 
for the build.xml file given at the end of the post.

Regarding the second error, appart from checking there is an exiting "C:\ant-ddl\data.xml"
file and that it's readable, I don't see what could be the error.

 
Bonne journée,
L@u
The Computing Froggy

=========== example of build.xml ==================
<?xml version="1.0"?>
<project name="MigrateToDerby" basedir=".">

   <path id="classpath">
      <fileset dir="./lib">
         <include name="**/*.jar"/>
      </fileset>

   </path>

<target name="import-derby" description="Creates db and Loads data">
      <taskdef name="ddlToDatabase"
              classname="org.apache.ddlutils.task.DdlToDatabaseTask">
         <classpath refid="classpath"/>
      </taskdef>

      <ddlToDatabase schemaFile="schema.xml" sortforeignkeys="false" verbosity="DEBUG"
shutdowndatabase="true" >

         <database url="jdbc:derby:example_db"
                 driverClassName="org.apache.derby.jdbc.EmbeddedDriver"
                 username=""
                 password=""/>

         <createDatabase failonerror="true"/>
         <writeSchemaToDatabase/>
        <writeDataToDatabase datafile="data.xml" failonerror="true" ensureforeignkeyorder="true"
useexplicitidentityvalues ="true"/>

      </ddlToDatabase>

</target> 



</project>
=========== End of example of build.xml ==================



----- Message d'origine ----
De : "fx.robin@laposte.net" <fx.robin@laposte.net>
À : ddlutils-user@db.apache.org
Envoyé le : Dimanche, 18 Novembre 2007, 15h00mn 15s
Objet : Could not parse xml data

Hi, I've got issue using import ant task.

First, my very simple database (MySQL) :


CREATE DATABASE IF NOT EXISTS test;
USE test;

--
-- Definition of table `groupes`
--

DROP TABLE IF EXISTS `groupes`;
CREATE TABLE `groupes` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `nom` varchar(45) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `groupes`
--

INSERT INTO `groupes` (`id`,`nom`) VALUES 
 (1,'Administrators'),
 (2,'Users');



--
-- Definition of table `personnes`
--

DROP TABLE IF EXISTS `personnes`;
CREATE TABLE `personnes` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `nom` varchar(45) NOT NULL,
  `prenom` varchar(45) NOT NULL,
  `fk_groupe` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `FK_personnes_groupes` (`fk_groupe`),
  CONSTRAINT `FK_personnes_groupes` FOREIGN KEY (`fk_groupe`)
 REFERENCES `groupes` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `personnes`
--

INSERT INTO `personnes` (`id`,`nom`,`prenom`,`fk_groupe`) VALUES 
 (1,'Robin','FX',1),
 (2,'John','Doe',2);


then my export ant task :

<project name="cofaxddl" default="databaseToDdl" basedir=".">

<path id="project-classpath">
  <fileset dir="lib">
    <include name="**/*.jar"/>
    <include name="**/*.zip"/>

  </fileset>
</path>

<taskdef classname="org.apache.ddlutils.task.DatabaseToDdlTask"
          name="databaseToDdl"
          classpathref="project-classpath" />

 <databaseToDdl usedelimitedsqlidentifiers="true"
                modelname="example">
   <database driverclassname="com.mysql.jdbc.Driver"
             url="jdbc:mysql://localhost:3306/test"
             username="root"
             password="root"/>

   <writeschematofile outputfile="schema.xml"/>
   <writedatatofile outputfile="data.xml"
                    encoding="ISO-8859-1"/>
 </databaseToDdl>

</project>


which produces :

C:\ant-ddl>ant -buildfile export.xml
Buildfile: export.xml
[databaseToDdl] Written schema to C:\ant-ddl\schema.xml
[databaseToDdl] Written data XML to fileC:\ant-ddl\data.xml

BUILD FAILED
Target "databaseToDdl" does not exist in the project "cofaxddl".

Total time: 10 seconds

(strange error on the target name ?)


here is the schema.xml :

<?xml version="1.0"?>
<!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database">
  <database name="example">
    <table name="groupes">
      <column name="id" primaryKey="true" required="true"
 type="INTEGER" size="10" autoIncrement="true"/>
      <column name="nom" primaryKey="false" required="true"
 type="VARCHAR" size="45" autoIncrement="false"/>
    </table>
    <table name="personnes">
      <column name="id" primaryKey="true" required="true"
 type="INTEGER" size="10" autoIncrement="true"/>
      <column name="nom" primaryKey="false" required="true"
 type="VARCHAR" size="45" autoIncrement="false"/>
      <column name="prenom" primaryKey="false" required="true"
 type="VARCHAR" size="45" autoIncrement="false"/>
      <column name="fk_groupe" primaryKey="false" required="false"
 type="INTEGER" size="10" autoIncrement="false"/>
      <foreign-key foreignTable="groupes" name="FK_personnes_groupes">
        <reference local="fk_groupe" foreign="id"/>
      </foreign-key>
    </table>
  </database>
  
here is the data.xml :

<?xml version="1.0" encoding="ISO-8859-1"?>
<data>
  <groupes id="1" nom="Administrators"></groupes>
  <groupes id="2" nom="Users"></groupes>
  <personnes id="1" nom="Robin" prenom="FX" fk_groupe="1"></personnes>
  <personnes id="2" nom="John" prenom="Doe" fk_groupe="2"></personnes>
</data>

Everything seems to be ok at this point

Now I'm trying to import with this task :

<project name="cofaxddl" default="ddlToDatabase" basedir=".">


<path id="project-classpath">
  <fileset dir="lib">
    <include name="**/*.jar"/>
    <include name="**/*.zip"/>

  </fileset>
</path>

<taskdef classname="org.apache.ddlutils.task.DdlToDatabaseTask"
          name="ddlToDatabase"
          classpathref="project-classpath"/>

 <ddlToDatabase usedelimitedsqlidentifiers="true">
   <database driverclassname="org.apache.derby.jdbc.ClientDriver"
             url="jdbc:derby://localhost:1527/MyDbTest';"
             username="root"
             password="root"/>
   <fileset dir=".">
     <include name="*schema.xml"/>
   </fileset>

   <createdatabase failonerror="false"/>
   <writeschematodatabase alterdatabase="true"
                          failonerror="false"/>
   <writedatatodatabase datafile="data.xml"
                        />
 </ddlToDatabase>

</project>

which produces :

C:\ant-ddl>ant -buildfile import-derby.xml -v

Apache Ant version 1.7.0 compiled on December 13 2006
Buildfile: import-derby.xml
Detected Java version: 1.6 in: c:\jdk\6\jre
Detected OS: Windows 2000
parsing buildfile C:\ant-ddl\import-derby.xml with URI =
 file:/C:/ant-ddl/import-derby.xml
Project base dir set to: C:\ant-ddl
[antlib:org.apache.tools.ant] Could not load definitions from resource
 org/apache/tools/ant/antlib.xml. It could not be found.
[ddlToDatabase] Read schema file C:\ant-ddl\schema.xml
[ddlToDatabase] Created database
[ddlToDatabase] Executed 0 SQL command(s) with 0 error(s)
[ddlToDatabase] Written schema to database
BUILD FAILED
C:\ant-ddl\import-derby.xml:16: Could not parse or write data file
 C:\ant-ddl\data.xml
        at
 org.apache.ddlutils.task.Command.handleException(Command.java:81)
        at
 org.apache.ddlutils.task.WriteDataToDatabaseCommand.readSingleDataFile(WriteDataToDatabas
eCommand.java:222)
        at
 org.apache.ddlutils.task.WriteDataToDatabaseCommand.execute(WriteDataToDatabaseCommand.ja
va:161)
        at
 org.apache.ddlutils.task.DatabaseTaskBase.executeCommands(DatabaseTaskBase.java:337)
        at
 org.apache.ddlutils.task.DatabaseTaskBase.execute(DatabaseTaskBase.java:365)
        at
 org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
        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.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:357)
        at
 org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:140)
        at
 org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java:96)
        at org.apache.tools.ant.Main.runBuild(Main.java:683)
        at org.apache.tools.ant.Main.startAnt(Main.java:199)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Caused by: org.apache.ddlutils.DdlUtilsException:
 java.net.MalformedURLException: unknown protocol:
c
        at
 org.apache.ddlutils.io.DatabaseDataIO.writeDataToDatabase(DatabaseDataIO.java:730)
        at
 org.apache.ddlutils.task.WriteDataToDatabaseCommand.readSingleDataFile(WriteDataToDatabas
eCommand.java:217)
        ... 17 more
Caused by: java.net.MalformedURLException: unknown protocol: c
        at java.net.URL.<init>(URL.java:574)
        at java.net.URL.<init>(URL.java:464)
        at java.net.URL.<init>(URL.java:413)
        at
 org.apache.commons.digester.Digester.createInputSourceFromURL(Digester.java:1958)
        at
 org.apache.commons.digester.Digester.parse(Digester.java:1804)
        at
 org.apache.ddlutils.io.DatabaseDataIO.writeDataToDatabase(DatabaseDataIO.java:726)
        ... 18 more
--- Nested Exception ---
org.apache.ddlutils.DdlUtilsException: java.net.MalformedURLException:
 unknown protocol: c
        at
 org.apache.ddlutils.io.DatabaseDataIO.writeDataToDatabase(DatabaseDataIO.java:730)
        at
 org.apache.ddlutils.task.WriteDataToDatabaseCommand.readSingleDataFile(WriteDataToDatabas
eCommand.java:217)
        at
 org.apache.ddlutils.task.WriteDataToDatabaseCommand.execute(WriteDataToDatabaseCommand.ja
va:161)
        at
 org.apache.ddlutils.task.DatabaseTaskBase.executeCommands(DatabaseTaskBase.java:337)
        at
 org.apache.ddlutils.task.DatabaseTaskBase.execute(DatabaseTaskBase.java:365)
        at
 org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
        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.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:357)
        at
 org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:140)
        at
 org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java:96)
        at org.apache.tools.ant.Main.runBuild(Main.java:683)
        at org.apache.tools.ant.Main.startAnt(Main.java:199)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Caused by: java.net.MalformedURLException: unknown protocol: c
        at java.net.URL.<init>(URL.java:574)
        at java.net.URL.<init>(URL.java:464)
        at java.net.URL.<init>(URL.java:413)
        at
 org.apache.commons.digester.Digester.createInputSourceFromURL(Digester.java:1958)
        at
 org.apache.commons.digester.Digester.parse(Digester.java:1804)
        at
 org.apache.ddlutils.io.DatabaseDataIO.writeDataToDatabase(DatabaseDataIO.java:726)
        ... 18 more

Total time: 2 seconds


It seems that the data.xml file is not parsed.
What is wrong ?
Here are the .jar that I put in the lib folder :

commons-beanutils.jar
commons-betwixt-0.8.jar
commons-codec-1.3.jar
commons-collections-3.2.jar
commons-dbcp-1.2.2.jar
commons-digester-1.8.jar
commons-lang-2.3.jar
commons-logging-1.1.jar
commons-pool-1.3.jar
DdlUtils-1.0.jar
derby.jar
derbyclient.jar
hsqldb.jar
jakarta-oro-2.0.8.jar
log4j-1.2.15.jar
mysql-connector-java-3.1.8-bin.jar


Please help me.

Regards.
F.X ROBIN



 Créez votre adresse électronique prénom.nom@laposte.net 
 1 Go d'espace de stockage, anti-spam et anti-virus intégrés.






      _____________________________________________________________________________ 
Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail 
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message