XML-0108: (Fatal Error) Start of root element expected

daisyz
daisyz used Ask the Experts™
on
I was trying to insert data from a XML file into oracle table using XSU. Can any one give any tips or pointers for this?

-------------------------------------------------------
I'm using the scott default table: emp

SQL> describe emp;
 Name                            Null?    Type
 ------------------------------- -------- ----
 EMPNO                           NOT NULL NUMBER(4)
 ENAME                                    VARCHAR2(10)
 JOB                                      VARCHAR2(9)
 MGR                                      NUMBER(4)
 HIREDATE                                 DATE
 SAL                                      NUMBER(7,2)
 COMM                                     NUMBER(7,2)
 DEPTNO                                   NUMBER(2)
----------------------------------------------------
my input file:

<?xml version='1.0'?>
<ROWSET>
  <ROW num="1">
    <EMPNO>7369</EMPNO>
    <ENAME>Smith</ENAME>
    <JOB>CLERK</JOB>
    <MGR>7902</MGR>
    <HIREDATE>12/17/1980 0:0:0</HIREDATE>
    <SAL>800</SAL>
    <COMM>23</COMM>
    <DEPTNO>20</DEPTNO>
  </ROW>
</ROWSET>
------------------------------------------ error msg
C:\XML_DB>java testInsert in.xml

<Line 1, Column 1>: XML-0108: (Fatal Error) Start of root element expected.
Exception in thread "main" oracle.xml.sql.OracleXMLSQLException: Start of root e
lement expected.
        at oracle.xml.sql.dml.OracleXMLSave.saveXML(OracleXMLSave.java:2093)
        at oracle.xml.sql.dml.OracleXMLSave.insertXML(OracleXMLSave.java:1083)
        at testInsert.main(testInsert.java:11)

----------------------------------------- code start

import java.sql.*;
import oracle.xml.sql.dml.OracleXMLSave;
public class testInsert
{
    public static void main(String argv[])
     throws SQLException
    {
     Connection conn = getConnection("scott","tiger");
     OracleXMLSave sav = new OracleXMLSave(conn, "scott.emp");
     
     sav.insertXML(argv[0]);
     sav.close();
    }
    // Get the connection given the user name and password..!
    private static Connection getConnection(String user, String passwd)
     throws SQLException
    {
     DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
     Connection conn =
         DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:zyx",
                         user,passwd);
     return conn;
    }
}
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
use :
sav.insertXML(sav.getUrl(argv[0]));
instead of
sav.insertXML(argv[0]);

insertXML needs an URL as argument, not an filename


or try out without your code first:

java OracleXML putXML \
      -user scott/tiger \
      -ignoreCase \
      -fileName yourfile.xml \
      yourtable
Helena Markováprogrammer-analyst

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept graf27's comment as answer.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Henka
EE Cleanup Volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial