Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 575
  • Last Modified:

using the sax parser with oracle 8.1.7


i am running an oracle 8.1.7 database. i'm looking for a way to use the sax parser to parse a xml file, transform it with an xsl file, and output a new xml file. i am currently doing this with the dom api, but some of the files are too big and i'm running out of memory.  i should specify that i'm not trying to change the original xml data in any way. the xsl is just to extract the data from the original xml file and put in into a form where the tag names match the column names of the oracle table i want to insert it to. is it possible to do this with the sax api?  i am not familiar with java. could someone please provide me with some code examples of how to use the sax api as mentioned?  i will need to call this thing from within a pl/sql procedure.  i have pasted in example xml file and xsl file. any help is appreciated. thanks.

bp


example xml file------------------------------------------------------------
<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
     xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
     xmlns:rs='urn:schemas-microsoft-com:rowset'
     xmlns:z='#RowsetSchema'>
<s:Schema id='RowsetSchema'>
     <s:ElementType name='row' content='eltOnly' rs:updatable='true'>
          <s:AttributeType name='BeginDate' rs:number='1' rs:write='true'>
               <s:datatype dt:type='dateTime' rs:dbtype='variantdate' dt:maxLength='16' rs:precision='0' rs:fixedlength='true'
                rs:maybenull='false'/>
          </s:AttributeType>
          <s:AttributeType name='EndDate' rs:number='2' rs:write='true'>
               <s:datatype dt:type='dateTime' rs:dbtype='variantdate' dt:maxLength='16' rs:precision='0' rs:fixedlength='true'
                rs:maybenull='false'/>
          </s:AttributeType>
          <s:AttributeType name='c2' rs:name='Site Master' rs:number='3' rs:write='true'>
               <s:datatype dt:type='string' dt:maxLength='4294967295' rs:precision='0' rs:long='true' rs:maybenull='false'/>
          </s:AttributeType>
          <s:AttributeType name='Permit' rs:number='4' rs:write='true'>
               <s:datatype dt:type='string' dt:maxLength='4294967295' rs:precision='0' rs:long='true' rs:maybenull='false'/>
          </s:AttributeType>
          <s:AttributeType name='c4' rs:name='Permit Condition' rs:number='5' rs:write='true'>
               <s:datatype dt:type='string' dt:maxLength='4294967295' rs:precision='0' rs:long='true' rs:maybenull='false'/>
          </s:AttributeType>
          <s:AttributeType name='c5' rs:name='Permit Condition Brief' rs:number='6' rs:write='true'>
               <s:datatype dt:type='string' dt:maxLength='4294967295' rs:precision='0' rs:long='true' rs:maybenull='false'/>
          </s:AttributeType>
          <s:AttributeType name='Active' rs:number='7' rs:write='true'>
               <s:datatype dt:type='dateTime' rs:dbtype='variantdate' dt:maxLength='16' rs:precision='0' rs:fixedlength='true'
                rs:maybenull='false'/>
          </s:AttributeType>
          <s:AttributeType name='Inactive' rs:number='8' rs:write='true'>
               <s:datatype dt:type='dateTime' rs:dbtype='variantdate' dt:maxLength='16' rs:precision='0' rs:fixedlength='true'
                rs:maybenull='false'/>
          </s:AttributeType>
          <s:extends type='rs:rowbase'/>
     </s:ElementType>
