How to edit the existing data in the XML file from java programming.

Hi all
i am able to create XML file with the sample data as below from java programming.
i need sample code on how to edit the existing data in the XML file?
for example
<?xml version="1.0"?>
   <mydata>
           <data1>
                     <key1>467</key1>
                    <name1>Paul</name1>
                    <id1>123</id1>
          </data1>
          <data2>
                     <key2>467</key2>
                    <name2>Paul</name2>
                    <id2>123</id2>
          </data2>
    </mydata>
i am able to insert the data in the XML.
now i need sample code on how to modify the data in the above XML file from the java programming for only key2,name2,id2 tags only. the remaining tags data in the XML file i want to keep same data except for key2,name2,id2 which are i want to modify from java code
Regards
Sunil
[points will be always rewardable]

hi
u need a parser or validate the xml file for to read the xml file from java coding u need for this
xml4j.jar u can download this file  from here
http://www.alphaworks.ibm.com/tech/xml4j
or we can use the SAX(simple API for XML)
some sample applications for this
http://www.java-tips.org/java-se-tips/javax.xml.parsers/how-to-read-xml-file-in-java.html
http://www.developertutorials.com/tutorials/java/read-xml-file-in-java-050611/page1.html
http://www.xml-training-guide.com/e-xml44.html
let me know u need any other info
bvr

