How do I create individual xml files from the parsed data output of a xml file?

I have written a program (DOM Parser) that parses data from a XMl File. I would like to create an individual file with the corresponding name for each set of data parsed from the xml document. If the parsed output is Single, Double, Triple, I would like to create an individual xml file (Single.xml, Double.xml, Triple.xml)with those corresponding names. How do I create the xml files and give each file the name of my parsed data output? Thanks in advance for your help.
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
public class MyDomParser {
  public static void main(String[] args) {
  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  try {
  DocumentBuilder builder = factory.newDocumentBuilder();
  Document doc = builder.parse("ENtemplate.xml");
  doc.normalize();
  NodeList rootNodes = doc.getElementsByTagName("templates");
  Node rootNode = rootNodes.item(0);
  Element rootElement = (Element) rootNode;
  NodeList templateList = rootElement.getElementsByTagName("template");
  for(int i=0; i < templateList.getLength(); i++) {
  Node theTemplate = templateList.item(i);
  Element templateElement = (Element) theTemplate;
  System.out.println("Template" + ": " +templateElement.getAttribute("name")+ ".xml");
  } catch (ParserConfigurationException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  } catch (SAXException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  } catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();

Ive posted the new code but now I'm getting a FileAlreadyExistException error. How do I handle this exception error correctly in my code?
import java.io.IOException;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
public class MyDomParser {
  public static void main(String[] args) {
  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  try {
  DocumentBuilder builder = factory.newDocumentBuilder();
  Document doc = builder.parse("ENtemplate.xml");
  doc.normalize();
  NodeList rootNodes = doc.getElementsByTagName("templates");
  Node rootNode = rootNodes.item(0);
  Element rootElement = (Element) rootNode;
  NodeList templateList = rootElement.getElementsByTagName("template");
  for(int i=0; i < templateList.getLength(); i++) {
  Node theTemplate = templateList.item(i);
  Element templateElement = (Element) theTemplate;
  System.out.println(templateElement.getAttribute("name")+ ".xml");
  for(int i=0; i < templateList.getLength(); i++) {
  Node theTemplate = templateList.item(i);
  Element templateElement = (Element) theTemplate;
  String fileName = templateElement.getAttribute("name") + ".xml";
  Files.createFile(Paths.get(fileName));
  System.out.println("File" + ":" + fileName + ".xml created");
  } catch (ParserConfigurationException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  } catch (SAXException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  } catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();

Similar Messages

  • How do i create a database template from the command line?

    Hi,
    As part of implementing a backup and recovery strategy for a client (including disaster recovery) I want to automate the creation of a database template From an Existing Database (Structure as well as data) via a script that will run every night.
    The background to this is that we will also be using RMAN to take backups of the database concerned but the client does not want to wait while an RMAN backup is restored and so wants an additional level of insurance in the form of a ‘standby’ clone database.
    The idea is that nightly we will run a script that creates a database template from the Existing Database (Structure as well as data) and then transfers the 2 files involved e.g. DB_data_included.dbc and DB_data_included.DFB across to a standby server where they can be used to recreate the database in the event of us needing to after e.g. a complete server failure.
    So I have a couple of questions about this that I would be very grateful if something could answer for me:
    1)     Is it possible? That is, can a database template be created from some utility by supplying a series of parameter=value pairs on the command line?
    2)     If yes how do I go about it, what utility do I use (the emca utility?). and what parameters do I need to supply on the command line to create the template?
    3)     The intention is that the script to create the template will run in the early hours of the morning when no-one is using the database but what state does the database need to be in when the template creation script runs i.e. up, down, mounted and does the creation of a template affect the state of an already up database i.e. if I kick off the template creation script and the database is up will it switch it into mount mode or anything like that? My concern here is that I want to make sure I understand exactly what is going on so that no users or connected external systems are affected?
    Thanks in anticipation of someone being able to guide me on what to do or what documentation to read.
    Also if you require any clarification on what i'm asking please post up your query and i'll respond ASAP.
    Kind Regards,
    George Johnston
    OCP 9i DBA

    Sybrandb,
    Firstly thanks for you reponse.
    However, I don’t agree that dbca only creates empty databases otherwise why does the option to create a template from an existing database (structure as well as data) exist in the dbca wizard?
    I have performed a test case where I have a created a database template including data on one 10g server. I have then used the files generated to recreate that database on a separate server. When the new database is started it is an exact copy of the original. So it’s not empty at all , it’s exactly what the client wants.
    So I don’t agree that I’m gaining zero.
    Why is this approach doomed to fail?
    There a number of reasons why I “just set up a proper standby database”
    1.     Time – I’m on a customer site in a tight engagement where the customer wants maximum value for money. I don’t have standby database skills and the customer isn’t willing to pay for me to learn on the job so please understand the tight circumstances I’m working in.
    2.     Availability – As far as I know the client is running 10.2.0.3.0 standard edition. Correct me if I’m wrong but is standby db available in that edition. Where do I look to check V$OPTION.
    On the RMAN duplicating a database front it’s an area I haven’t used before but I will take a look at it.
    Also please revisit the context of my original posting where I state
    The background to this is that we will also be using RMAN to take backups of the database concerned but the client does not want to wait while an RMAN backup is restored and so wants an additional level of insurance in the form of a ‘standby’ clone database.
    So please understand that this a quick fix that the client wants developed in the minimum time possible in ADDITION to a full nightly RMAN backup being taken.
    In an ideal world I’d have the time to follow best practice but in the real world of on-site customer support I just need to get the job done operating under the customer imposed constraints.
    Many Thanks,
    George Johnston
    OCP 9i DBA

  • How can I create an audio CD from the audio only portion of my iMovie?

    Hello, I brought in about 50 min of Digital video into iMovie, I separated (split) the audio from the video, I unlocked the audio, I deleted the video, and now I want to just create an audio CD from the audio that is left.
    Can I do this? and if yes how? If I can not, how can I create an Audio CD from on my G5 off a tape on my digital camcorder?
    Any help would be apprecaited.

    This is how:
    Go to:
    'File'
    'Share'
    'Quicktime'
    'Expert Settings'
    'Audio as AIFF' or pick your brand of compression.
    Drag and drop the resulting file into iTunes.
    Enjoy!
    P.S. - You didn't need to delete the video but I think that'll be okay.

  • How do I delete individual phone calls from the recent tab on my 3GS?

    Hi there all,
    My first post online in an Apple forum. God I wish I switched from my HTC pile of %$*&! to an iPhone earlier, what a great phone.
    I have gone online and read the manual as to trying to find the answer but I can't. So maybe fellow users can assist me?
    In the recent calls tab on Ver 3.1 How do I delete individual calls without deleting the entire history of all the other calls?
    Say I have ten phone calls on my screen in the recent tab. I want to delete the one from Bob Claus and leave the rest of the history of all other callers there?
    How does one do this please?
    Many thanks in advance for your assistance and advice.

    Welcome to the discussions,
    this is not supported at this time. If you want this feature, you can leave your suggestion directly here http://www.apple.com/feedback/iphone.html

  • How can i create multiple apple ids from the same mac

    There seems to be a limit on how many apple ids can be created from the same cpu. Trying to create 100 apple ids for a client to use on ipads distributed to employees i found i could only create three or four before i got the message account cannot be created, contact itunes support. Had the same problem creating multiple itunes accounts through the App Store.

    I found this discussion because I need to create dozens of Apple IDs for the faculty and staff of the school for which I'm the IT Director.
    This is weak.
    Apple, PLEASE upgrade the Apple ID system so it represents the current needs and paradigm.
    What am I thinking, Apple (like Google) don't follow user discussion forums, except by accident when an employee sees something and is motivated enough to carry the water for users in need.

  • How do I create a new contact from the same company as one I already have

    How do I simply create multiple contacts from the same company? In Outlook this is achieved using by "New contact from same company". Is there a similar function in gMail contacts?

    Check that out with Gmail support.
    http://mail.google.com/support/

  • How can I create an internal space from the border in every cell in a table?

    How can I create an space between the text contents and the border inside in every cell in a table in Pages?

    Change the Inset margin in the Inspector palette > T tab > Text

  • I am having problems downloading files from the web. After a number of files are downloaded, the system become sluggish, and then hangs. I traced the problem to the download history file: downloads.sqlite.

    After downloading a number of 1.0 MB files, the system became very sluggish, and I started to get lots of (Not Responding) messages when trying to download or just use Firefox for browsing. Using Performance Monitor, I observed that the Firefox executable was growing larger and larger - up to as large as 1.2 GB on a system with 2.0 GB memory. Page faults were off the chart.
    Looking for a similar problem, I found one that discussed the downloads.sqlite file becoming corrupted. I first noticed that this file was over 600 MB in size, so I deleted it. I then downloaded additional files, and observed that the new downloads.sqlite file would increase in size by about 150% of the size of each file that was downloaded. Once it would get up to 500 MB in size, the system started slowing down again.
    I don't know the purpose of this file, but it appears that it keeps a full copy of every file downloaded, which may be the function of a download history file, but it does not seem correct that the file should grow in size without limit, and thus impact the system.
    I would also appear that the Firefox executable is trying to read the entire contents of this file each time a new file is downloaded, which does not seem right.
    Temporary fix is to periodically delete the downloads.sqlite file when it gets too large and starts impacting performance.. Apparently it is smart enough to open a new file if the old one is not found. I am not sure what the correct behavior for this file should be. Apparently is does not re-initialize when a new Firefox session is initiated.
    Please feel free to contact me if more information is desired. I'm not sure what details you might need to troubleshoot this type of problem.

    Hi Katy, and a warm welcome to the forums!
    What is the exact name of the file?
    Is it aim.bin?
    Which requires either Stuffit Expander, or the Unarchiver to deflate.
    http://www.apple.com/downloads/macosx/systemdiskutilities/theunarchiver.html

  • How can I create a working link from the home page to other pages?

    Using iWeb, I created links on the Home page directed to other pages within my web site. The links are located in the main body of the Home page (on the right side) and are not included in the Navigation Menu. The links function correctly when I test them in iWeb, however, the links do not function at all after publishing to the internet.
    Within the inspector, I have chosen, Link To: "One of my pages" and the appropriate page is selected.
    The links within the gray rectangles do not function. The same links below the gray rectangle links go to a "Page Not Found" page.
    See the home page at http://www.daleenstrom.com
    How can I make these links function correctly?

    Welcome to the Apple Discussions. I've found that using the "One of my pages" often doesn't work. Since you've published the site go to each page, copy its URL and use it for the hyperlink. I've found that to me more reliable.
    Are those two links inside the shapes or just on top? Both of those items are one large image file. If you inserted the link in the shape be sure you've selected the text (might take a few clicks to get inside and select it) to use for the hyperlink. Also make sure there are no other objects overlapping each of the shaped with the hyperlinked text.
    Also it appears that the entire text box is an image. Turn on iWeb's preferences to display the text image indicator:
    Click to view full size
    and then you'll see the following on any object that will be converted to text once published:
    Click to view full size
    The two links below work for me. Be sure to clear your browsers cache (CommandOptionE for Safari) and reload the page.
    OT

  • Output File from the Saudi Payment Output File

    Dear All ,
    I want to ask where did oracle save or store the output file after I ran the request Saudi Payment Output File.
    I need to see the file , to send it for the Bank.
    best Regards.

    Pl post details of OS, database and EBS versions. Did the concurrent program complete without errors ? Pl post the contents of the concurrent log file.
    Pl also see MOS Doc 553518.1 (What is the Extension of Saudi Payment output file ? And where it is exist ?).
    HTH
    Srini

  • How to read .xml file from embedded .swf(flash output) in captivate

    I have been trying to read .xml file from the .swf (Flash output) that is embedded within the captivate file but no luck yet . Please if anyone got any clue on how get this thing done using Action script 3.0 then let me know. I am using Adobe Captivate 5.5 at present and Flash CS 5.5.
    I am well aware about how to read .xml file through action script 3.0 in flash but when insert the same flash in captivate and publish nothing comes in captivate output. I would higly appreciate if anyone could help me out with that.
    Here is is graphical demonstration of my query :
    Message was edited by: captainmkv

    Hi Captainmkv,
    Does the information in this post cover what you're trying to do: http://forums.adobe.com/message/5081928#5081928
    Tristan,

  • Security Issue: How to create a derived role from the Base role

    Hi All,
    Kindly let me know how can i create a derived role from the base role?
    Please respond at the earliest.
    Thanks in advance.
    Ramesh.

    Go to PFCG and Create a role with desired Name.
    In the Description Tab, on the Left Side there is a text box for "Derive From "
    enter the Base role.
    Now your newly created role is derived from the Base role.
    Save the newly created role and again run PFCG, enter the Base role name and execute.Select Edit role. Go to Authorization tab.
    Edit Authorization.
    In the Menu Adjust Derived -> Generate and Adjust derive
    This will Generate the derived role.
    Now you may go and check the authorization in the derived role.

  • How to export the XFDF file from the PDF?

    I need to export as XFDF file from the PDF and then save that xfdf file in the same location through javascript. I used this.exportAsXFDF(); for exporting. But i dont know how to save that xfdf file through scripting. Kindly advice me. This is for Acrobat 8.0 professional and windows platform.

    There are couple of security restrictions you will have to deal with.
    You need to use a trusted function as outlined in the Acrobat JavaScript API Reference, freely down loadable form the Developer community on Adobe's site.
    See the following articles by Thom Parker:
    File paths in Acrobat JavaScript
    How to save a PDF with Acrobat JavaScript

  • How do you remove files from your start up disk without deleting any files?, How do you remove files from your start up disk without deleting any files?

    Hi,
    I was wondering if anyone knew how to remove files from the start up disk without deleting any files?
    I am unable to add any more photos and even download the latest updates because the start up disk is full....
    Is it possible to move the files off the start up disk without deleting them?
    I would appreciate feedback,
    Thanks
    Sammy

    Well you can move them to an external drive but this will delete them from the internal drive. Which is what you have to do to free up disk space.

  • Can't create multiple dependent LOVs from the same bind variable

    Hi all,
    I'm having difficulty creating multiple dependent LOVs from queries based on the same bind variable in my JSF application (JDev 10.1.3.1). Basically I have a static LOV in a af:selectOneChoice component from which users select a value which then becomes the bind variable value for two separate queries that generate two different dependent LOV. Having developed the code along the lines of Steve Muench 's blog (http://radio.weblogs.com/0118231/2006/04/03.html#a685), the first dependent LOV works really well. The first dynamic LOV gets refreshed whenever the list from the static LOV changes, and I can execute other queries based on the values selected.
    The problem arises when I want to create the second dynamic/dependent LOV that has the same bind variable based on the same selected value from the static LOV. Here I would also like the functionality whereby the second dynamic LOV is also refreshed after the selected value in the static LOV changes. Thinking that all I had to do was replicate the methodology used in creating the first dependent LOV, I created the second iterator, invokeAction and other binding components in the PageDef. The executable section now looks like the following:
    <iterator id="SelectStaticQueryViewObjIterator"
                  Binds="SelectStaticQueryViewObj" RangeSize="-1"
                  DataControl="DMSApplicationModule1DataControl"/>
    <invokeAction id="refreshDynamicQuery1BindParameter"
                  Binds="ExecuteWithParams1" Refresh="prepareModel"
                  RefreshCondition="#{empty requestScope.VariableChanged}"/>
    <iterator id="SelectDynamicQuery1ViewObjIterator"
                  Binds="SelectDynamicQuery1ViewObj" RangeSize="-1"
                  DataControl="DMSApplicationModule1DataControl"/>
    <invokeAction id="refreshDynamicQuery2BindParameter"
                  Binds="ExecuteWithParams2" Refresh="prepareModel"
                  RefreshCondition="#{empty requestScope.VariableChanged}"/>
    <iterator id="SelectDynamicQuery2ViewObjIterator"
                  Binds="SelectDynamicQuery2ViewObj" RangeSize="-1"
                  DataControl="DMSApplicationModule1DataControl"/>I now have a problem whereby everytime I change the value of the static LOV, multiple HTML components for the same ADF component are being generated (the LOVs are refreshed via PPR). The surprising thing is that this duplicating behaviour applies to all ADF components listed after the first dynamic LOV in the *.jspx source. For example, I have a <af:outputText="Test Text"/> component created after the first dynamic LOV. Each time the value in the static LOV changes, a duplicate HTML component is created. This also applies to the 'related' second dynamic LOV which is bound to a af:selectOneChoice component - multiple dropdown lists are created. I've checked with the browser's Page Source and there are actually multiple html components being generated with their own unique ADF-generated IDs. I've tried all different options for the Referesh and RefreshCondition attibutes in the second invokeAction element but nothing seems to eliminate this issue.
    Any suggestions about how I might create multiple dependent LOVs from the same bind variable that get refreshed when the selected value changes would be greatly appreciated.
    Thanks
    George

    Hi all,
    Just updating the thread on how I've overcome this issue. As it stood the manner in which I was trying to solve my use case, as described above, was creating an absolute mess. Then with a blank sheet of paper I quickly realised that a much simpler solution would be to create a whole series of master-detail VOs and build my components around them. Thankfully I haven't had any issues going down this path as yet.
    Cheers
    George

Maybe you are looking for

  • How to I get iCal to open on login (not just startup but also open a new window)

    I have added iCal to the startup on login in user preferences but it only starts the program, what I am trying to achieve is it startup and open a new window for me to review my daily calendar as soon as I login to my computer.

  • Processor removal help: G5 liquid cooled

    I am looking for some help on removing the heat sync/ processor on a dual 2.5 with the liquid cooled unit. The 8 CPU Heatsink Allen screws 2.5 mm. that sit in the "Lagshields" are loosened, but the CPU unit still is being held down by more fasteners?

  • MacBook Startup Chime Repeating

    Hi, I have a late a late 2009 Macbook and im having a problem with the startup chime repeating and its starting to get rather annoying. It usually just gets to the point where i get sick of listening to it and just hold down the power button to resta

  • While statements

    Hi All. I am a student in java programming, beginning class. I am having problems with understanding how to make a loop body work properly using a while statement. I have a problem I am working on, and I can't seem to get it to run properly, and I be

  • TOPN and rest as Others.

    Hi All, We are creating a report in which we are using 1 measure "# of Service Requests" and "Customer" dimesnion. Suppose if we have 10 Customers , we want a report where Customers are in X axis and "# of Service Requests" in Y axis. Where in X axis