External Parser - XML to Pipe Delimited - Sql Loader BETTER DBMS_XMLSTORE

Hi All,
If I have got data in GIGs in a complex format.
Can Using an External Java based XML Parser to convert XML to Pipe Delimited FIle and then Using SQL Loader
BE BETTER THAN
Using XSL to convert to Oracle <ROWSET> <ROW> Format and using DBMS_XMLSTORE to load data into tables.
In terms of:
Performace
Scalability
Exception Handling
Regards....

Go to the {forum:id=34} forum and look at the second page of the XML DB FAQ Thread (stickied to the top of the posts). While it doesn't compare using external tools to parse XML and load via SQL*Loader, it does talk about better ways to load large amounts of XML into the DB. This is also a good thread on the subject too from that forum, {thread:id=1096784}

Similar Messages

  • Load Xml Data in oracle (SQL LOADER)

    i have written a sql loader script given below....
    load data
    infile 'contact1.xml' "str '</CONTACT>'"
    truncate
    into table XmlTest
    dummy filler terminated by ">",
    Location_id enclosed by "<Location_id>" and "</Location_id>",
    fname enclosed by "<fname>" and "</fname>",
    lname enclosed by "<lname>" and "</lname>"
    the content of the contact1.xml is given below.....
    <CONTACT>
    <Location_id>1</Location_id>
    <fname>Robert</fname>
    <lname>Jones</lname>
    </CONTACT>
    <CONTACT>
    <Location_id>1</Location_id>
    <fname>Robert</fname>
    <lname>Jones</lname>
    </CONTACT>
    the script works fine for the given xml... but if one of the tag in the xml is changed to below syntax....
    <CONTACT Location_id="1">
    <fname>Robert</fname>
    <lname>Jones</lname>
    </CONTACT>
    <CONTACT Location_id="1">
    <fname>Robert</fname>
    <lname>Jones</lname>
    </CONTACT>
    what modification is required in the script to read such xml...Kindly Help!!

    And in what way does this relate to SQL and PL/SQL?
    There is a demo of loading XML in Morgan's Library under SQL*Loader.
    But as your question is off-topic here ... if the demo does not help you please continue this by starting a thread in the correct forum: Database General.
    Thanks.

  • XML Function pipe delimiter function error

    Hi SQL gurus,
    Thank you for any assistance. I was given the below query to use for taking a column that contains values and delimited with "|". below is a sample of the data in that column, the error, and the function with the query:
    XML parsing: line 1, character 199, illegal name character
    Item - Shim Stock | Type - Sheet | Material - Polyester | Thickness (In.) - 0.0005" | Thickness (mm) - 0.013mm | Thickness Tolerance - +/-0.000025" | Size - 5 x 20" | Width Tolerance - +/-0.0625" | Length Tolerance - +/-0.0625" | Moisture Absorption - 0.08% | Compress To - 1.00% | Color - Silver | Tensile Strength (PSI) - 30,000 psi | Temp. Range (F) - -90 to 300 Degrees | Meets/Exceeds - LP-377 | Package Quantity - 5
    CREATE FUNCTION [dbo].[split](
    @delimited NVARCHAR(MAX),
    @delimiter NCHAR(1)
    ) RETURNS @t TABLE (id INT IDENTITY(1,1), val NVARCHAR(MAX))
    AS
    BEGIN
    DECLARE @xml XML
    SET @xml = N'<t>' + REPLACE(@delimited,@delimiter,'</t><t>') + '</t>'
    INSERT INTO @t(val)
    SELECT r.value('.','varchar(MAX)') as item
    FROM @xml.nodes('/t') as records(r)
    RETURN
    END
    SELECT
    ItemNo, 2ItemNo,NameItem , SV.val, sv.id
    from #TableWithData v
    cross apply dbo.split(v.ColumnwithValues,'|') sv
    Edwin Lopera

    To get you moving, here is another example of a splitter that works with the examples you supplier:http://andrewtuerk.wordpress.com/2012/08/10/cross-apply-yes-you-can-use-a-table-valued-function-without-a-cursor/

  • Parse xml response from PL/SQL

    Can anyone please help me parse the xml below?
    DECLARE
       l_response     CLOB;
       g_system_id    VARCHAR2 (255);
       g_session_id   VARCHAR2 (255);
       g_user_id      VARCHAR2 (255);
    BEGIN
       l_response :=
          '--uuid:18cb22a2-11cc-43f4-bfea-c213da179d30+id=156
    Content-ID: <http://tempuri.org/0>
    Content-Transfer-Encoding: 8bit
    Content-Type: application/xop+xml;charset=utf-8;type="application/soap+xml"
    <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><a:Action s:mustUnderstand="1">http://tempuri.org/ILoginService/LoginByUserNameResponse</a:Action><a:RelatesTo>urn:uuid:cf410a05-23d4-4b92-a22c-329cbc19fbe7</a:RelatesTo></s:Header><s:Body><LoginByUserNameResponse xmlns="http://tempuri.org/"><LoginByUserNameResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:x="http://www.w3.org/2001/XMLSchema"><XObject.m_element i:type="x:string" xmlns="">&lt;OnlineContext SystemId="{19E0DDB4-5FA5-41EE-B624-AEA762865A6C}" SessionId="{F23D32A4-B325-4BFA-9E90-39CA253E843C}" UserId="{2C6ABE4C-D356-46F0-B4BE-9C4F0A36A522}" /&gt;</XObject.m_element></LoginByUserNameResult></LoginByUserNameResponse></s:Body></s:Envelope>
    --uuid:18cb22a2-11cc-43f4-bfea-c213da179d30+id=156--';
          SELECT systemid, sessionid, userid
            INTO g_session_id, g_system_id, g_user_id
            FROM XMLTABLE (
                    xmlnamespaces ('http://www.w3.org/2003/05/soap-envelope' AS "data"),
                    'data:LoginByUserNameResponse/LoginByUserNameResult/XObject.m_element/OnlineContext'
                    PASSING xmltype (l_response)
                    COLUMNS systemid VARCHAR2 (50) PATH '@OnlineContext',
                            sessionid VARCHAR2 (50) PATH '@OnlineContext',
                            userid VARCHAR2 (50) PATH '@OnlineContext') xt;
       DBMS_OUTPUT.put_line (
             'Session id '
          || g_session_id
          || ' System id '
          || g_system_id
          || ' User id '
          || g_user_id);
    END;
    Thanks.

    This gets you a little bit closer
    declare 
    -- Local variables here
    l_response     CLOB;
    g_system_id    VARCHAR2 (255);
    g_session_id   VARCHAR2 (255);
    g_user_id      VARCHAR2 (255);
    begin
    -- Test statements here
    l_response := '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"> 
    <s:Header>
        <a:Action s:mustUnderstand="1">http://tempuri.org/ILoginService/LoginByUserNameResponse</a:Action> 
        <a:RelatesTo>urn:uuid:cf410a05-23d4-4b92-a22c-329cbc19fbe7</a:RelatesTo>
    </s:Header>
    <s:Body>
        <LoginByUserNameResponse xmlns="http://tempuri.org/"> 
           <LoginByUserNameResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:x="http://www.w3.org/2001/XMLSchema"> 
              <XObject.m_element i:type="x:string" xmlns=""><OnlineContext SystemId="{19E0DDB4-5FA5-41EE-B624-AEA762865A6C}" SessionId="{F23D32A4-B325-4BFA-9E90-39CA253E843C}" UserId="{2C6ABE4C-D356-46F0-B4BE-9C4F0A36A522}" /></XObject.m_element>
              </LoginByUserNameResult>
          </LoginByUserNameResponse>
      </s:Body>
    </s:Envelope>';
        SELECT systemid, sessionid, userid
          INTO g_session_id, g_system_id, g_user_id
          FROM XMLTABLE (
                  xmlnamespaces ('http://www.w3.org/2003/05/soap-envelope' AS "s", 
                                 'http://tempuri.org/' as "data"), 
                  's:Envelope/s:Body/data:LoginByUserNameResponse/data:LoginByUserNameResult/XObject.m_element/OnlineContext'
                  PASSING xmltype (l_response)
                  COLUMNS systemid VARCHAR2 (50) PATH '@SystemId',
                          sessionid VARCHAR2 (50) PATH '@SessionId',
                          userid VARCHAR2 (50) PATH '@UserId') xt;
    DBMS_OUTPUT.put_line (
           'Session id '
        || g_session_id
        || ' System id '
        || g_system_id
        || ' User id '
        || g_user_id);
    end;    
    You will need to manually parse that CLOB and pull out the XML string itself from the response.  That can be done via SUBSTR and INSTR looking for the first < and last > in what you showed at least.  Updated from previous version to work properly with the xmlns="", which resets the default namespace back to the default value.  The XPath was corrected to reflect proper prefix usage.

  • SQL-Loader and Pipes

    I have to insert 300.000.000 datasets (generated dynamically by a seperate process) into an Oracle 8.1.6 database. I'd like to do this via SQL-Loader but since Linux (kernel 2.2 at least) supports only files up to 2Gigs and I don't have the necessary space on my machine to generate a large amount of ASCII files I'd like to ask whether there is a possibility to use an ordinary pipe in combination with SQL-Loader. I tried to use a named pipe but all my attempts failed.
    I don't like to use Perl and the DBI module since this would be far so slow (would take about one week I guess).
    Hans

    External tables are accessible from SQL, which generally simplifies life if the data files are physically located on the database server since you don't have to coordinate a call to an external SQL*Loader script with other PL/SQL processing. Under the covers, external tables are normally just invoking SQL*Loader.
    SQL*Loader is more appropriate if the data files are on a different server or if it is easier to call an executable rather than calling PL/SQL (i.e. if you have a batch file that runs on a server other than the database server that wants to FTP a data file from a FTP server and then load the data into Oracle).
    Justin

  • XML Column from table extract to Pipe Delimited Text File

    Hi,
    I have an XML column with large data in a Table ( Source SQL server Database).
    I was asked to   extract    XML column to .txt file using SSIS.
    Is it possible to extract xml column with huge data to text file ?
    when I tried,  select XML column from Table in source , I noticed  that Property of column is taken as [DT_NTEXT] . I Converted it to DT_TEXT as Ansi donot support DT_NTEXT.
    Execution method was success but it failed due to trucation. so wondering is there a way to get XML column extracted to Pipe delimited text file?
    Is it advisable to do this ? or IS It Valid to export XML in Pipe Delimited File ?
    Please Kindly advice
    thanks
    kodi

    Are you looking at shredding data within XML nodes and then importing it to text file or are you looking at exporting XML value as is? Also is SSIS a necessity?
    If not, You can simply use T-SQL for this along with bcp for this. just use a query like
    EXEC xp_cmdshell 'bcp "SELECT CAST(XMLColumn AS varchar(max)) AS Column FROM table" queryout <full file path> -c -S <ServerName> -T -t |'
    provided you use trusted connection (windows authentication)
    see
    http://visakhm.blogspot.in/2013/10/bcp-out-custom-format-data-to-flat-file.html
    If you want to shred the data use Xpath functions in the query as below
    http://visakhm.blogspot.in/2012/10/shred-data-as-well-as-metadata-from-xml.html
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • SQL *Loader and External Table

    Hi,
    Can anyone tell me the difference between SQL* Loader and External table?
    What are the conditions under we can use SQL * Loader and External Table.
    Thanx

    External tables are accessible from SQL, which generally simplifies life if the data files are physically located on the database server since you don't have to coordinate a call to an external SQL*Loader script with other PL/SQL processing. Under the covers, external tables are normally just invoking SQL*Loader.
    SQL*Loader is more appropriate if the data files are on a different server or if it is easier to call an executable rather than calling PL/SQL (i.e. if you have a batch file that runs on a server other than the database server that wants to FTP a data file from a FTP server and then load the data into Oracle).
    Justin

  • Parse XML in PL/SQL

    I need help with parsing xml data in PL/SQL. I was able to read the attribute name & values but not able to read the element text.Any help is greatly appreciated.Following is the anonymous block and the desired output -
    Declare
    nl xmldom.DOMNodeList;
    len1 number;
    len2 number;
    n xmldom.DOMNode;
    e xmldom.DOMElement;
    nnm xmldom.DOMNamedNodeMap;
    attrname varchar2(100);
    attrval varchar2(100);
    doc xmldom.DOMDocument;
    p xmlparser.Parser;
    in_xml clob;
    begin
    -- get all elements
    p := xmlparser.newParser;
    in_xml := '<?xml version="1.0" encoding="utf-8"?>
    <Issue>
    <T_ISSUE_TITLE ID = "1">Test Issue</T_ISSUE_TITLE>
    <T_ISSUE_DESC ID = "2">Update Test Issue</T_ISSUE_DESC>
    <STATUS ID = "3">2</STATUS>
    <ISSUE_SD ID = "4">07/09/10</ISSUE_SD>
    <ISSUE_ED ID = "5">09/09/10</ISSUE_ED>
    <CREATE_DT ID = "6">07/09/10</CREATE_DT>
    <CREATE_USER_ID ID = "7">John</CREATE_USER_ID>
    <LST_UPD_USER_ID ID = "8">John</LST_UPD_USER_ID>
    </Issue>';
    xmlparser.parseClob(p,in_xml);
    doc :=xmlparser.getDocument(p);
    nl := xmldom.getElementsByTagName(doc, '*');
    len1 := xmldom.getLength(nl);
    -- loop through elements
    for j in 0..len1-1 loop
    n := xmldom.item(nl, j);
    e := xmldom.makeElement(n);
    dbms_output.put_line(xmldom.getTagName(e) || ':');
    -- get all attributes of element
    nnm := xmldom.getAttributes(n);
    len2 := xmldom.getLength(nnm);
    if (xmldom.isNull(nnm) = FALSE) then
    len2 := xmldom.getLength(nnm);
    -- loop through attributes
    for i in 0..len2-1 loop
    n := xmldom.item(nnm, i);
    --dbms_output.put_line(n);
    attrname := xmldom.getNodeName(n);
    attrval := xmldom.getNodeValue(n);
    dbms_output.put_line(' ' || attrname || ' = ' || attrval);
    end loop;
    end if;
    end loop;
    end;
    /** Output
    Issue:
    T_ISSUE_TITLE:
    ID = 1, Test Issue
    T_ISSUE_DESC:
    ID = 2, Update Test Issue
    STATUS:
    ID = 3, 2
    ISSUE_SD:
    ID = 4, 07/09/10
    ISSUE_ED:
    ID = 5, 09/09/10
    CREATE_DT:
    ID = 6, 07/09/10
    CREATE_USER_ID:
    ID = 7, John
    LST_UPD_USER_ID:
    ID = 8, John
    Thank You.

    Use dbms_xslprocessor.valueOf and dbms_xmldom.getnodevalue to get the value of node
    eg: l_doc is paresed XML doc with nodes as partdetails and part
    declare
      l_n       dbms_xmldom.DOMNode;
      l_nl      dbms_xmldom.DOMNodeList;
    l_partname varchar2(100);
    begin
    ---parsing code--
    l_nl := dbms_xslprocessor.selectNodes(dbms_xmldom.makeNode(l_doc),'/PartDetails/Part');
    FOR cur_emp IN 0 .. dbms_xmldom.getLength(l_nl) - 1 LOOP
      l_n := dbms_xmldom.item(l_nl, cur_emp);
      dbms_xslprocessor.valueOf(l_n,'Name/text()',l_partname);
    dbms_output.put_line(l_partname);
    end loop;
    end;Edited by: SBH on Jul 13, 2010 11:06 AM

  • SQL Loader versus External Table

    If anyone has worked on external tables please let me know your views.

    user637544 wrote:
    for sqlldr i follow the following approach
    1. truncate table
    2. call sqlldr and load records in staging table
    3. check for bad records
    how do i tuncate, call external table and check bad records for external table.As part of the SQL*Loader control file you can tell it to truncate the table as part of the process before it loads in the data.
    The key differences between SQL*Loader and External Tables are:
    1. SQL*Loader is an external utility run from the o/s command line, whereas External tables are usable from within SQL and PL/SQL.
    2. SQL*Loader can only load data up into the database, whereas External tables can allow you to read files and write files (10g onwards)
    3. SQL*Loader has limited control on skipping rows etc. whereas External tables can be queried using SQL and has all the flexibility that SQL can offer.
    4. SQL*Loader requires connection information to the database, whereas External tables are already part of the database
    5. SQL*Loader can only change the source filename through dynamic o/s level scripts, whereas External tables can have the filename changed using an ALTER TABLE ... LOCATION ... command.
    If you want to truncate your staging table before loading it with data from the external table, then you will just have to do that as a seperate step, because the external table is not associated with other tables. Simply truncate the other table and then query the data from the external table into the staging table.
    External tables offer a lot more flexibility than using SQL*Loader.

  • Request: PL/SQL, External Table and SQL Loader

    I see lately Questions asked in SQL and PL/SQL forum regarding SQL Loader and External Table are being moved to {forum:id=732}.
    Being an PL/SQL developer for some time now i feel External Table (and if i may, SQL Loader and DBMS_DATAPUMP) are very much an integral part of a PL/SQL development and the question related to these topics are well suited in SQL and PL/SQL forum. Even in SQL and PL/SQL FAQ we have exclusive content that discuss on these topics {message:id=9360007}
    So i would like to request the moderators to consider not moving such questions out of the SQL and PL/SQL forum.
    Thanks,
    Karthick.

    Karthick_Arp wrote:
    I see lately Questions asked in SQL and PL/SQL forum regarding SQL Loader and External Table are being moved to {forum:id=732}.
    Being an PL/SQL developer for some time now i feel External Table (and if i may, SQL Loader and DBMS_DATAPUMP) are very much an integral part of a PL/SQL development and the question related to these topics are well suited in SQL and PL/SQL forum. Even in SQL and PL/SQL FAQ we have exclusive content that discuss on these topics {message:id=9360007}
    So i would like to request the moderators to consider not moving such questions out of the SQL and PL/SQL forum.
    Thanks,
    Karthick.Not sure which moderators are moving them... cos it ain't me. I'm quite happy to leave those there.

  • Sql Loader and carriage returns

    I am currently trying to use sql loader to load data from flat files that was extracted from sybase using bcp and delimited with pipes. There are text and varchar columns that contain carriage return line feeds. I want to preserve these, but I can not load them into Oracle 8.05 using sql loader as it interprets them as end of record indicators. Does anyone have a way to solve this problem? Any assistance would be appreciated.
    Thanks in advance,
    Jignesh

    External tables are accessible from SQL, which generally simplifies life if the data files are physically located on the database server since you don't have to coordinate a call to an external SQL*Loader script with other PL/SQL processing. Under the covers, external tables are normally just invoking SQL*Loader.
    SQL*Loader is more appropriate if the data files are on a different server or if it is easier to call an executable rather than calling PL/SQL (i.e. if you have a batch file that runs on a server other than the database server that wants to FTP a data file from a FTP server and then load the data into Oracle).
    Justin

  • Sql loader and Store Prrocedures

    Hi!!
    I ned load text files with sql loader first at temporal tables,later on put this in tables with Stored Procedures in one data base Oracle 8.1.5.
    My sqlldr version is 8.1.6 and not4s compatible with 8.1.5 of the data base server.
    How can i load the files?
    Thank4s

    External tables are accessible from SQL, which generally simplifies life if the data files are physically located on the database server since you don't have to coordinate a call to an external SQL*Loader script with other PL/SQL processing. Under the covers, external tables are normally just invoking SQL*Loader.
    SQL*Loader is more appropriate if the data files are on a different server or if it is easier to call an executable rather than calling PL/SQL (i.e. if you have a batch file that runs on a server other than the database server that wants to FTP a data file from a FTP server and then load the data into Oracle).
    Justin

  • Sql*Loader and Conc. Mgr.

    I would like for our users to submit a request (in GL) that will run sql*loader to load a file of their choosing to an oracle table. Oracle tells me I must use their consulting arm for this kind of question. Does anyone have any ideas on how to do this?

    External tables are accessible from SQL, which generally simplifies life if the data files are physically located on the database server since you don't have to coordinate a call to an external SQL*Loader script with other PL/SQL processing. Under the covers, external tables are normally just invoking SQL*Loader.
    SQL*Loader is more appropriate if the data files are on a different server or if it is easier to call an executable rather than calling PL/SQL (i.e. if you have a batch file that runs on a server other than the database server that wants to FTP a data file from a FTP server and then load the data into Oracle).
    Justin

  • Loading through sql* loader

    Hi,
    I want to load xml file data using sql*loader into Oracle.
    Kindly advice what could be the pros & cons for this.
    Is there any online document for this?
    Thanks
    Deepak

    Is there any online document for this?<br>
    Here it is

  • SQL*Loader problem - not efficient, parsing error for big xml files

    Hi Experts,
    First of all, I would like to store xml files in object relation way. Therefore I created a schema and a table for it (see above).
    I wants to propagate it (by using generated xml files), hence I created a control file for sql loader (see above).
    I have two problems for it.
    1, It takes a lot of time. It means I can upload a ~80MB file in 2 hours and a half.
    2, At bigger files, I got the following error messages (OCI-31011: XML parsing failed OCI-19202: Error occurred in XML processing LPX-00243: element attribute value must be enclosed in quotes). It is quite interesting because my xml file is generated and I could generated and uploaded the first and second half of the file.
    Can you help me to solve these problems?
    Thanks,
    Adam
    Control file
    UNRECOVERABLE
    LOAD DATA
    CHARACTERSET UTF8
    INFILE *
    APPEND
    INTO TABLE coll_xml_objrel
    XMLTYPE(xml)
    FIELDS
    ident constant 2
    ,file_name filler char(100)
    ,xml LOBFILE (file_name) TERMINATED BY EOF
    BEGINDATA
    generated1000x10000.xml
    Sql Loader command
    sqlldr.exe username/password@//localhost:1521/SID control='loader.ctl' log='loadr.log' direct=true
    Schema
    <?xml version="1.0" encoding="UTF-8"?>
    <schema targetNamespace="http://www.something.com/shema/simple_searches" elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.something.com/shema/simple_searches">
        <element name="searches" type="tns:searches_type"></element>
        <element name="search" type="tns:search_type"></element>
        <element name="results" type="tns:results_type"></element>
        <element name="result" type="tns:result_type"></element>
        <complexType name="searches_type">
            <sequence>
                <element ref="tns:search" maxOccurs="unbounded"></element>
            </sequence>
        </complexType>
        <complexType name="search_type">
            <sequence>
                <element ref="tns:results"></element>
            </sequence>
            <attribute ref="tns:id" use="required"></attribute>
            <attribute ref="tns:type" use="required"></attribute>
        </complexType>
        <complexType name="results_type">
            <sequence maxOccurs="unbounded">
                <element ref="tns:result"></element>
            </sequence>
        </complexType>
        <complexType name="result_type">
            <attribute ref="tns:id" use="required"></attribute>
        </complexType>
        <simpleType name="type_type">
            <restriction base="string">
                <enumeration value="value1"></enumeration>
                <enumeration value="value2"></enumeration>
            </restriction>
        </simpleType>
        <attribute name="type" type="tns:type_type"></attribute>
        <attribute name="id" type="string"></attribute>
    </schema>
    Create table
    create table coll_xml_objrel
    ident Number(20) primary key,
    xml xmltype)
    Xmltype column xml
    store as object relational
    xmlschema "http://www.something.com/schema/simple_searches.xsd"
    Element "searches";

    Hi Odie_63,
    Thanks for your answer.
    I will post this question in the XML DB forum too (edit: I realized that you have done it. Thanks for it).
    1, Version: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    2, see above
    3, I have registered my schema with using dbms_xmlschema.registerSchema function.
    Cheers,
    Adam
    XML generator:
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import javax.xml.stream.XMLOutputFactory;
    import javax.xml.stream.XMLStreamException;
    import javax.xml.stream.XMLStreamWriter;
    public class mainGenerator {
        public static void main(String[] args) throws FileNotFoundException, XMLStreamException {
            // TODO Auto-generated method stub
            final long numberOfSearches = 500;
            final long numberOfResults = 10000;
            XMLOutputFactory xof = XMLOutputFactory.newFactory();
            XMLStreamWriter writer = xof.createXMLStreamWriter(new FileOutputStream("C:\\Working\\generated500x10000.xml"));
            writer.writeStartDocument();
            writer.writeStartElement("tns","searches", "http://www.something.com/schema/simple_searches");
            writer.writeNamespace("tns", "http://www.something.com/schema/simple_searches");
            for (long i = 0; i < numberOfSearches; i++){
                Long help = new Long(i);
                writer.writeStartElement("tns","search", "http://www.something.com/schema/simple_searches);
                writer.writeAttribute("tns", "http://www.something.com/schema/simple_searches", "type", "value1");
                writer.writeAttribute("tns", "http://www.something.com/schema/simple_searches", "id", help.toString());
                writer.writeStartElement("tns","results", "http://www.something.com/schema/simple_searches");
                for (long j = 0; j < numberOfResults; j++){
                    writer.writeStartElement("tns","result", "http://www.something.com/schema/simple_searches");
                    Long helper = new Long(i*numberOfResults+j);
                    writer.writeAttribute("tns", "http://www.something.com/schema/simple_searches", "id", helper.toString());
                    writer.writeEndElement();
                writer.writeEndElement();
                writer.writeEndElement();
            writer.writeEndElement();
            writer.writeEndDocument();
            writer.close();
    registerSchema:
    begin
    dbms_xmlschema.registerSchema(
    'http://www.something.com/schema/simple_searches',
    '<?xml version="1.0" encoding="UTF-8"?>
    <schema targetNamespace="http://www.something.com/schema/simple_searches" elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.something.com/schema/simple_searches">
        <element name="searches" type="tns:searches_type"></element>
        <element name="search" type="tns:search_type"></element>
        <element name="results" type="tns:results_type"></element>
        <element name="result" type="tns:result_type"></element>
        <complexType name="searches_type">
            <sequence>
                <element ref="tns:search" maxOccurs="unbounded"></element>
            </sequence>
        </complexType>
        <complexType name="search_type">
            <sequence>
                <element ref="tns:results"></element>
            </sequence>
            <attribute ref="tns:id" use="required"></attribute>
            <attribute ref="tns:type" use="required"></attribute>
        </complexType>
        <complexType name="results_type">
            <sequence maxOccurs="unbounded">
                <element ref="tns:result"></element>
            </sequence>
        </complexType>
        <complexType name="result_type">
            <attribute ref="tns:id" use="required"></attribute>
        </complexType>
        <simpleType name="type_type">
            <restriction base="string">
                <enumeration value="value1"></enumeration>
                <enumeration value="value2"></enumeration>
            </restriction>
        </simpleType>
        <attribute name="type" type="tns:type_type"></attribute>
        <attribute name="id" type="string"></attribute>
    </schema>',
    TRUE, TRUE, FALSE, FALSE);
    end

Maybe you are looking for