Similar Messages

  • What the best way to create XML files from JAVA application?

    Hi to all,
    I need to edit and to create new filex in format of xml. I know to parse, but what would be the best way to do:
    1. - Create new file, create like simle text file, or there is some clases that know to do it in more simple way
    2.a - Edit XML file, to take some data and add it to the XML in the place I want to.
    2.b - Also Edit, but not to add fields, just update some of them.
    Code examples or links to samples woul be welcomed.
    Best regards, Nick.

    I have tried working with XML directly using the Java classes but this was a pain. I then looked at DOM4J and JDOM and found JDOM easier to use.

  • How to Enter the existing data  in the entity beans?

    hello
    my problem is as follows--
    i am creating a CMP entity bean.in these beans client create the data instances using create() function.
    now a entity bean will be created for the newly created data and it's EJBObject will also be formed.
    now we will be able to perform finder methods over them.
    remember these data has been newly created in the database.
    but now if i want to perform the finder methods on the
    existing data in the database( i don't need to use create() fn as i am not "creating" the data.). how will i perform the query over the existing data.
    basically i have to make a CMP bean to extract the data corresponding to a particular condition , from the database table. i don't want to create the data in the database but just find out what data satisfies my condition.
    thanking you
    Prashant

    All I say here is based on limited knowledge on 1.1 ejb specification. There could be improvements on 2.0 spec. 1.1 specification does not formaly provide how the finders should work for container managed beans. It leaves it at the hand of bean providers. Currently bean providers describes the finers in a description of the Entity Bean. Refer to documentation accompanied with application server you are using.
    I attach the famous bank account example in weblogic server.
    <finder-list>
    <finder>
    <method-name>findBigAccounts</method-name>
    <method-params>
    <method-param>double</method-param>
    </method-params>
    <finder-query><![CDATA[(> balance $0)]]></finder-query>
    </finder>
    </finder-list>
    Method definition in Home inteface is
    public Enumeration findBigAccounts(double balanceGreaterThan)
    throws FinderException, RemoteException;

  • How to export a data as an XML file from oracle data base?

    could u pls tell me the step by step procedure for following questions...? how to export a data as an XML file from oracle data base? is it possible? plz tell me itz urgent requirement...
    Thankz in advance
    Bala

    SQL> SELECT * FROM v$version;
    BANNER
    Oracle DATABASE 11g Enterprise Edition Release 11.1.0.6.0 - Production
    PL/SQL Release 11.1.0.6.0 - Production
    CORE    11.1.0.6.0      Production
    TNS FOR 32-bit Windows: Version 11.1.0.6.0 - Production
    NLSRTL Version 11.1.0.6.0 - Production
    5 rows selected.
    SQL> CREATE OR REPLACE directory utldata AS 'C:\temp';
    Directory created.
    SQL> declare                                                                                                               
      2    doc  DBMS_XMLDOM.DOMDocument;                                                                                       
      3    xdata  XMLTYPE;                                                                                                     
      4                                                                                                                        
      5    CURSOR xmlcur IS                                                                                                    
      6    SELECT xmlelement("Employee",XMLAttributes('http://www.w3.org/2001/XMLSchema' AS "xmlns:xsi",                       
      7                                  'http://www.oracle.com/Employee.xsd' AS "xsi:nonamespaceSchemaLocation")              
      8                              ,xmlelement("EmployeeNumber",e.empno)                                                     
      9                              ,xmlelement("EmployeeName",e.ename)                                                       
    10                              ,xmlelement("Department",xmlelement("DepartmentName",d.dname)                             
    11                                                      ,xmlelement("Location",d.loc)                                     
    12                                         )                                                                              
    13                   )                                                                                                    
    14     FROM   emp e                                                                                                       
    15     ,      dept d                                                                                                      
    16     WHERE  e.DEPTNO=d.DEPTNO;                                                                                          
    17                                                                                                                        
    18  begin                                                                                                                 
    19    OPEN xmlcur;                                                                                                        
    20    FETCH xmlcur INTO xdata;                                                                                            
    21    CLOSE xmlcur;                                                                                                       
    22    doc := DBMS_XMLDOM.NewDOMDocument(xdata);                                                                           
    23    DBMS_XMLDOM.WRITETOFILE(doc, 'UTLDATA/marco.xml');                                                                  
    24  end;                                                                                                                  
    25  /                                                                                                                      
    PL/SQL procedure successfully completed.
    .

  • How to modify an existing xml file from java code.

    Hi
    I have worked on creating a new xml file from java code using xmlbeans.But if i try to modify an already existing file using java code I am unable to get errorfree xmlfile.
    For example if xml file(studlist.xml) is as below:
    <?xml version="1.0" encoding="UTF-8"?>
    <StudentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="D:\kchaitanya\xmlprac1\abc\Studlist.xsd">
         <Student>
              <Name>ram</Name>
              <Age>27</Age>
         </Student>
    <Student>
              <Name>sham</Name>
              <Age>26</Age>
         </Student>
    </StudentList>
    Now suppose i have set name to victor using student.setName,
    and set age to 20 using setAge from javacode,
    the new xml file is as follows:
    <?xml version="1.0" encoding="UTF-8"?>
    <StudentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="D:\kchaitanya\xmlprac1\abc\Studlist.xsd">
         <Student>
              <Name>ram</Name>
              <Age>27</Age>
         </Student>
    <Student>
              <Name>sham</Name>
              <Age>26</Age>
         </Student>
    </StudentList>
    <Student>
              <Name>victor</Name>
              <Age>20</Age>
         </Student>
    As observed this is not a valid xml file.But how can i modify without any errors?

    I know it's an old post, but I found this while doing a google search for something else, and don't like to leave it un-aswered
    Just in case anyone has a similar problem... In this case the new elements have been appended outside of the root element
    What you need to do is first get the root element and then append the new children to that, there are several ways of getting the root element, which depend on what you want to do with the elements you get back here's a simple (incomplete) way.
    // gets the root element of the specified file (code not shown)
    Element rootElement= new SAXReader().read(file).getRootElement();Then just append the new elements as below (this is non-generic code and would need to be modified for your situation)
    // write a new student element
    Element student = document.createElement("Student");  // creates the new student
    rootElement.appendChild(student); // ***appends it to the root element***
    Element name = document.createElement("Name"); // creates the name element
    name.appendChild(document.createTextNode("Fred")); // adds the name text to the name element
    student.appendChild(name); // appends the name to the student
    Element age= document.createElement("Age"); // creates the age element
    age.appendChild(document.createTextNode("26")); // adds the age text to the age element
    student.appendChild(age); // appends the name to the studentThen flush ya buffers or whatever and write the file
    Edited by: Dream-Scourge on Apr 23, 2008 11:10 AM

  • How I can create a XML file from java Aplication

    How I can create a XML file from java Aplication
    whith have a the following structure
    <users>
    <user>
    <login>anyName</login>     
    <password>xxxx</password>
    </user>
    </users>
    the password label must be encripted
    accept any suggestion

    Let us assume you have all the data from the jsp form in an java bean object..
    Now you want a xml file. This can be acheived in 2 ways
    1. Write it into a file using java.io classes. Say you have a class with name
    write("<name>"+obj.getName+</name>);
    bingo you have a flat file with the xml
    2. Use data binding to do the trick
    will recommend JiBx and Castor for the 2nd option
    Regards,
    Rajagopal

  • How many softwares are there to create a setup file for java programs

    Hi, i am new to java
    I want to know how many softwares are there to create a setup file for java programs.
    I know one software i.e java launcher to create a setup file.
    I want to know about any other softwares are available to create a setup file for java programs.
    I created a setup file for swings program in JCreator.
    And don't think that i am wastiing ur time with this question .
    Help me regarding this topic.
    Thanks in Advance

    superstar wrote:
    I want to know how many softwares are there to create a setup file for java programs.13, no wait, 42.
    I know one software i.e java launcher to create a setup file.You should clearly identify what you think you already know.
    I want to know about any other softwares are available to create a setup file for java programs.
    I created a setup file for swings program in JCreator.Is this the one you talked before, or is this different?
    And don't think that i am wasting ur time with this question .Why should I not think that?

  • How to Call .XDO file From Java Program

    Hi,
    I have developed a report in using BI Publisher version 10.1.3.
    I created the report and it only created XDO files. If I want to call XDO file from Java program how I can do that.
    What are the APIs available to do that.
    Thanks
    -Ashutosh

    Hi,
    the JavaAPI didn't work with the xdo-Files. But you can create a proxy stub for the Web Service API of BI Publisher which uses the xdo's in the repository.
    regards
    Rainer

  • The nicest way to generate xml-files by Java???

    I have to generate huge and quite complex xml files by Java. I have to fetch the data from a Oracle database. What I really don't know is a proper and reliable way to this? I could of course create a String and concatenate all the tags, attributes and data but it doesn't feel right. I guess this is a quite common task and there are many established ways to this by Java. My question is what is the best way to this? What is your suggestion?
    Thank you for any clues...

    Hi,
    Since you have access to the database, I think one of the best way is to create stored procedures that will generate those files for you (using SQL/XML functions preferably) and return the content to the Java caller.

  • How to Generate XML File from Java Code.

    I want to generate the xml file from the java code.
    Could you plz suggest any webSite address with example?

    Here is the code
    import java.io.File;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.FactoryConfigurationError;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerConfigurationException;
    import javax.xml.transform.TransformerException;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    public class CreateXML {
         private DocumentBuilderFactory factory = null;
         private DocumentBuilder builder = null;
         private Document document = null;
         public CreateXML() {
              try {
                   factory = DocumentBuilderFactory.newInstance();
                   builder = factory.newDocumentBuilder();
                   document = builder.newDocument();
              } catch (FactoryConfigurationError e) {
                   e.printStackTrace();
              } catch (ParserConfigurationException e) {
                   e.printStackTrace();
         /** Creates the document for xml. */
         public Document createDocument(){
              try{               
                   Element root = document.createElement("Root");
                   Element child = document.createElement("child");
                   root.appendChild(child);
                   document.appendChild(root);
              }catch(RuntimeException e){
                   e.printStackTrace();
              return document;
         /** Saves the document as xml. */
         public void saveDocument(Document document){
              try{
                   TransformerFactory transFactory = TransformerFactory.newInstance();
                   Transformer transformer = transFactory.newTransformer();
                   DOMSource source = new DOMSource(document);
                   StreamResult stream = new StreamResult(new File("sample.xml"));
                   transformer.transform(source, stream);
                   System.out.println("XML Created !!");
              }catch(TransformerConfigurationException e){
                   e.printStackTrace();
              } catch (TransformerException e) {
                   e.printStackTrace();
         public static void main(String args[]){
              CreateXML createXML = new CreateXML();
              Document document = createXML.createDocument();
              createXML.saveDocument(document);
    }

  • How to read XML files from java

    i need a sugession that how to read a xml file using java code
    and i need to parse using some parsers and display attributes and entity seperately
    as a string.......

    import org.dom4j.Document;
    import org.dom4j.DocumentException;
    import org.dom4j.io.SAXReader;
    import java.io.File;
    import java.text.AttributedCharacterIterator.Attribute;
    import java.util.Iterator;
    import java.util.StringTokenizer;
    public class XmlParser
    private String Result="";
    private String Final="";
    private String Delim="";
    public void bar1(Document document) throws DocumentException
    org.dom4j.Element root = document.getRootElement();
    // System.out.println(root.getName());
    bar2(root);
    System.out.println(this.Result);
    process();
    public void bar2(org.dom4j.Element e)
    for(Iterator i = e.elementIterator();i.hasNext();)
    org.dom4j.Element Element = (org.dom4j.Element) i.next();
    Result += Element.getName()+"\t"+Element.getText()+"\n";
    bar2(Element);
    public void process()
    StringTokenizer Tokenizer = new StringTokenizer(this.Result,"\n");
    String element;
    while(Tokenizer.hasMoreTokens())
    element = Tokenizer.nextToken();
    StringTokenizer Tokenizer2 = new StringTokenizer(element,"\t");
    // Do what ever String Process here Example
    this.Final += element.getName();
    this.Final += this.Delim;
    System.out.println(this.Final);
    public static void main(String s[])throws Exception
    Document document = null;
    SAXReader reader = new SAXReader();
    File f1= new File("D:/Rajesh/EDI to XML/EDI.xml");
    document = reader.read(f1);
    Demo obj = new Demo();
    obj.bar1(document);
    i think this will hep full.......

  • Best Practices for Accessing the Configuration data Modelled as XML File in

    Hi,
    I refer the couple of blof posts/Forum threads on How to model and access the Configuration data as XML inside OSB.
    One of the easiest and way is to
    Re: OSB: What is best practice for reading configuration information
    Another could be
    Uploading XML data as .xq file (Creating .xq file copy paste all the Configuration as XML )
    I need expert answers for following.
    1] I have .xsd file which is representing the Configuration data. Structure of XSD is
    <FrameworkConfig>
    <Config type="common" key="someKey">proprtyvalue</Config>
    <FrameworkConfig>
    2] As my project will move from one env to another the property-value will change according to the Environment...
    For Dev:
    <FrameworkConfig>
    <Config type="common" key="someKey">proprtyvalue_Dev</Config>
    <FrameworkConfig>
    For Stage :
    <FrameworkConfig>
    <Config type="common" key="someKey">proprtyvalue_Stage</Config>
    <FrameworkConfig>
    3] Let say I create the following Folder structure to store the Configuration file specific for dev/stage/prod instance
    OSB Project Folder
    |
    |---Dev
    |
    |--Dev_Config_file.xml
    |
    |---Stage
    |
    |--Stahe_Config_file.xml
    |
    |---Prod
    |
    |-Prod_Config_file.xml
    4] I need a way to load these property file as xml element/variable inside OSb message flow.?? I can't use XPath function fn:doc("URL") coz I don't know exact path of XMl on deployed server.
    5] Also I need to lookup/model the value which will specify the current server type(Dev/Stage/prod) on which OSB MF is running. Let say any construct which will act as a Global configuration and can be acccessible inside the OSb message flow. If I get the vaalue for the Global variable as Dev means I will load the xml config file under the Dev Directory @runtime containing key value pair for Dev environment.
    6] This Re: OSB: What is best practice for reading configuration information
    suggest the designing of the web application which will serve the xml file over the http protocol and getting the contents into variable (which in turn can be used in OSB message flow). Can we address this problem without creating the extra Project and adding the Dependencies? I read configuration file approach too..but the sample configuration file doesn't show entry of .xml file as resources
    Hope I am clear...I really appreciate your comments and suggestion..
    Sushil
    Edited by: Sushil Deshpande on Jan 24, 2011 10:56 AM

    If you can enforce some sort of naming convention for the transport endpoint for this proxy service across the environments, where the environment name is part of the endpoint you may able to retrieve it from $inbound in the message pipeline.
    eg. http://osb_host/service/prod/service1 ==> Prod and http://osb_host/service/prod/service2 ==> stage , then i think $inbound/ctx:transport/ctx:uri can give you /service/prod/service1 or /service/stage/service1 and applying appropriate xpath functions you will be able to extract the environment name.
    Chk this link for details on $inbound/ctx:transport : http://download.oracle.com/docs/cd/E13159_01/osb/docs10gr3/userguide/context.html#wp1080822

  • Where is the UME data source configuration XML file stored on the server?

    I'm trying to activate windows integrated authentication in my portal server.  The java engine's UME configuration has been loaded as a deep AD read only database using the file "dataSourceConfiguration_ads_deep_readonly_db.xml" but I can't find this on my server.  I need to modify a couple of parameters in there to activate kerberos principal management.  My recent portal training course offered me a completed working example but it was for an ads_flat_writeable_db so I can't simply load that and I need to understand the changes required.
    Where to I find the configuration file on my java instance server so I can make the necessary changes to a copy and upload that?

    Try to read
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/e1959b90-0201-0010-849c-d2b1d574768b
    UME user data is stored in one or more data sources. Each type of data source has its own persistence adapter. The persistence manager consults the persistence adapters when creating, reading, writing, and searching user management data. Persistence adapters for the following types of repositories are available: 1. Database: See the Product Availability Matrix on SAP Service Marketplace (http://service.sap.com/pam60) for details on which databases are supported. 2. u2022 Lightweight Directory Access Protocol (LDAP) directory: See the Product Availability Matrix on SAP Service Marketplace (http://service.sap.com/pam60) for details on which directories are supported. 3. SAP Systems based on Web Application Server 6.20 You can configure UME to use one or more of these persistence devices in parallel. Users can also be stored in several different physical LDAP directory servers, or in different branches of the same LDAP directory server.

  • How to edit/modify a line of a text file using java io

    Hi every body
    I am new 2 java
    I am struck in editing a text file that ends with .dat
    I successfully added,viewed data of the *.dat file.
    but,I cannt edit,delete the lines that i need to do randomly.
    Here is the code i have written.
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.DataInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.LineNumberReader;
    import java.io.RandomAccessFile;
    import java.util.ArrayList;
    import java.util.StringTokenizer;
    public class ReadWriteFile {
         String id=null;
         String name=null;
         String dept=null;
         String doj=null;
         String adrss=null;
         public void WriteFile(String Id,String Name,String Dept,String Doj,String Adrss) throws IOException{
              File f=new File("TraineeDetails.dat");
             if(!f.exists()){
             f.createNewFile();
              BufferedWriter bw=new BufferedWriter(new FileWriter("TraineeDetails.dat",true));
              BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
              System.out.print("Enter Id : ");
              Id=br.readLine();
              System.out.print("Enter name : ");
              Name=br.readLine();
              System.out.print("Enter dept : ");
              Dept=br.readLine();
              System.out.print("Enter doj : ");
              Doj=br.readLine();
              System.out.print("Enter adrss : ");
              Adrss=br.readLine();
              bw.write(Id+"::"+Name+"::"+Dept+"::"+Doj+"::"+Adrss+":END:");
              bw.flush();
              bw.newLine();
              bw.close();
         public static void main(String[] args) throws IOException {
              ReadWriteFile rwf=new ReadWriteFile();
              String TID = null;
              String TADRSS = null;
              String TDOJ = null;
              String TNAME = null;
              String TDEPT = null;
              rwf.ReadFile(TID,TNAME,TDEPT,TDOJ,TADRSS);
         public void ReadFile(String Id1,String Name1,String Dept1,String Doj1,String Adrss1) throws IOException{
              BufferedReader br = new BufferedReader(new FileReader("TraineeDetails.dat"));
              String s;
               while((s = br.readLine())!= null)
                 // Create string tokenizer
                    StringTokenizer st =new StringTokenizer(s, "::");
                      System.out.println("----------------------------------------------");
                      System.out.println("| Trainee Id: "+st.nextToken()             +"|");
                      System.out.println("| Trainee Name: "+st.nextToken()           +"|");
                      System.out.println("| Trainee Department:"+st.nextToken()      +"|");
                      System.out.println("| Date of Joining: "+st.nextToken()        +"|");
                      System.out.println("| Trainee Address: "+st.nextToken()        +"|\n");
                      System.out.println("----------------------------------------------");
               // Close file reader
               br.close();
    }     and here is the data i have written
    Trainee.dat*
    111::jain::roads::2-2008::Blore:END:
    123::tim::service::1-2000::delhi:END:
    444::faru::civil::3-2200::sanapur:END:
    555::niv::cse::10-2000::gnagar:END:
    999::linda::mech::6-2001::tnagar:END:
    258::yansi::geo::8-2002::rtnagar:END:
    656::hari::garrage::3-1000::uttarahalli:END:
    888::muni::hr::5-2009::ernakulam:END:
    007::bond::spy::2-1972::america:END:
    0123::landy::games::6-2003::hdp:END:
    678::maddy::pumbing::4-1999::dispur:END:

    kalanidhi2u wrote:
    I want to randomly access the file
    But i cannt access itmake it RandomAccessFile... RandomAccessFile
    I edited it
    but i cannt edit the file by using itBoth of these are contradictory.

  • How to check image GPS data and get image file from image field

    Hello,
    I have some trouble and want to fix this problem.
    1. I want to validate image file before its attached in image field about the image file have a GPS data or not. Have any way that can be check about image has contained a GPS data?
    2. After validate image and PDF form is upload to the server. I want to get image file that embed in image field, because I have to extract image from PDF form and store this image in project image folder. If this topic can be fix by code script please give me some example code.
    Thakyou for every comment and suggestion
    Best Regards,
    Mai

    Hi Naill,
    First I have to say thankyou for your answer.
    About my (1) question, My image fields have set to be a embedded data and I try to test many example script of image fields.I can get image content type, image size. But that not work when I used ImageField1.desc.embeddedHref.value. It's response as "Unknown Embedded URI". Therefore, image field is and embedded data. How can I access filename?
    (2) In that forum. As I see, his problem is about how to automate change image field with href image file. But I want to extract an exist embedded image in PDF form to normal image file with original metada (such as extract image filed to .JPEG with GPS data. Same as before attached in PDF form.). There has any concept or solution in this problem?
    Best Regards,
    Mai

Maybe you are looking for

  • Down payment process - merge for FI

    Hi everyone, I have recently setup the downpayment process in SD (ECC 6.0). It works fine but I have question regarding the SD/FI integration. I'm creating a sales order for about more than one item, e.g. 10 items. Then we create the down payment req

  • How I reset Mac Mail to default?

    I've tried going into Library and deleting the Mail folder and com.apple.mail.plist, It's not working, all sorts of things are wrong with the Mail App, I only got this Mac a month ago... I'm using IMAP, nothing is wrong with the server, I asked my ho

  • Trouble burning CDs.

    iTunes burns and plays the disc fine. But the disc won't play in a standard CD player. Starts out ok, then cuts in and out then nothing. I've tried different brands of discs. I have a 2008 MacBook. Never had issues till now.

  • Desktop cannot be changed

    My Computer ist working well, harddisk seems to be o.k., All other users have no problems But my admin account makes problems, desktop cannnot be changed, It's not possible to create new folders. Folders/Icons can't be moved to annother place, Files

  • Has anyone had a battery changed in 4th gen?

    Has anyone had a battery changed in 4th gen? Does it require apple to do it?