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

Similar Messages

  • 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 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.

  • How to handle children of custom component

    Hi,
    does anybody know an example of how to develop a custom UIComponent which is able to render any kind of child? For example:
    <x:mycomponent columns="3" valu="#{list-of-items} var="item">
    <h:graphicImage url="#{item.url}/>
    <h:selectBooleanCheckbox />
    </x:mycomponent>
    The result should be a table with 3 columns where each table-cell contains the result of the rendering process of its children, in this case a picture with a checkbox.
    I have tried it and managed to get the correct html-result. But I do not get the input of the checkbox if the above code snippet is a part of a html-form.
    So what I realy like to have is the sourcecode of some kind of UIComponent which does something like this.
    Kind Regards,
    Tobias

    Thanks for the swift reply Craig
    My custom component has 3 elements hence the currentTarget
    could be either the folder icon, the status icon or the text field.
    Is there some way of finding the parent of which ever of
    these sub items of the cusom component is clicked?
    Here is the code for my custom component
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Canvas xmlns:mx="
    http://www.adobe.com/2006/mxml"
    width="240" height="60" cornerRadius="15" borderStyle="none"
    backgroundColor="#ffffff" themeColor="#ff0000">
    <mx:Script>
    <![CDATA[
    [Bindable]
    public var studentName:String ="Student Name";
    ]]>
    </mx:Script>
    <mx:Text x="64" y="24" text="{studentName}" />
    <mx:SWFLoader x="10" y="10" width="32" height="24"
    source="@Embed('assets/folderIcon.swf')" />
    <mx:SWFLoader x="19" y="42" width="11" height="11"
    source="@Embed('assets/cfStatusIcon.swf')" />
    </mx:Canvas>

  • Handle  text  using list box in dialog program

    hi,
      I am  working  on  dialog program  , Created  two fileds , one is list  box type  I/O field and another is  i/O  field  which displays  text  based  on  value  selected in list box.
    Please  provide  any  inf  how  to Handle  text  using list box value in dialog program.
    thanks

    Hi,
    <li>Check the screen to know how to set I/O field to set as listbox.[ dropdown box picture|http://2.bp.blogspot.com/_O5f8iAlgdNQ/Sm7RBrqfjcI/AAAAAAAAFaU/RateViiVqrU/s1600-h/drop_down-754481.JPG]
    <li>in the above screen we need to set FctCode  for the dropdown box field so that when you select value from the dropdown box PAI event is triggered.
    <li>screen flow logic like below
    PROCESS BEFORE OUTPUT.
    MODULE values_into_dropdown.
    FIELD g_bukrs.
    FIELD g_text.
    PROCESS AFTER INPUT.
    FIELD g_bukrs.
    FIELD g_text MODULE get_bukrs_txt.
    <li>Logic to fill Dropdown field with values.
      PROGRAM  sapmztest_dropdown.
    DATA: g_bukrs TYPE t001-bukrs.
    *&      Module  VALUES_INTO_DROPDOWN  OUTPUT
    MODULE values_into_dropdown OUTPUT.
    TYPE-POOLS:vrm.
    DATA:
           field     TYPE  vrm_id,
           it_values TYPE  vrm_values,
           wa_values LIKE LINE OF it_values.
    DATA: t001 TYPE t001 OCCURS 0 WITH HEADER LINE.
    IF it_values[] Is INITIAL.
       SELECT * FROM t001 INTO TABLE t001 UP TO 10 ROWS.
       LOOP AT t001.
         wa_values-key  = t001-bukrs.
         wa_values-text = t001-butxt.
         APPEND wa_values TO it_values.
         CLEAR  wa_values.
       ENDLOOP.
    ENDIF.
    field = 'G_BUKRS'.
    CALL FUNCTION 'VRM_SET_VALUES'
       EXPORTING
         ID     = FIELD
         values = it_values.
    ENDMODULE.                 " VALUES_INTO_DROPDOWN  OUTPUT
    *&      Module  get_bukrs_txt  INPUT
    MODULE get_bukrs_txt INPUT.
    read table it_t100 into wa_t100 with key bukrs = g_bukrs.
    g_text = t001-butxt.
    ENDMODULE.                 " VALUES_INTO_DROPDOWN  INPUT
    I hope that it helps you.
    Thanks
    Venkat.O

  • How do i parse this, using JDOM?!

    This xml is in the form of a String, can someone tell me how to use JDOM to parse this, i've actually made a start:
    SAXBuilder builder = new SAXBuilder();
    Reader r = new StringReader(str1);
    Document doc = builder.build(r);
    <StockQuotes>
    <Stock>
    <Symbol>IBM</Symbol>
    <Last>111.32</Last>
    <Date>8/1/2007</Date>
    <Change>+0.67</Change>
    <Open>110.39</Open>
    <High>111.95</High>
    <Low>110.06</Low>
    </Stock>
    </StockQuotes>
    and then im kinda lost... please help! really need it!
    cheers,
    Shivek Sachdev

    hey,
    thanks a lot for the reply.
    i get the idea now, to be able to trace to the childrens
    but it would be really helpful if u can give me a more complete version of the code, im really new to this stuff.
    i did wat u told:
    List stock = root.getChildren();
    //now im at the 2nd level
    how do i get to <Symbol> so that i can print out the value of that tag.
    cheers,
    Shivek Sachdev

  • How do I get values from a resultset using JDOM?

    I am very new to this and I dont have the slightest idea how to retrive values from a result and create a XML tree using JDOM
    Can someone please help me?
    I have the JDOM Parser installed on my machine.
    This is my code so far:
    import org.jdom.input.*;
    import org.jdom.*;
    import java.sql.*;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class Display extends HttpServlet {
    public void doPost(HttpServletRequest rq, HttpServletResponse rs) throws IOException, ServletException
    rs.setContentType("text/html");
    PrintWriter out = rs.getWriter();
    try {
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         Connection listcars_con = DriverManager.getConnection("jdbc:odbc:Cars");
         Statement listcars_statement = listcars_con.createStatement();
         ResultSet listcars_rs = listcars_statement.executeQuery("Select CarNr FROM cars");
    //Load the appropriate driver, establish a connection and create a statement which is used to execute the query that returns all the
    //columns from the cars table
    Document doc = new Document(new Element("rootElement"));
              listcars_statement.close();
              listcars_con.close();
    //close the connections
    catch (ClassNotFoundException cnfe)
    System.err.println(cnfe);
    } catch (SQLException sqlex) {
    System.err.println(sqlex);
    } catch (Exception er) {
    er.printStackTrace();
    } //closing bracket for doPost method
    } //closing bracket for class definition

    ResultSet object has nothing to do with XML... so the only way to it
    is just read each row/column in your resultset and then create
    XML record based on structure of your resultset - annoying job...
    Also you can try to use tool developed by Oracle which based
    on SQL select statement parses resultset into XML...
    Paul

  • How to handle rpc/encoded style messages using BizTalk?

    I am integrating with a lot of services and one of our customers has a service with rpc/encoded style
    I could consume and generate schema from their wsdl file via BizTalk consume WCF wizard.
    Once I am trying to call the service with request message that generated from the schema, it is giving an error that can not desterilize the first element of the message. 
    No Deserializer found to deserialize a 'FieldName' using encoding style 'null'
    I compared the stub xml request message from SaopUI and I noticed that the xml expecting the data type with the element like this .
    <soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsb="WSBanka">
    <soapenv:Header/>
    <soapenv:Body>
    <wsb:bnkBorcsorgulama soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <sozlesmeNo xsi:type="xsd:string">?</sozlesmeNo>
    <bankaKodu xsi:type="xsd:string">?</bankaKodu>
    <anahtar xsi:type="xsd:string">?</anahtar>
    </wsb:bnkBorcsorgulama>
    </soapenv:Body>
    </soapenv:Envelope>
    On the other hand, I got the request of the message from Fiddler using the BizTalk , and the generate xml of the BizTalk schema without the data type.
    <soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsb="WSBanka">
    <soapenv:Header/>
    <soapenv:Body>
    <wsb:bnkBorcsorgulama>
    <sozlesmeNo>?</sozlesmeNo>
    <bankaKodu>?</bankaKodu>
    <anahtar>?</anahtar>
    </wsb:bnkBorcsorgulama>
    </soapenv:Body>
    </soapenv:Envelope>
    In SoapUi, if I remove a datatype from the message, I will get same error from the BizTalk request.
    I read some articles that rpc/encoded style are not supported but I am not sure and these articles are not clear.
    I also read that it was supported with Soap adapter but now it is deprecated.
    So, Is there any one has an experience in rpc/encoded style messages and how to handle these message in BizTalk or is there any work around to handle these messages?
    Your inputs really appreciate it.
    Thanks in advance,
    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer

    Hi,
    Please refer to the document which might help you:
    #RPC/Encoded Style
    http://www.c-sharpcorner.com/UploadFile/martinkropp/DesigningInteroperableWebService11232005044847AM/DesigningInteroperableWebService.aspx

  • How to handle the Exception in GP using executable callabel object.

    Hi all,
            I handled an exception in GP using Background callable Object. That is working fine.
    (Ex: Exception_No_User_Found). The Problem is I am not able to handle the exceptions for normal callable object. I have done the same thing as i did in background callable object except implementing IGPBackgroundCallableObject Class.  I have created an WebDynpro DC Project where in getDescription method i declared an Exception and in execute method of component controller I caught the exception if no user found.
    Then i created an callable object for this simple DC project. but that is not working i could not catch the exception. when i execute the process it is asking the User ID if i give the wrong userId it is not refreshing back to the user id input form.
    But if i test that simple callable object separately it is throwing an Exception when I give the wrong input..
    but the same thing is working fine using background callable object.
    I couldn't handle the exception for the simple callable object or executable callable object.
    Please If anyone bring me the solution that would be appreciated.
    Thanks in advance.
    Regards,
    Malar.

    Hi Shikhil
    Thanks for your reply
    Please have a look below for exceptions which i am getting in GP and let me know how to handle these exceptions.
    1) "Activity could not be read"
    2) "Action has been stopped"
    3) error while processing the item can not be displayed
    if you give any idea/clue how to handle these exceptions then it would be great help to me
    Thanks
    Sunil

  • How to get the "encoding" of a XML file using JDOM

    As in XML file, <?xml version="1.0" encoding="UTF-8" ?> indicates the encoding of this file
    while using JDOM to parse a XML file, how can I get the encoding type?
    thanx!!!

    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!!!

  • How to handle error while using dbms_sql.execute

    Hi,
    I am inserting some records by using the following piece of code.
    stmt := 'insert into SSI_KPI_GOAL_VALUE_H (KPI_VAL_KPI_ID, KPI_VAL_RM_CDE,'|| v_day_value ||',KPI_VAL_ACT_DLY,'||v_month_val||',KPI_VAL_BIZ_UNIT_CDE) values (:kpi_array,:rm_array,:day1_array,:day1_array,:day1_array,:busnunit_array)';
    l := dbms_sql.open_cursor;
         dbms_sql.parse(l, stmt, dbms_sql.native);
         dbms_sql.bind_array(l, ':kpi_array', col1_ins,1,ins_cnt-1);
         dbms_sql.bind_array(l, ':rm_array', col2_ins,1,ins_cnt-1);
         dbms_sql.bind_array(l, ':day1_array', col3_ins,1,ins_cnt-1);
         dbms_sql.bind_array(l, ':busnunit_array', col4_ins,1,ins_cnt-1);     
         dummy := dbms_sql.execute(l);
         dbms_sql.close_cursor(l);
    I am getting an error since any one of the row contains value larger than the column.
    How to handle exception handling for those rows which is having errors. I would like insert the records which is having
    no errors. Like SAVE EXCEPTIONS for 'forall' is there any option is available to handle exceptional records.
    Please help.
    Thanks & Regards,
    Hari.

    Hari,
    What's oracle version? Are you looking for something similar to this? see following example
    DECLARE
       TYPE array
       IS
          TABLE OF my_objects%ROWTYPE
             INDEX BY BINARY_INTEGER;
       data          array;
       errors        NUMBER;
       dml_errors exception;
       error_count   NUMBER := 0;
       PRAGMA EXCEPTION_INIT (dml_errors, -24381);
       CURSOR mycur
       IS
          SELECT *
          FROM t;
    BEGIN
       OPEN mycur;
       LOOP
          FETCH mycur BULK COLLECT INTO data LIMIT 100;
          BEGIN
             FORALL i IN 1 .. data.COUNT
             SAVE EXCEPTIONS
                INSERT INTO my_new_objects
                VALUES data (i);
          EXCEPTION
             WHEN dml_errors
             THEN
                errors        := sql%BULK_EXCEPTIONS.COUNT;
                error_count   := error_count + errors;
                FOR i IN 1 .. errors
                LOOP
                   DBMS_OUTPUT.put_line(   'Error occurred during iteration '
                                        || sql%BULK_EXCEPTIONS(i).ERROR_INDEX
                                        || ' Oracle error is '
                                        || sql%BULK_EXCEPTIONS(i).ERROR_CODE);
                END LOOP;
          END;
          EXIT WHEN c%NOTFOUND;
       END LOOP;
       CLOSE mycur;
       DBMS_OUTPUT.put_line (error_count || ' total errors');
    END;Regards
    OrionNet

  • How to handle system errors in XI using BPM? please help!

    Hi Experts,
         I have a requirement where I have to handle system errors. For example when I am making RFC call using RFC adapter if the remote destination is down then I have create a understandable error message and store it in another SAP table.
    How to handle it? I am using BPM. I can see that there is "Exceptions" in the send step. How to use this?
    Thanks
    Gopal

    Hi Gopalkrishna,
    In this case whenever you get Mapping Exception , you can raise an Exception with the help of BPM and you can send the status to the RFC. But with the help of BPM.
    For a Simple case refer:
    http://help.sap.com/saphelp_nw2004s/helpdata/en/33/4a773f12f14a18e10000000a114084/frameset.htm
    If you want you can do it without a BPM
    and throw an exception in case any of the values is missing:
    have a look at this weblog on how to throw exceptions
    in a nice way:
    /people/alessandro.guarneri/blog/2006/01/26/throwing-smart-exceptions-in-xi-graphical-mapping
    Also just go through <a href="/people/sap.user72/blog/2005/02/23/raising-exceptions-in-sap-xi-mapping Exceptions in SAP XI Mapping</a> and see if it helps you solve the problem.
    Also go through these links:
    http://help.sap.com/saphelp_nw04/helpdata/en/dc/6b7f2243d711d1893e0000e8323c4f/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/68/253239bd1fa74ee10000000a114084/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/cf/f2bbc8142c11d3b93a0000e8353423/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/5d/2166e6a91d11d188de0000e8216438/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/05/bb223905b61b0ae10000000a11402f/content.htm
    Please do let know if it helped.
    Regards,
    Abhy

  • How to handle HTTP-POST encrypted data for ECC Using proxy or RFC

    I have a scenario HTTP-POST ->PI->ECC.sender is HTTP Post  send encrypted data i need to handle the data and stored in to SAP ECC  with out decrypt using PI .what should i take for receiver  can i use inbound proxy or RFC  and how can handle the encrypted data  for decrypt.
    Regards
    Ravi

    1. my sender is HTTP POST . what should i configure in sender communication channel in SAP PI .like SOAP or HTTP .What are the parameters i need to pass .
    >>>
    If you are on PI 7.3 and above, configure the HTTP AAE adapter - Configuring the Java HTTP Adapter on the Sender Channel - Advanced Adapter Engine - SAP Library
    2.while using inbound proxy for encrypted data  i need  store the data in to table , the same proxy can i call  another outbound  service for decrypt  same data.
    >>>>
    Yes you can always a proxy within a proxy.

  • I bought a cd with Lightroom 5. After installation and registration I am not able to use 'help' function and I cannot update the software. I anyone able to give me a hint how to handle it? Thank you ind advance Karl

    I bought a cd with Lightroom 5. After installation and registration I am not able to use 'help' function and I cannot update the software. Is anyone able to give me a hint how to handle it?
    Thank you in advance
    arl

    Hi Keith, sorry for my late reply.
    Surely I am able to connect to the help function when Icontact the website
    of AdobeLR5.The problem is as follows,
    When I open LR5 on my computer and work with it and try to open the help
    function in the software, I don't get it.
    When I bought the CD I was naiv enough to believe that I get an independent
    working software. I learned in the meantime, that the seller does not allow
    to work with, without being connected to them.
    I don't believe that I am paranoid, but I like to buy something and use it
    without to inform the supplier that I do it. Otherwise I could have bought
    the license fpr LR5 via internet.
    Best regards
    Karl
    2015-01-02 13:42 GMT+01:00 kglad <[email protected]>:
        I bought a cd with Lightroom 5. After installation and registration I
    am not able to use 'help' function and I cannot update the software. I
    anyone able to give me a hint how to handle it? Thank you ind advance Karl
    kglad <https://forums.adobe.com/people/kglad?et=watches.email.outcome>
    marked Keith_Reeder
    <https://forums.adobe.com/people/Keith_Reeder?et=watches.email.outcome>'s
    reply on I bought a cd with Lightroom 5. After installation and
    registration I am not able to use 'help' function and I cannot update the
    software. I anyone able to give me a hint how to handle it? Thank you ind
    advance Karl
    <https://forums.adobe.com/thread/1669640?et=watches.email.outcome> as
    helpful. View the full reply
    <https://forums.adobe.com/message/7059196?et=watches.email.outcome#7059196>

  • How to handle  user exits while using BAPI

    HI experts can any one help me on how to handle user exits while using BAPI. Do we need to handle it explicitly or standard  BAPI will take care of it??.
    Regards,
    Hari Krishna

    If you have added some fields using append structures for screen enhancements, then you have to use appropriate user exits to fill these data while calling BAPI.  Some BAPIs have EXTENSION structures to fill the custom data which can be processed using user exists or enhancements.
    Regards
    Vinod

Maybe you are looking for