I'm using ColdFusion (openBlueDragon) to place the information from the large (200MB) xml file right into a database without needing to load the whole file into memory that is the way i typically would get it done. I saw a Much The Same QUESTION here: Looping over a large XML file that appears to become the solution I'm searching for.
However, I am novice enough in java to know and adapt the code to me. I discovered not a way to reply to the expert (@orangepips) who published the code otherwise I wouldn't have published this type of similar question.
My xml file appears like this:
<allItems> <item> <subject>The subject text</subject> <date>2007-05-21 04:03:00</date> <content>text content often contains many paragraphs of text</content> <author>JPass78</author> </item> </allItems>
This is actually the code, courtesy orangepips, that I am attempting to adapt for my purpose. I have modified it a little to incorporate my very own area names:
<cfset fis = createObject("java", "java.io.FileInputStream").init( "#getDirectoryFromPath(getCurrentTemplatePath())#/file.xml")> <cfset bis = createObject("java", "java.io.BufferedInputStream").init(fis)> <cfset XMLInputFactory = createObject("java", "javax.xml.stream.XMLInputFactory").newInstance()> <cfset reader = XMLInputFactory.createXMLStreamReader(bis)> <cfloop condition="#reader.hasNext()#"> <cfset event = reader.next()> <cfif event EQ reader.START_ELEMENT> <cfswitch expression="#reader.getLocalName()#"> <cfcase value="allItems"> <!--- root node, do nothing ---> </cfcase> <cfcase value="item"> <!--- set values used later on for inserts, selects, updates ---> </cfcase> <cfcase value="subject"> <!--- some selects and insert ---> </cfcase> <cfcase value="contentdate"> <!--- insert or update ---> </cfcase> <cfcase value="content"> </cfcase> <cfcase value="author"> </cfcase> </cfswitch> </cfif> </cfloop> <cfset reader.close()>
I've got a single table and i'm trying to puzzle out how do you access the values from each XML element and so i may place it one row at any given time? such as this: Place INTO content (subject,contentdate, content, author) VALUES ("The topic text", 2007-5-21 04:03:00, "text content here","JPass78")