How to delete a perticular node from xml file using java code

Hii All,
Now i am trying to delete a perticular node from xml file.Like...
XML file:
<Licence>
<SERVER>
<was id="1">1</was>
<was id="2">2</was>
</SERVER>
</LICENCE>
I am working in messaging service using JABBER framework with whiteboard facility.
Here Some commands i have created to add,modify,delete nodes from xml file.They Are
1.If u want to add a new node then.
create Licence.SERVER <ss id="3">ddd</ss> lic.xml
(here u want to add a new node called "ss" under Licence.SERVER.
And lic.xml is tyhe xml file name where it was saved.
2.If u want to delete a node(Suppose <was id="1">),then the command should be
delete Licence.SERVER.was:id='"1" lic.xml
A problem arises that here it find two was attributes.And it delete the last was attribute,not the requested node.
PLEASE HELP ME IN SOLVING THIS CODE..
------------------------------------

Looks like you clicked on "Post" before you pasted in the code you were talking about.

Similar Messages

  • How to search and replace in an xml file using java

    Hi all,
    I am new to java and Xml Programming.
    I have to search and replace a value Suresh with some other name in the below xml file.
    Any help of code in java it is of great help,and its very urgent.
    I am using java swings for generating two text boxes and a button but i am not able to search in the xml file thru the values that are entered into these text boxes.
    Thanks in advance.
    **XML File*
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <student>
    <stud_name>Suresh</stud_name>
    <stud_age>40</stud_age>
    </student>Also i am using SAX Parser in the java program
    any help of code or any tutorials for sax parisng is very urgent please help me to resolve this problem
    Edited by: Karthik84 on Aug 19, 2008 1:45 AM
    Edited by: Karthik84 on Aug 19, 2008 3:15 AM

    Using XPath to locate the elements you are after is very easy.
    Try something like this:
    import java.io.File;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import javax.xml.xpath.XPath;
    import javax.xml.xpath.XPathConstants;
    import javax.xml.xpath.XPathFactory;
    import org.w3c.dom.Document;
    import org.w3c.dom.NodeList;
    import org.xml.sax.InputSource;
    public class BasicXMLReplaceWithDOM4J {
         static String inputFile = "C:/student.xml";
         static String outputFile = "C:/studentRenamed.xml";
         public static void main(String[] args) throws Exception {
              // Read xml and build a DOM document
              Document doc = DocumentBuilderFactory.newInstance()
                        .newDocumentBuilder().parse(new InputSource(inputFile));
              // Use XPath to find all nodes where student is named 'Suresh'
              XPath xpath = XPathFactory.newInstance().newXPath();
              NodeList nodes = (NodeList)xpath
                   .evaluate("//stud_name[text()='Suresh']", doc, XPathConstants.NODESET);
              // Rename these nodes
              for (int idx = 0; idx < nodes.getLength(); idx++) {
                   nodes.item(idx).setTextContent("Suresh-Renamed");
              // Write the DOM document to the file
              Transformer xformer = TransformerFactory.newInstance().newTransformer();
              xformer.transform(new DOMSource(doc), new StreamResult(new File(outputFile)));
    }- Roy

  • Updating an existing xml file using java code

    hi friends,
    I have simple problem, I have an existing xml file and I want to update some of the values in the file.
    can any one send me the java code for that.
    bye.
    -harish

    org.w3c.dom.Document d = parseXmlFile("D:/www/Detailcache/detail.xml", false);
    public static Document parseXmlFile(String filename, boolean validating) {
    try {
    // Create a builder factory
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(validating);
    // Create the builder and parse the file
    Document doc = factory.newDocumentBuilder().parse(new File(filename));
    return doc;
    } catch (Exception e) {
    System.out.println("ERROR-->");e.printStackTrace();
    return null;
    look at .. for more related examples
    http://javaalmanac.com/egs/javax.xml.parsers/BasicDom.html?l=rel

  • How to delete string or line from unix file(dataset) of application server

    Hi  All,
    After transfer workarea information or all records into dataset(unix file). When I see the file in application server automatically the last line is shown a blank line. I am not passing any blank line.
    I have tried for single record than also the file generates the last line(2nd line) also a blank line.
    When I m reading the dataset, it is not reading the last blank line but why it is showing the last blank line?
    How to delete string or line from unix file(dataset) of application server?
    Please give your comments to resolve this.
    Thanks
    Tirumula Rao Chinni

    Hi Rio,
    I faced similar kind of issue working with files on UNIX platform.
    The line is a line feed to remove it use
    DATA : lv_carr_linefd TYPE abap_cr_lf VALUE cl_abap_char_utilities=>cr_lf. 
      DATA : lv_carr_return TYPE char1,                                   
             lv_line_feed   TYPE char1.                                          
      lv_line_feed   = lv_carr_linefd(1).
      lv_carr_return = lv_carr_linefd+1(1).
    Note: IMP: The character in ' ' is not space but is a special
    character set by pressing ALT and +255 simultaneosly
      REPLACE ALL OCCURRENCES OF lv_line_feed IN l_string WITH ' '.
      REPLACE ALL OCCURRENCES OF lv_carr_return IN l_string WITH ' '.

  • How to read the data from Excel file and Store in XML file using java

    Hi All,
    I got a problem with Excel file.
    My problem is how to read the data from Excel file and Store in XML file using java excel api.
    For getting the data from Excel file what are all the steps i need to follow to get the correct result.
    Any body can send me the code (with java code ,Excel sheet) to this mail id : [email protected]
    Thanks & Regards,
    Sreenu,
    [email protected],
    india,

    If you want someone to do your work, please have the courtesy to provide payment.
    http://www.rentacoder.com

  • Passing Parameters from XML file to Java Application

    Can any one help me to know the way of passing values from XML file to Java Application..
    Thanx in advance

    With the Processing Instructions <?name pidata?>
    Get the Nodes in a Document.
    Node node;
    if(node.getNodeType()==Node.PROCESSING_INSTRUCTION_NODE)
    //String param=node.getData();

  • How to write as XML file using java 1.5

    hi all,
    i am trying to create an XML file using java 1.5. I took a XML creating java file which was working with java 1.4 and ported same file into java 1.5 with changes according to the SAX and DOM implmentation in java 1.5 and tried to compile. But while writing as a file it throws error "cannot find the symbol."
    can any body help me out to solve this issue.......
    thankx in advance
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.w3c.dom.NamedNodeMap;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    import org.xml.sax.DocumentHandler;
    import org.xml.sax.InputSource;
    import org.xml.sax.helpers.ParserFactory;
    import java.io.*;
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();                   
                   dbf.setNamespaceAware(true);
    DocumentBuilder db = dbf.newDocumentBuilder();                   
    Document xmlDoc =  db.newDocument();
    // this creates the xml document ref
    // parent node reference
    Element rootnd = (Element) xmlDoc.createElement("ALL_TABLES");
    // root node
    xmlDoc.appendChild(rootnd);
    Element rownd = (Element) xmlDoc.createElement("ROW");
    rootnd.appendChild(rownd);
    Element statusnd = (Element) xmlDoc.createElement("FILE_STATUS");
    rownd.appendChild(statusnd);
    statusnd.appendChild(xmlDoc.createTextNode("Y")
    FileOutputStream outpt = new FileOutputStream(outdir + "//forbranch.xml");
    Writer outf = new OutputStreamWriter(outpt, "UTF-8");
    //error is occuring here Since write method is not available in the Document class
    xmlDoc.write(outf);
    outf.flush();

    Hi,
    when I look in the JDK1.4.2 specification I don't see any write method in the Document interface.
    However, your solution is the Transformer class. There you transform your DOM tree into any output you need. Your code sould look something like this:     TransformerFactory tf = TransformerFactory.newInstance();
         // set all necessary features for your transformer -> see OutputKeys
         Transformer t = tf.newTransformer();
         t.transform(new DOMSource(xmlDoc), new StreamResult(file));Then you have your XML file stored in the file system.
    Hope it helps.

  • How do I produce an excel file using java code

    How do i produce an excel file using java code.
    If it is possible would ne one have ne source code as an example.
    I have tried looking up information on outputing the information to a *.csv file but unfortunality i have had no luck in finding any information. To be exact ne source code.
    Thanks
    Lee

    That's what I use and I'd be the first to admit that it's very messy. But it works. Go use Google and see what else you can find.

  • Merging 2 message history xml files using java

    hi., i'm new to xml programming..
    well..., i got homework bout it..., and got a lot of problems to write it..
    could you help me a favor??
    I need to write a homework bout merging 2 MSN mssg history files (xml files) using java.
    At least need to maintain their date, time, sender, receiver, and information(sayings)....and are ordered using time..
    can u help me??

    Well, show us what you've got and where you are having difficulty.

  • How can I generate IDOC(WPUUMS) from XML file in POSDM or in SAP Retail

    Hallo Retail expert,
                                I have following scenario,
    I have Retail Store who send me their daily sales report through Wincor Nixdorf Point of sale. There i am using standard POSLOG2 to SEEBURGER(its a middleware which act as Converter) xml format and then i post that data first in POSDM and then with BAPI i transfer or book that data to SAP Retail.
    Above is the one scenario which is working.
    This is the Second scenario.......
    I have some external Retail store, they dont have Wincor Nixdorf POS, so they send me their Sales Report through SEEBURGER(its a middle Hardware which act as Converter) and SEEBURGER Convert that Sales data to XML format. My question is....
    How can i upload or Convert a XML File into IDOC (WPUUMS)in SAP or in POSDM?
    any new suggestion are welcome.
    Thank you all in advance.
    regards,
    Niel

    Hi,
    1. To get the required XML Schema, use transaction code WE60 to go to the IDoc documentation -> enter the IDoc type you want to use (WPUUMS01). Flag control and data record. Then display the XSD by choosing Documentation -> XML Schema from the menue bar. Now you can donwload the XSD for usage in Seeburger.
    2. Create your mapping from the POS format into the IDoc XML format in Seeburger.
    3. Create an XML File Port in ERP or POS DM using transaction code WE21.
    3. To inbound the XML file from Seeburger into POS DM or SAP Retail Seeburger should trigger the function module EDI_DATA_INCOMING. Parameters for this FM are the Pathname to the XML file and the Portname you just created. Based on the port name the FM can derive the port type xml and the data will be handled as XML data.
    Regards Carsten

  • How to parse contents from XML file in Java

    Hi All,
    I have a scenario like this . I have one xml file with key value pairs of ( name , URL ) . I have retrieved contents from XML file , now I want to parse these contents and store in a bean object.
    How to parse Contents of XML file??
    Thanks in advance,
    Rajendra.

    Hi All,
    I have a scenario like this . I have one xml file with key value pairs of ( name , URL ) . I have retrieved contents from XML file , now I want to parse these contents and store in a bean object.
    How to parse Contents of XML file??
    Thanks in advance,
    Rajendra.

  • How to delete photos and albums from ipad without using iTunes

    I have an ipad 2 5.1.1 I need to delete photo albums without using iTunes. I've tried the edit button but it won't let me delete images or albums, just modify them. How do I delete?

    The links below have instructions for deleting photos.
    iOS and iPod: Syncing photos using iTunes
    http://support.apple.com/kb/HT4236
    iPad Tip: How to Delete Photos from Your iPad in the Photos App
    http://ipadacademy.com/2011/08/ipad-tip-how-to-delete-photos-from-your-ipad-in-t he-photos-app
    Another Way to Quickly Delete Photos from Your iPad (Mac Only)
    http://ipadacademy.com/2011/09/another-way-to-quickly-delete-photos-from-your-ip ad-mac-only
    How to Delete Photos from iPad
    http://www.wondershare.com/apple-idevice/how-to-delete-photos-from-ipad.html
    How to: Batch Delete Photos on the iPad
    http://www.lifeisaprayer.com/blog/2010/how-batch-delete-photos-ipad
    (With iOS 5.1, use 2 fingers)
    How to Delete Photos from iCloud’s Photo Stream
    http://www.cultofmac.com/124235/how-to-delete-photos-from-iclouds-photo-stream/
     Cheers, Tom

  • How to edit/update data into an XML file using Flex and Actionscript

    I can read an external xml file, please see the code below:
    protected function button1_clickHandler(event:MouseEvent):void
    var GrowthChartsDataGrid:XML;
    var loader:URLLoader = new URLLoader();
    var request:URLRequest = new URLRequest("../GrowthChartsDataGrid.xml");
        loader.load(request);
        loader.addEventListener(Event.COMPLETE, onComplete)
    function onComplete (event:Event)
         var loader:URLLoader = URLLoader(event.target);
         GrowthChartsDataGrid = new XML(loader.data);
         GrowthChartsDataGrid.GrowthChartGridView += <Month> {txtMonth.text} <Weight> {txtWeight.text} </Weight> </Month>
         texttesting.text = GrowthChartsDataGrid.toString();
    I can read an XML file and can add an extra node and can display it in a text filed. But I want to update the XML file contents which will come from the txtMonth and txtWeight text boxes.
    Please any suggestions???

    First of all thanks for your quick reply .
    I actually want to add another node inthe xml file. Files is at a local location and i can read the file and add an extra node (but I cant store this extra node in the actual XML file). But I want to save XML with the extra node.
    For exmaple,
    my current xml is:
    <?xml version="1.0" encoding="utf-8"?>
    <GrowthChartGridView>
        <Month> 1
        <Weight>3.5</Weight></Month>
    <Month> 2
        <Weight>3.9</Weight></Month>
    <Month> 3
        <Weight>4.5</Weight></Month>
    </GrowthChartGridView>
    and at run time, I can create a new node using the data from two textboxes at button click event.
         GrowthChartsDataGrid.GrowthChartGridView += <Month> {txtMonth.text} <Weight> {txtWeight.text} </Weight> </Month>
    Now what I want to do is, I want to add this node back in to my XML. Therefore, the result I am looking for is, my local XML should update like this.
    <?xml version="1.0" encoding="utf-8"?>
    <GrowthChartGridView>
        <Month> 1
        <Weight>3.5</Weight></Month>
    <Month> 2
        <Weight>3.9</Weight></Month>
    <Month> 3
        <Weight>4.5</Weight></Month>
    <Month> {txtMonth.text} <Weight> {txtWeight.text} </Weight> </Month>  //I can read data from text boxes so its fine but I can not store this in to                                                                                                          my original XML
    </GrowthChartGridView>
    Thanks

  • How Do I write an XML file using Java?

    Hello there!! to everyone reading my post.
    I have this project I need to do, and I have no clue where to start, I was wondering if you guys could help me out.
    I need to know how to write an XML file using a Java Program, but without using a Third party library.... just using java native APIs.
    I will probably take the values to construct the file from a form.
    I will certainly appreciate if you could post some sample code for me.
    Thank you very much in advance..

    Hello there!,
    I have some doubts about the Tutorial I am currently reading. correct me If I'm wrong, but the section "Write a simple XML file" teaches you how to do so using a text editor. I need to create my XML file from a running Java Program written by myself, that takes the values to build it from some variables.
    If I'm totally wrong about what I'm saying, could you please point me to where I can find the information of how to do what I'm asking for, inside the tutorial.
    Thank you very much,...
    sincerely.

  • How to read the attribute of the xml file using jaxb

    Thanks,
    Buddy as i have a issue i have to read the xml file using jaxb and xml file contains this data and i have read the attribute like name , desc and action for a particular menu name pls tell the code how to do this it will be a great favour to me
    thanx in advance
    Rasool
    <contextmenu>
    <menu name='Lead' >
    <menuitem name='newlead' desc='New Lead' action='/leads.do?dispatch=insert' />
    <menuitem name='editlead' desc='Edit Lead' action='' />
    <menuitem name='leadinfo' desc='Lead Information' action='' />
    </menu>
    <menu name='Cases' >
    <menuitem name='' desc='' action='' />
    <menuitem name='' desc='' action='' />
    <menuitem name='' desc='' action='' />
    </menu>
    <menu name='Contact' >
    <menuitem name='' desc='' action='' />
    <menuitem name='' desc='' action='' />
    <menuitem name='' desc='' action='' />
    </menu>
    </contextmenu>

    What my program do is to get the encoding of XML files and convert them to UTF-8 encoding files, while I need this "encoding" information of the original XML document thus I can convert...
    After reading specifications and JDOM docs, the truth turns to be disappointed, no function is provided to get this information in JDOM level 2(the current released one), while it's promissed that this function will be provided in JDOM level API....
    Thanx all for your help and attention!!!

Maybe you are looking for

  • SSL handshake failed: X509CertChainIncompleteErr - How to call secure WS?

    Hi all, I'm trying to use a third party web service over SSL. I'm using jdk 1.5.0_11 and jDev 10.1.3.0.4. Here is what I've done so far: 1 - I generated a web service proxy using jDev's wizard. 2 - I created a simple keystore with keytool with the fo

  • Aperture 3 Backing Up Referenced Masters

    I am trying to develop my workflow better. I shoot images into the field and download them to my laptop. I then transfer them back to my iMac when I get home. I use Aperture 3 for my pictures. In Aperture, I have all of my files referenced to a exter

  • Can a vendor have multiple Payment terms?

    Hi The user has maintained payment terms in MM (MK02) & FI (FK02) and maintained same payment term for Company code. However in BW report for "Purchase statistic per Supplier" does not match with R/3 and some vendor shows multi payment term. What mig

  • What is the use of # in data declaration

    hi experts, i am working in one of the old programs, where in data declaration they have used - data: matnr like mara-matnr,##          mfrpn like mara-mfrpn,## and when i work in front end editor (4.7c), these data come in red colour. i know when i

  • Installing Canon PIXMA MG3170 to my MacBook Pro (OS 10.8)

    I'm trying to install my new Canon PIXMA MG3170 printer to my MacBook Pro. I am aware that the bundled software isn't compatible to OS 10.8, and after endless research through this community, I came across several solutions. I installed it via IP add