How to change value of element and update XML file

Hi
I have an xml file called test.xml like below
<?xml version="1.0" encoding="UTF-8"?>
<printing>
     <userName/>
     <viewName/>
</printing>I want to change value of user name and view name and update test.xml file in my folder
Anyone has sample code to do so
Ashish

Thanx
i was able to do so, but what i want now is to remove element
for example
i have following xml
<?xml version="1.0" encoding="UTF-8"?>
<printing>
<firstLineTexts>
          <firstLineText />
          <firstLineText>|line11</firstLineText>
          <firstLineText>|line12</firstLineText>
</firstLineTexts>
</printing>how do i remove all elements fireLineText
my final output should be
<?xml version="1.0" encoding="UTF-8"?>
<printing>
<firstLineTexts>
</firstLineTexts>
</printing>How do i do it using DOM,
I can create instance of DOM and write it using TransformerFactory
Ashish

Similar Messages

  • How to update/change the value of elements in an xml file?

    Hi Everyone,
    Could any one of u tell me how to update the value of elements in an XML file, using java? The reason is i want to use an XML file as a data source (i.e. more or less like a database), without using any RDBMS, for simple applications such as to read a record and update the record. By the way, my XML file will have only one record, such as the current weather information, with fields such as temperature, humdity etc. for 1 city only.
    Thanks in advance.

    Here is a solution how to check a particular value or element name in an xml and update the changes e to an xml.
    Sample.xml
    <URLConstructor>
    <application name="cp_outage">
    <resource>hello</resource>
    <value>val</value>
    </application>
    <application name="cp_outage">
    <resource>hello</resource>
    <value>val</value>
    </application>
    </URLConstructor>
    XMLWriter.java
    package com;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.JDOMException;
    import org.jdom.input.DOMBuilder;
    import org.jdom.output.XMLOutputter;
    // used for printing
    import org.apache.xml.serialize.XMLSerializer;
    import org.jdom.output.XMLOutputter;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    import java.util.Iterator;
    import java.util.List;
    class XMLWriter{
    public void update(File fileName)
    try {
              DOMBuilder domBuilder=new DOMBuilder();
              Document doc=domBuilder.build(fileName);
              Element element=doc.getRootElement();
              getChildren(element);
              writeToXML(doc,fileName);
              getChildren(element);
    } catch (Exception e) {
    e.printStackTrace();
         * @param doc
         private void writeToXML(Document document,File filePath)
                   XMLOutputter xmloutputter = new XMLOutputter();
                        try
                             FileOutputStream fileOutputStream = new FileOutputStream(filePath);
                             xmloutputter.output(document, fileOutputStream);
                             fileOutputStream.close();
                        catch (FileNotFoundException e)
                             e.printStackTrace();
                        catch (IOException e)
                             e.printStackTrace();
         public void getChildren(Element element)
                        if(!element.hasChildren())
                             return;
                        List childrenList = element.getChildren();
                        Iterator itr=childrenList.iterator();
                        while(itr.hasNext())
                             Element childElement=(Element) itr.next();
                             if(childElement.hasChildren())
                                       getChildren(childElement);
    //                                   System.out.println("Name "+childElement.getName());
    //                                   System.out.println("Value "+childElement.getText());
                                       if(childElement.getText().equals("hello") || (childElement.getName().equals("resource")))
                                            updateInfo(childElement,"New_Resource","AddedText");
         * @param childElement
         * @param string
         * @param string2
         private void updateInfo(Element element, String elementName, String value)
              element.setName(elementName);
              element.setText(value);          
    static public void main(String[] args)
    XMLWriter xmlWriter=new XMLWriter();
    xmlWriter.update(new File("c:/sample.xml"));
    After execution the file will be changed to
    <URLConstructor>
    <application name="cp_outage">
    <New_Resource>AddedText</New_Resource>
    <value>val</value>
    </application>
    <application name="cp_outage">
    <New_Resource>AddedText</New_Resource>
    <value>val</value>
    </application>
    </URLConstructor>
    Regards,
    Maheswar

  • How to change \Adobe\Premiere Elements\12.0\Encoded Files location to another drive?

    Hello. I am using Premiere Elements 12. I am not able to burn blueray disk because I have insufficient disk space. I am using SSD drive so I need to move Adobe\Premiere Elements\12.0\Encoded Files location to another drive. How can I do this?

    tolppa
    What computer operating system is your Premiere Elements 12/12.1 running on? For now, assuming Windows 7, 8, or 8.1 64 bit....
    In the Premiere Elements 12/12.1 Expert workspace, go to Edit Menu/Preferences/Scratch Disc and set the location for the category
    named Disc Encoding.
    Please let us know if that works for you.
    Thank you.
    ATR

  • Writing and updating XML file on client side

    Hello,
    I'm looking for a simple example which permit to write and
    update a xml file on the client side.
    Someone can help me, please?

    meghashyamgr ,
    Because of security reasons a swf running in a browser cannot
    read or write xml files to a user's computer. What can be done,
    however, is write xml to what is known as a SharedObject.
    SharedObjects act as cookies for Flashplayer.
    If you would like an example of this I'd be more than happy
    to show you...

  • How to change(extend) VO appearing in a  xml file

    hi all
    in a page of irecruitment module ,we have a heperlink ,after clicking on this link a xml file gets open ,it is showing attributes of a VO (OfferLetterDetailsVO) we have to add some extra attributes in this VO,so at the first instance i just extended the VO but it is not working out ,after that going against the oracle standard i made the changes in standard VO itself ,but it is also not working ,now i dont know the other approach ,can somebody please suggest whould should be done
    the xml details are given below
    <OfferLetterDetailsVO>
    <OfferLetterDetailsVORow>
    <PersonId>5956</PersonId>
    <PersonEffectiveStartDate>2004-10-29</PersonEffectiveStartDate>
    <PersonEffectiveEndDate>4712-12-31</PersonEffectiveEndDate>
    <VacancyId>5583</VacancyId>
    <AddressId null="true"/>
    <JobId>144</JobId>
    <PayBasisId null="true"/>
    <PayProposalId null="true"/>
    <VendorId null="true"/>
    <OfferId>940</OfferId>
    <AssignmentId>12598</AssignmentId>
    <AssignmentEffectiveStartDate>2005-09-26</AssignmentEffectiveStartDate>
    <AssignmentEffectiveEndDate>4712-12-31</AssignmentEffectiveEndDate>
    <PostingContentId>4142</PostingContentId>
    <SexLookupType null="true"/>
    <SexLookupCode null="true"/>
    <MaritalLookupType null="true"/>
    <MaritalLookupCode null="true"/>
    <TitleLookupType null="true"/>
    <TitleLookupCode null="true"/>
    <ApplicantNumber>74</ApplicantNumber>
    <DateOfBirth>1972-12-26</DateOfBirth>
    <EmailAddress>[email protected]</EmailAddress>
    <Title>Mr.</Title>
    <FullName>Banda, Ravi</FullName>
    <FirstName>Ravi</FirstName>
    <Honors>BEng Hons.</Honors>
    <LastName>Banda</LastName>
    <KnownAs>Ravi</KnownAs>
    <MiddleNames null="true"/>
    <OrganizationName>HR Development</OrganizationName>
    <OrganizationId>479</OrganizationId>
    <PositionName>510.SENIOR MANAGER</PositionName>
    <PositionId>424</PositionId>
    <PositionEffectiveStartDate>1985-05-05</PositionEffectiveStartDate>
    <PositionEffectiveEndDate>4712-12-31</PositionEffectiveEndDate>
    <ManagerTitle>Dr.</ManagerTitle>
    <ManagerFullName>Millmore, Martin</ManagerFullName>
    <ManagerEffectiveStartDate null="true"/>
    <ManagerEffectiveEndDate null="true"/>
    <ManagerFirstName>Martin</ManagerFirstName>
    <ManagerLastName>Millmore</ManagerLastName>
    <ManagerHonors null="true"/>
    <ManagerKnownAs null="true"/>
    <ManagerPhone>+44 1189 123456</ManagerPhone>
    <RecruiterTitle null="true"/>
    <RecruiterFullName null="true"/>
    <RecruiterEffectiveStartDate null="true"/>
    <RecruiterEffectiveEndDate null="true"/>
    <RecruiterFirstName>Chris</RecruiterFirstName>
    <RecruiterLastName null="true"/>
    <RecruiterHonors null="true"/>
    <RecruiterKnownAs null="true"/>
    <RecruiterPhone>+1 650 506 4321</RecruiterPhone>
    <RecruiterPersonId null="true"/>
    <LookupType null="true"/>
    <LookupCode null="true"/>
    <ManagerPersonId null="true"/>
    <LookupType1 null="true"/>
    <LookupCode1 null="true"/>
    <SalaryCurrency>USD</SalaryCurrency>
    </OfferLetterDetailsVORow>
    </OfferLetterDetailsVO>
    here after "SalaryCurrency" we want to add extra attributes
    thanx
    Pratap

    Please check the VOImpl.java of the standard View Object. In some places, queries are changed dynamically in the standard code.
    Also check the AMImpl if there is any dynamic change in viewobject query.
    --Prasanna                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to change values in VBAP and VBUP tables?

    All,
    I have a sales order where I need to change the values in 2 fields.
    VBAP-ABGRU  and VBUP-UVP03
    I have found the BAPI_SALESORDER_CHANGE but not sure it will let me change the VBUP field.
    Any suggestions would be nice.
    Thanks.
    Scott

    SEE THIS:
    http://www.sapabapsdmm.com/sap-abap-bapi-programming.htm
    http://abap.wikiprog.com/wiki/BAPI_SALESORDER_CHANGE

  • How to read and write Xml file at client side using JavaScript !

    Hello,
    i am new to javascript.
    I have requirement to read and update XML file at client side.
    Will you please guide what could be the best way to read and update XMl file using javascript.
    Thanks,
    Zuned

    This is a Java forum,not a Javascript forum. Maybe you should ask here [http://www.webdeveloper.com/forum/forumdisplay.php?forumid=3&s|http://www.webdeveloper.com/forum/forumdisplay.php?forumid=3&s].

  • I recently changed my email address and updated my password.  However, when I connect my iPhone 4 it defaults to my old email address which is no longer valid.  How do I get my phone to recognize my updated email address?

    I recently changed my email address and updated my password.  However, when I connect my iPhone 4 it defaults to my old email address which is no longer valid.  How do I get my phone to recognize my updated email address and how do I now change the iPhone 4 to recognize the new address?  I wish to delete all reference to the old address.  All help would be appreciated.

    Hi.
    Here is a procedure that should help.
    1. Go to "Settings"
    2. Go to "Mail, Contacts, Calendars"
    3. Click the account you don't want anymore
    4. Go to the bottom and click "Delete Account"
    5. Confirm the deletion
    6. Go back to "Mail, Contacts, Calendars" (if you're not there already)
    7. Add your new account

  • How to change the screen element to be ineditable in Dynpro POV

    Hi Experts,  any one has experience on how to change the screen element to be ineditable in Dynpro POV?

    Write this piece of code in the PROCESS ON VALUE-REQUEST..
    PROCESS ON VALUE-REQUEST.
    FIELD MARA-MATNR MODULE matnr_mod.
    MODULE matnr_mod input.
    LOOP at Screen.
    if screen-name=<field_name>.
      screen-input = 0.
      modify screen.
    endif.
    ENDLOOP.
    ENDMODULE.
    Thanks
    Venkat.O

  • How to change value of ${eol} from \n to \r\n, writing by File Adapter

    Hi All,
    How to change value of ${eol} from \n to \r\n, while writing file through File Adapter.
    As my file is being created in Linux environment, so for new line separater, \n is used. I mounted this file directory to windows System.
    As Windows requires \r\n for new line seperator. So I need to change value of ${eol} in the Schema created for file writing.
    Can any one provide help regarding this.
    Thanks in advance

    Hi,
    When an XML payload is written to a file \n would be used as the default line separator regardless of if its windows or linux, as per the XML specification http://www.w3.org/TR/REC-xml/#sec-line-ends.
    As such, one need not worry about the line separators because, the XML file would eventually be processed by a parser which usually would be able to understand both line endings (as they are whitespace characters as far as the parser is concerned).
    If you want to convert the line terminators (for readability etc), 10.1.3.4 has a new feature - in the XML schema definition for the file adapter payload, add these two top level directives to the schema element:
    xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd"
    nxsd:normalizeLineTerminators="false"
    Regards,
    Shanmu.

  • How to change to canadian store to update apps

    How to change to canadian store to update apps

    Change to Canadian App Store
    1. Tap "Settings"
    2. Tap "iTunes & App Stores"
    3. Tap on your Apple ID
    4.Tap "View Apple ID"
    5. Enter your user name and password.
    6. Tap "Country/Region."
    7. Tap "Change Country/Region"
    8. Select the country/region where you are located; re-select country/region even if it is correct
    9. Tap "Done".
    Note: If the change doesn't take effect, sign out of account and sign in again.

  • I have a used mac computer. I want to sync and update my iphone. Currently itunes tells me that my iphone is connected to a different itunes account. How do I make itunes sync and update my phone without deleting all the current information on my phone?

    I have a used mac computer. I want to sync and update my iphone. Currently itunes tells me that my iphone is connected to a different itunes account and will sync, but delete everything from my phone. How do I make itunes sync and update my phone without deleting all the current information on my phone?

    Iphone will sync with one and only one cpomptuer at a time.  Syncing to another will erase the current content and replace with content from the new computer.  This is the design of the  iphone.
    It will erase the content when you sync.
    Why not update from the comptuer with which you normally sync?

  • How to change data source name and context root during deployment

    Hi,
    Env:
    WLS 10.1.3
    JDev 11.1.1.6
    Hudson
    I need to deploy two instances of my ADF application on the same development enviroment. We are using Hudson to deploy. My question is how to change data source name and application context root before second deployment.
    Kuba

    I don't believe there is an inbuilt facility to do this.
    Previously how I've done this is when checking files out using Hudson jovs, before the build I then use an Ant extension called XmlTask (http://www.oopsconsultancy.com/software/xmltask/) to modify the required XML files.
    Can I ask why you're doing this in the first place please? Multi-tenancy? 2 versions of the same app?
    CM.

  • How to set value for trim and bleed using jsx script?

    I have tried using bleedoffsetRect but somehow it is not working. Can anybody please help me on how to set value for trim and bleed using jsx script? Any example will be highly appreciated.
    Following is the code I am trying with:
    var _saveName = new File ( root_path +_strFileName+".pdf");
        var _saveOpts = new PDFSaveOptions();
        _saveOpts.printerResolution = 300; 
        var bleedarray = new Array();
         bleedarray[0] =9.00;
         bleedarray[1]=9.00;
         bleedarray[2]=9.00;
         bleedarray[3]=9.00;    
        _saveOpts.bleedOffsetRect = bleedarray;

    I would expect although I've not actually tried this for the bleed off set box to be larger than the artbaord and the first two values to be negative or 0…
    var bleedarray = new Array(-9,-9,artboard.width+9,artboard.height+9);
    Where 'artboard.width' & 'artboard.height' you will have calculated from your file. An Array(9,9,9,9); would not constitute any boxes bounds.

  • How do you download free software and updates without a credit card? I'm unable to by-pass the credit card information page..

    How do you download free software and updates without a credit card? I'm unable to by-pass the credit card information page..

    This user, mountaingoatgirl, explains how to get a None option in your account details in the iTunes app on a Mac or PC. -
    https://discussions.apple.com/message/24907941

Maybe you are looking for

  • Can't open .ppt file: "out of memory" error on Mavericks

    Hello, I have a couple of .ppt files that can't open/import in keynote v5.3. It says "import error: out of memory". The files are pretty small, 500kb to 8mb, no videos or music, only images and plain text. I have dozens of free gb. This error started

  • Run report from EBS with Discoverer running on a separate server

    Hi. Usually, when I define a report as a form function, it can be accessed using an URL. In my current project, Discoverer (10g) is running on a separate application server (but using the same database). Is there any way of specifying a function in E

  • My downloaded aps won't launch on iPad

    I hooked up to my work computer today and I've never done that before so it asked me to sync iTunes, I thought I declined but I was tethering using iBooks... Now none of my downloaded aps will launch.  I'm on the iPad 3

  • ERROR MESSAGE: 1327 HELP PLEASE!!!!

    Hi there, I've looked in the forums for answers to this error message but nothing has helped me. I had 2 disc drives in my computer, but recently my d drive where I had alot of my programs etc failed and it had been taken out of my computer. I am now

  • How to move iPhoto Library from external drive to new mac?

    I have exported a copy of my iPhoto Library from my old mac to an external hard drive. How can I import entire library into iPhoto of new mac? When I click Import to Library, I'm unable to highlight iPhoto Library file listed on my external hard driv