</s:Schema>
<rs:data>
     <z:row BeginDate='2002-12-14T10:31:06' EndDate='2003-03-14T10:31:06' c2='SM Fermentation Non-App Determin. of Pharma MACT Standards'
           Permit='Tippe Title V Permit' c4='D.3.1 Non-Appicability Determination of Pharma MACT Standards' c5='The emission units associated with the fermentation operations do not process, use, or produce (HAPs). Therefore pursuant to 40 CFR 63.1250(a)(1)(iii), the emission units associated with the fermentation operations are not subject to 40 CFR 63, GGG.'
           Active='2001-01-01T00:00:00' Inactive='1899-12-30T00:00:00'/>
     <z:row BeginDate='2002-12-14T10:31:06' EndDate='2003-03-14T10:31:06' c2='SM Fermentation Non-App Determin. of State VOC Emission Std.-a'
           Permit='Tippe Title V Permit' c4='D.3.2a Non-Applicability Determin. of State VOC Emission Std.' c5='The emission units associated with the fermentation operations do not manufacture Pharmeceutical products by chemical synthesis. Therefore, the emission units associated with the fermentation operations are not subject to 326 IAC 8-5-3.'
           Active='2001-01-01T00:00:00' Inactive='1899-12-30T00:00:00'/>
     <z:row BeginDate='2002-12-14T10:31:06' EndDate='2003-03-14T10:31:06' c2='SM Fermentation Non-App Determin. of State VOC Emission Std.-b'
           Permit='Tippe Title V Permit' c4='D.3.2b Non-Applicability Determin. of State VOC Emission Std.' c5='The emission units associated with the fermentation operations are not subject to the requirements of 326 IAC 8-1-6 because the VOC emissions associated with each emission project are less than 25 tons per year.'
           Active='2001-01-01T00:00:00' Inactive='1899-12-30T00:00:00'/>
</rs:data>
</xml>

example xsl file-------------------------------------------------------
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rs='urn:schemas-microsoft-com:rowset' xmlns:z='#RowsetSchema'
       version="1.0"><xsl:output method="xml" indent="yes"/> <xsl:template match="rs:data">
<xml>
<ROWSET>Table_Name="BO_REQ_MGMT_PERMIT"
<xsl:apply-templates />
</ROWSET>
</xml>
</xsl:template>
<xsl:template match="z:row">
<ROW>
<SITE_MASTER> <xsl:value-of select="@c2"/> </SITE_MASTER>
<PERMIT> <xsl:value-of select="@Permit"/> </PERMIT>
<PERMIT_CONDITION> <xsl:value-of select="@c4"/> </PERMIT_CONDITION>
<PERMIT_CONDITION_BRIEF> <xsl:value-of select="@c5"/> </PERMIT_CONDITION_BRIEF>
<ACTIVE_DATE> <xsl:value-of select="@Active"/> </ACTIVE_DATE>
<INACTIVE_DATE>  <xsl:value-of select="@Inactive"/> </INACTIVE_DATE>
</ROW>
</xsl:template>
</xsl:stylesheet>
0
indypung
Asked:
indypung
1 Solution
 
benpungCommented:
solved this question myself with this code:


import java.io.*;

/**
 * A simple demo of JAXP 1.1
 */
public class SimpleJaxp {

    /**
     * Accept two command line arguments: the name of an XML
     * file, and the name of an XSLT stylesheet. The result
     * of the transformation is written to stdout.
     */
    public static void main(String[] args)
         throws javax.xml.transform.TransformerException {
     if (args.length != 3) {
       System.err.println("Usage:");
       System.err.println("  java " + SimpleJaxp.class.getName(  )
                 + " xmlFileName xsltFileName" + " outputfilename");
       System.exit(1);
     }

     File xmlFile = new File(args[0]);
     File xsltFile = new File(args[1]);
     File outputFile = new File (args[2]);

     javax.xml.transform.Source xmlSource =
       new javax.xml.transform.stream.StreamSource(xmlFile);
     javax.xml.transform.Source xsltSource =
       new javax.xml.transform.stream.StreamSource(xsltFile);
     javax.xml.transform.Result result =
       new javax.xml.transform.stream.StreamResult(outputFile);

     // create an instance of TransformerFactory
     javax.xml.transform.TransformerFactory transFact =
       javax.xml.transform.TransformerFactory.newInstance(  );

     javax.xml.transform.Transformer trans =
        transFact.newTransformer(xsltSource);

     trans.transform(xmlSource, result);

 }
}

this reads in a xml file and xsl file and sends the transformed output to a system file.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now