How to edit xml using jdom

hi
how to read and edit xml file using jdom, i tried using
javax.xml.transform.*; // JAXP
javax.xml.transform.dom.DOMSource; //
i can read xml file . but iam not able to edit the xml file.
how to achive this

1. Select nodes to be modified with the JDom XPath class selectSingleNode and selectNodes methods.
SAXBuilder saxBuilder=new SAXBuilder("org.apache.xerces.parsers.SAXParser");
org.jdom.Document jdomDocument=saxBuilder.build(new File("c:/input.xml"));
org.jdom.Element node= (org.jdom.Element)(XPath.selectSingleNode(jdomDocument,"/root/node"));
2. Modify the node values with the Element class setter methods.
3. Output document with the XMLOutputer class.

Similar Messages

  • How to edit xml using AS3

    I want to edit xml file on run time dynamically using AS3
    Plzzzzzzzz if it possible send the tutorials links or sample script.

    Flash player 10 has support for accessing local system file. This can be done using the FileReference class. You can browse a loca file, rad it and then save it back. But at the time of saving, the user is prompted to choose a location for saving the file.
    Else you can use some server side technology with your app to read and write files.

  • How to edit xml file particular value. and how to send xml file over ip address 192.168.2.10 using ftp

    how to edit xml file particular value. and how to send xml file over ip address 192.168.2.10 device using ftp through Ethernet

    Hello
    For using FTP function in LabVIEW, I recommend you to check this document: FTP Basics
    Also, take a look at FTP Browser.vi, which is available at the Example Finder.
    To edit a XML file, try to use VIs in XML palette. Maybe Write to XML.vi helps you.
    Post your current VI if possible.
    Regards
    Mondoni

  • How to validate xml using xsd

    Hi All
    please tell me how to validate xml using xsd
    regards

    Try using this link:
    = http://www.google.nl/search?q=XML+validate+oracle for instance or
    = use the search button on this forum and / or
    = read the FAQ on this (XML DB FAQ
    Thanks Eddie et all, for educating me via http://awads.net/wp/2006/11/14/barts-punishment-for-asking-dumb-questions (don't mind the URL , the info there is really useful)
    The following link on this site is just brilliant: http://www.albinoblacksheep.com/flash/posting.php
    Grz
    Marco
    Message was edited by:
    mgralike

  • How to get data using JDOM

    Hi,
    I have this xml file stored in operator.xml
    <Operator>
         <Customer>
              <Name>sam</Name>
              <Street>albert str.</Street>
              <ZipCode>45454</ZipCode>
              <City>NY</City>
              <Country>USA</Country>
              <EMailAddress>[email protected]</EMailAddress>
              <MeterNumber>1000</MeterNumber>
              <MeasuringUnit>kWh</MeasuringUnit>
              <Reading>
              <Month>1</Month>
              <Value>900</Value>
              </Reading>
              <Reading>
              <Month>2</Month>
              <Value>725</Value>
              </Reading>
              <Reading>
              <Month>3</Month>
              <Value>950</Value>
              </Reading>
         </Customer>
    </Operator>I have the following getter statements in my code:
    String name=req.getName();
    int month=req.getMonth();Now, I want to get value for particular customer (by checking name for equality with getter) and for particular month( by checking for equality with getter).
    I have written the following statements:
    final String filename="operator.xml";
    SAXBuilder builder=new SAXBuilder(true);
    Document doc=builder.build(filename);
    Element root=doc.getRootElement();How to proceed further using JDOM. I am confused with getChild(), getChildText() etc.,
    thanks,

    Obtain values with the JDom XPath class selectSingleNode and selectNodes methods.
    SAXBuilder saxBuilder=new SAXBuilder("org.apache.xerces.parsers.SAXParser");
    org.jdom.Document jdomDocument=saxBuilder.build(new File("c:/input.xml"));
    org.jdom.Element zipcodeNode= (org.jdom.Element)(XPath.selectSingleNode(jdomDocument,"/Operator//Customer/zipCode"));

  • How to handle children using JDOM 8

    Hi,
    I'll like to handle (write, add child, remove child) a XML file with this structure using JDOM :
    <parent>
    <child1 name="">
    <element1></element1>
    <element2></element2>
    <element3></element3>
    </child1>
    <child2 name="">
    <element1></element1>
    <element2></element2>
    <element3></element3>
    </child2>
    </parent>
    I already use JDOMb8 to read and to manipulate the document, and it works well, but documentation does not make me feel comfortable for setting up new child??
    My problem is how to add a second child with such elements ??
    thank you.
    X

    Hi,
    I found a solution.
    If you're interested in... this helps a lot :
    http://www.javaworld.com/javaworld/jw-07-2000/jw-0728-jdom2-p2.html
    X

  • How to edit xml link?

    First a few words about my context:
    I received a layout made on a CS3 version of InDesign. Now I am trying to create a procedure to automate the production of several pdf based on this layout. Manually the process would be to open the layout; edit the xml link with each xml source and create a corresponding pdf...
    First issue:
    In CS4 when I want to manually edit the xml link, the opened dialog prevent me (xml files are in gray) to select xml files, is it a well-known issue? How can I avoid it?
    Second question:
    How to edit the xml link from script?
    Last question - applescript question - :
    How to skip application dialogs? Like "This document miss some links, would you continue?"
    If you'd be able to help me, thanks in advance!

    Dear Loic_aigon
       Many thanks!
    But I used what you said!.
    But Still I'm facing the same problem [ not find : "image"]
    Here the below tag I used..
    <Figure id="f0020"><label>Figure 2 </label><caption>Dummy Figure </caption>
    <image href="C:/Program %20Files/VUG/clouds.jpg"></image></Figure>
    Program :
    //============== Start =====================//
    #include "E:/HariharaSudhan/XMDOM_TEST/xml_for_script-3.1/jsXMLParser/xmldom.js";
    var myFile = File("E:/HariharaSudhan/XMDOM_TEST/xml/test.xml");
    myFile.open("r");
    var myXMLString = String(myFile.read());
    var objDom = new XMLDoc(myXMLString, undefined);
    var domTree = objDom.docNode;
    $.writeln(domTree);
    var myImage = domTree.getElements("image");
    var myDoc = app.open(File("E:/HariharaSudhan/XMDOM_TEST/Indd/test.indd"), true);
    $.writeln(myImage);
    for(var i=0; i<myImage.length; i++)
    $.writeln( myImage[i].name);
    myImage[i].getAttribute("href").replace('file:///','');
      var myPage = doc.pages[0].duplicate(LocationOptions.AT_END);
      var myFrame = myPage.pageItems.item("image");
      myFrame.place(File(myImage[i].getAttribute("href").replace('file:///','')));
      app.pdfExportPreferences.pageRange = myPage.name;
      app.pdfExportPreferences.viewPDF  = false;
      myDoc.exportFile(ExportFormat.pdfType, File("E:/HariharaSudhan/XMDOM_TEST/PDF/" +(i+ 1)+".pdf"), undefined, undefined, undefined, undefined);
    myDoc.close(SaveOptions.NO);
    //===================== End ============================//
    So please kindly see the attached xml file, and please send me the solutions.
    Please this is my humble request.
    Thanks & Regards
    T.R.Harihara SudhaN

  • How to edit XML parsed data and save on iPhone app

    Hi,
    How to edit and XML retrieved data that is displayed on an iPhone app and save again in the same XML file using iPhone SDK.
    In other words I want to change the XML file data or edit and save.
    Thnx in advance.
    Regards
    Amit

    Hello amit,
    No, not at all. Surely you will parse your XML file using the NSXMLParser class. OK! i think i get it now, do you wants to change/modify the value of any tag in the XML file? For that you will be required to parse your XML file using NSXMLParser class, and fill out some data structure (according to the the XML format) do some changes into your data structure, and then write your XML to the file (according to the edited data structure) using the method i told u earlier. This is what my preferred method is, and i am pretty much sure that it is not a bad way to do this at all.
    Hope this clarifies some of your queries.
    Best regards,
    Obaid

  • How to edit entries using se16n?

    I want to change some entries using se16n.:h1 But I don't have the authorization for changing the table entries. Is there any way for me to change the entries in se16n?
    Moderator message: obtain proper authorization, nasty workrounds are not supported here, replies have been rejected.
    Edited by: Thomas Zloch on Mar 16, 2011 2:53 PM

    1. Select nodes to be modified with the JDom XPath class selectSingleNode and selectNodes methods.
    SAXBuilder saxBuilder=new SAXBuilder("org.apache.xerces.parsers.SAXParser");
    org.jdom.Document jdomDocument=saxBuilder.build(new File("c:/input.xml"));
    org.jdom.Element node= (org.jdom.Element)(XPath.selectSingleNode(jdomDocument,"/root/node"));
    2. Modify the node values with the Element class setter methods.
    3. Output document with the XMLOutputer class.

  • How to send XML using UTL_HTTP

    I am trying to workout how to send XML data to a webserver using UTL_HTTP but am not getting any reply
    I need to submit the following XML document to a server "http://api.fastsms.co.uk/api/xmlapi.php"  Their instructions are "The XML Document should be posted unencoded, with a UTF-8 character set as parameter 'xml'"
    If I submit the following XML on their test form
    <?xml version="1.0"?>
    <apirequest version="1">
    <user>
      <username>**USER**</username>
      <password>**PASSWORD**</password>
    </user>
    <application>
      <name>Example Application</name>
      <version>1.0</version>
    </application>
    <inboundcheck lastid="10711399"/>
    </apirequest>
    I get an XML response back with the messages in my inbox. 
    This is the code I am trying to use to accomplish the same from PL/SQL : I know a response is coming back as there is header information - just no content.  What am I doing wrong ?
      l_xml VARCHAR2(5000);
      req utl_http.req;
      resp utl_http.resp;
      header_name VARCHAR2(256); -- Response header name
      header_value VARCHAR2(1024); -- Response header value
      response_text VARCHAR2(4000); -- Response body
      l_url VARCHAR2(100);
    BEGIN
      l_xml := 'xml=<?xml version="1.0"?>';
      l_xml := '<apirequest version="1">';
      l_xml := '<user>';
      l_xml := '<username>**USER**</username>';
      l_xml := '<password>**PASSWORD**</password>';
      l_xml := '</user>';
      l_xml := '<application>';
      l_xml := '<name>Example Application</name>';
      l_xml := '<version>1.0</version>';
      l_xml := '</application>';
      l_xml := '<inboundcheck lastid="10711399"/>';
      l_xml := '</apirequest>';
      -- Open HTTP connection
      l_url := 'http://api.fastsms.co.uk/api/xmlapi.php';
      req := utl_http.begin_request(l_url,'POST',utl_http.HTTP_VERSION_1_1);
      -- Set headers for type and length
      utl_http.set_header(req,'Content-Type','application/x-www-form-urlencoded');
      utl_http.set_header(req,'Content-Length',to_char(length(l_xml)));
      -- Write parameter
      utl_http.write_text(req,l_xml);
      -- Read response file
      resp := utl_http.get_response(req);
      -- Print out the response headers
      FOR i IN 1 .. utl_http.get_header_count(resp) LOOP
        utl_http.get_header(resp,i,header_name,header_value);
        logging_pkg.info(header_name || ': ' || header_value);
      END LOOP;
      -- Print out the response body
      BEGIN
        LOOP
          utl_http.read_text(resp,response_text);
          logging_pkg.info(response_text);
        END LOOP;
      EXCEPTION
        WHEN utl_http.end_of_body THEN
          logging_pkg.info('End of body');
      END;
      -- close http connection
      utl_http.end_response(resp);
      EXCEPTION
        WHEN utl_http.end_of_body THEN
          utl_http.end_response(resp);
    END;
    Cheers,
    Brent

    Hi Billy
    Yikes - how embarassing !  Thanks for pointing out my beginners mistake there.  I've fixed my code - and also implemented the substitutions of parameters like you suggested - I like that approach.
    Unfortunately the end result is no better - the line
    utl_http.read_text(resp,response_text);
    Still returns nothing back
    The headers that are coming back are
    Date: Thu, 04 Jul 2013 08:31:56 GMT
    Server: Apache/2.2.16 (Ubuntu)
    X-Powered-By: PHP/5.3.3-1ubuntu9.3
    Expires: Thu, 19 Nov 1981 08:52:00 GMT
    Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    Pragma: no-cache
    Vary: Accept-Encoding
    Content-Length: 0
    Content-Type: text/html; charset=UTF-8
    Connection: close
    I guess I will need to try chasing it with the fastsms vendor so see if they can check my incoming request and see if there are any glaring problems. I know the xml is correct as I am now logging the xml string just before I send it and when I take that string and put it in their test form it works perfectly - something else in the puzzle is missing. I've had no experience using utl_http before - perhaps it's no possible to read the xml repsonse using this ?
    Anyway, thanks for your help Billy.
    ps - How do you paste your code into your message to get that formatting ?
    Cheers,
    Brent

  • How to edit video using iMovie?

    Hi,
    I am new to iMovie. I am not familiar with its key tools. Can any one please tell me how to edit a video using the software? I need to put a video on Youtube displaying features of my website http://www.fundoofun.com
    Thanks in advance.
    K V Gautam

    Move the video between iPads using Dropbox or an App like Photo Transfer.

  • How to edit registry using recovery console or dos

    Hello everybody!
    Due to some reason (virus) the value of  - "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon - Shell " was changed so I repaired it with Explorer.exe. But  due to some spelling mistake now I can log in in Win Xp. When the user log in screen appears and I choose the account its automatically logOff and return to the User Log in screen.
    Now I have to repair the spelling mistake in registry key.
    Please inform How can I do this. I can't log in so I can't use "Regedit". Can it is possible to edit the registry using recovery console?
    Thanks & regards
    nitin

    Step 1
    Type "cd %systemroot%/system32/" into the command prompt to go to the folder that contains the Registry Editor.
    Step 2
    Type "reg" into the command prompt to display a list of parameters and instructions on how to edit the system registry.
    Step 3
    Type "reg [parameter] /?", replacing "[parameter]" with one of the listed parameters, into the command prompt to list all available functions that can be used with that parameter.
    Step 4
    Type "reg [parameter] [function]" into the command line, but replace "[parameter]" with one of the listed parameters (query, add, delete, copy, etc.) and "[function]" with a function listed above, along with any additional options
    for each function. For example, to delete a registry key, type "reg delete [rootkey]\[keyname]", replacing the "[rootkey]\[keyname]" text with the location of the registry key.
    Step 5
    Save a registry key by typing "reg save [rootkey]\[keyname] [filename].hiv", where the "[rootkey]" and "[keyname]" text are the location and name of the registry file and "[filename]" is the name of the file to which
    you are saving the key.
    Step 6
    Restore a registry key by typing "reg restore [rootkey]\[keyname] [filename].hiv", where the "[rootkey]" and "[keyname]" text are the location and key name that you want to restore and "[filename]" is the name of the
    file containing the saved key.
    Step 7
    Import a "REG" file by typing "reg import [filename].reg". To export a registry key to a "REG" file, type "reg export [rootkey]\[keyname] [filename].hiv", where the "[rootkey]" and "[keyname]" text
    are the location and key name that you want to export and "[filename]" is the name of the "REG" file you are exporting.

  • How to generate xml using "Data Template"

    Hi,
    Can any one please tell me the steps to create xml using "Data Template".
    As per the user guide the execution method for "data Template" is "Java Concurrent Program" and the Executable mentiones is "XDODTEXE".
    But there is no information about the "execution file name" and "execution path name" which is mandatory.
    Thanks and Regards,
    Sandhya

    Hi Sandhya,
    To put a Data Template into use, you don't need to define any new executables. XDODTEXE executable is already registered in the system, as it ships with the application. The Data Template is not an executable as such, but a collection of instructions for what queries to perform and what should the resulting XML look like. XDODTEXE knows how to interpret those instructions, and produce the XML output.
    (And if you add a layout template, handle that too.)
    You do need to do the following:
    1) Create a new Data Definition (XML Publisher Administrator > Data Definitions)
    2) Upload your Data Template (remember the Code for the next step)
    3) Create a Concurrent Program that is linked to the Data Definition (Short Name = Code) (System Administrator > Program > Define)
    4) Add your Concurrent Program to a Request Group (System Administrator > Security > Responsibility > Request)
    I recommend you take a look at the XML Publisher Administration and Developer's Guide, you will find more information there.
    (http://download-west.oracle.com/docs/cd/B40089_02/current/acrobat/120xdoig.pdf)
    Best Regards & Happy New Year 2008,
    Matilda Smeds

  • How to validate XML using java_xml_pack-summer-02?

    In jaxp1.1, we validate the xml file in this way:
    c:\java -jar Validator.jar myBookStore.xml
    However, in java_xml_pack-summer-02, which is latest version of jaxp, the Validator.jar is not available. So, how to validate xml file?
    Pls help.

    develop your own validator... here is a quick and dirty one, which spits exceptions when error are met:
    import java.io.*;
    import javax.xml.parsers.*;
    import org.xml.sax.*;
    import org.xml.sax.helpers.DefaultHandler;
    public class Validator
      public static void main(String[] args) throws Exception {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        spf.setValidating(true);
        spf.setNamespaceAware(true);
        SAXParser sp = spf.newSAXParser();
        sp.parse(new File(args[0]), new DefaultHandler());
    }

  • Parsing Xml using Jdom

    Hi all,
    I am reposting it as I was told to format the code and send it again.
    I am trying to parse a xml file using a jdom java code.This code works fine if I remove xmlns attribute in the root element. (I get the expected result) .If the "xmlns" attribute is put in the xml as it should be then the parsing and retrieving returns null. Please tell me how to fix this issue.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Xml
    <process name="CreateKBEntryService" targetNamespace="http://serena.com/CreateKBEntryService" suppressJoinFailure="yes" xmlns:tns="http://serena.com/CreateKBEntryService" xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/" xmlns:bpelx="http://schemas.oracle.com/bpel/extension" xmlns:ora="http://schemas.oracle.com/xpath/extension" xmlns:nsxml0="http://localhost:8080/axis/services/CreateKBEntryService" xmlns:nsxml1="http://DefaultNamespace" xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
    <partnerLinks>
    <partnerLink name="client" partnerLinkType="tns:CreateKBEntryService" myRole="CreateKBEntryServiceProvider"/>
    <partnerLink name="CreateKBEntryPartnerLink" partnerLinkType="nsxml0:CreateKBEntryLink" partnerRole="CreateKBEntryProvider"/>
    </partnerLinks>
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
    Java:
    import java.io.*;
    import java.util.*;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.input.SAXBuilder;
    public class sample1 {
    public static void main(String[] args) throws Exception {
    // create a XML parser and read the XML file
    SAXBuilder oBuilder = new SAXBuilder();
    Document oDoc = oBuilder.build(new File("**xml file location**"));
    Element root = oDoc.getRootElement();
    System.out.println(root.getName());
    String tgtns= root.getAttributeValue("targetNamespace");
    System.out.println("tgt ns "+ tgtns);
    List list= root.getChildren("partnerLinks");
    Iterator it1= list.iterator();
    System.out.println("Iterator 1 - "+list.size());
    while(it1.hasNext()){
    Element partnerlinks = (Element)it1.next();
    List list2= partnerlinks.getChildren("partnerLink");
    System.out.println("iterator 2 - "+list2.size());
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Result:
    Without Xmlns in xml file(Expected and correct output)
    process
    tgt ns http://serena.com/CreateKBEntryService
    Iterator 1 - 1//expected and correct result that comes when I remove xmlns attribute from xml
    iterator 2 - 2
    Result with xmlns:
    process
    tgt ns http://serena.com/CreateKBEntryService
    Iterator 1 - 0 //instead of 0 should return 1

    Hi all,
    I am reposting it as I was told to format the code and send it again.
    I am trying to parse a xml file using a jdom java code.This code works fine if I remove xmlns attribute in the root element. (I get the expected result) .If the "xmlns" attribute is put in the xml as it should be then the parsing and retrieving returns null. Please tell me how to fix this issue.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Xml
    <process name="CreateKBEntryService" targetNamespace="http://serena.com/CreateKBEntryService" suppressJoinFailure="yes" xmlns:tns="http://serena.com/CreateKBEntryService" xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/" xmlns:bpelx="http://schemas.oracle.com/bpel/extension" xmlns:ora="http://schemas.oracle.com/xpath/extension" xmlns:nsxml0="http://localhost:8080/axis/services/CreateKBEntryService" xmlns:nsxml1="http://DefaultNamespace" xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
    <partnerLinks>
    <partnerLink name="client" partnerLinkType="tns:CreateKBEntryService" myRole="CreateKBEntryServiceProvider"/>
    <partnerLink name="CreateKBEntryPartnerLink" partnerLinkType="nsxml0:CreateKBEntryLink" partnerRole="CreateKBEntryProvider"/>
    </partnerLinks>
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
    Java:
    import java.io.*;
    import java.util.*;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.input.SAXBuilder;
    public class sample1 {
    public static void main(String[] args) throws Exception {
    // create a XML parser and read the XML file
    SAXBuilder oBuilder = new SAXBuilder();
    Document oDoc = oBuilder.build(new File("**xml file location**"));
    Element root = oDoc.getRootElement();
    System.out.println(root.getName());
    String tgtns= root.getAttributeValue("targetNamespace");
    System.out.println("tgt ns "+ tgtns);
    List list= root.getChildren("partnerLinks");
    Iterator it1= list.iterator();
    System.out.println("Iterator 1 - "+list.size());
    while(it1.hasNext()){
    Element partnerlinks = (Element)it1.next();
    List list2= partnerlinks.getChildren("partnerLink");
    System.out.println("iterator 2 - "+list2.size());
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Result:
    Without Xmlns in xml file(Expected and correct output)
    process
    tgt ns http://serena.com/CreateKBEntryService
    Iterator 1 - 1//expected and correct result that comes when I remove xmlns attribute from xml
    iterator 2 - 2
    Result with xmlns:
    process
    tgt ns http://serena.com/CreateKBEntryService
    Iterator 1 - 0 //instead of 0 should return 1

Maybe you are looking for

  • Macbook does not recognize iphone 5s when connected using usb cable that came with charger

    I have a mac book pro Retina, 15-inch, Late 2013 and iPhone 5s. When I connect iphone to the macbook using the usb cable that came with iphone charger, macbook pro is not recognizing the iphone 5s. Does any one have any solution for the problem

  • JVM bug with Turkish locale settings (windows)

    Hello, There is a serious bug in all versions of java virtual machine. When you set your locale settings to Turkish language, you can not install & use database driven java applications (that needs to create a database). For example; you can't instal

  • Curve 9320 issue (hang problem)

    Hello, i have purchased curve 9320 3G 1 month back but i couldn't use this more than 1 day, i use to freeze frequently, after inserting sim, it was running fine for 10-12 Hrs, after than when i received incoming call, it showed me the number and cont

  • Cannot find the Realtek Wireless Driver for download

    Dear Users I had to do a Toshiba recovery and now can't access the net because i don't have the wireless driver. Can anyone help as i don't seem to be able to find the driver online ? Hope you can help

  • Urgent* Device Not Detected by Firewire

    I'm using a 20" iMac 10.4.1, FCP 5.1.4 along with the Panasonic Pv-GS250 and trying to capture footage. The camcorder is set to playback. FCP is showing Unable to Initialize. System profiler doesn't show the camcorder as being plugged in under the fi