Extracting nested element text

Hi everyone,
I have a basic question which has been on my mind for a few days now. I'd be appreciative for any assistance or advice.
I'm aiming to extract info using JDOM from all the children of 'Parent' (please see code below). Getting info/text from 'ChildOne' and 'ChildTwo' is easy, but I am having trouble extracting info out of the nested-element at 'ChildThree'.
I'd be appreciative if anyone can shed light on how to solve such a question: how to not only extract info out of ChildOne, Two but also ChildThree, knowing that ChildThree is nested.
I've playing around with instantiating an element which gets the children of 'ChildThree' and another which gets the elements of 'ChildThree/'FirstChild'... but I think there's an easier way than that!!
I've attached a code-snippet which is resembles my XML file. I'd be very appreciative for any advice.
Thanks,
p
  <Root>
    <Parent>
      <ChildOne>First</ChildOne>
      <ChildTwo>Second</ChildTwo>
      <ChildThree>
        <InnerChild>
          <First>Text</First>
          <Second>Text</Second>
          <Third>Text</Third>
        </InnerChild>
      </ChildThree>
    </Parent>
  <Root>

I reached a solution to my problem actually.
In case other people have the same problem, this is what I did; source-attached.
I made a behavior called 'displayElements' and it takes a parameter of type Element. I then made it so that for this specific element, I call the '.getChildren()' behavior such that a List is produced. This List was then saved as an Iterator and read-through iteratively.
At the end, I re-called the 'displayElements' method and passed-in the same element because that element MIGHT have inner-elements.
Anyways, enough talk. Here's my code incase other people have the same problem.
public static void displayKids(Element current) {
          //Printing the current-element and the corresponding element-text
          System.out.println(current.getName() + "\t" + current.getTextTrim());
          //Print a row of stars; increases readability
          System.out.println("********************************");
          //For the specific element, we then call 'getters' which get the
          //children for that specific element and save as type 'List'
          List<Element> children = current.getChildren();
          Iterator iterator = children.iterator();
          while (iterator.hasNext()) {
               Element child = (Element) iterator.next();
               //Recursively calling the function
               displayKids(child);
     }

Similar Messages

  • Who to query and join nested elements

    I have a table that contains a XMLTYPE Field. How do I query and join nested elements. For example I have a schema that has a PerstrenList element that holds one or more Perstren nodes.  The Perstren node will contain a RemarksList node that can contain one or more Remarks nodes.  My goal is to query all of the Remarks and join them with the information in it's parent node. Without the parent node information the remark is meaningless.  Following is a example document and desire result set. I know how to query the Perstren or the Remarks I just can not figure out how to marry the two. The query should only return the remarks joined with the parent information.
    <RasDataSet>
       <PerstrenList>
            <Perstren>
               <TPERS>A</TPERS>
               <DEPLY>B</DEPLY>
               <STRUC>5</STRUC>
               <RemarksList>
                   <REMARK>
                        <LABEL>ABC</LABEL>
                        <GENTEXT>Hello world</GENTEXT>
                   </REMARK>
                   <REMARK>
                        <LABEL>XYZ</LABEL>
                        <GENTEXT>Oracle XML</GENTEXT>
                   </REMARK>
               <RemarksList>
            </Perstren>
            <Perstren>
           <TPERS>C</TPERS>
           <DEPLY>D</DEPLY>
           <STRUC>4</STRUC>
           <RemarksList>
               <REMARK>
                    <LABEL>EFG</LABEL>
                    <GENTEXT>Database</GENTEXT>
               </REMARK>
           <RemarksList>
            </Perstren>
            <Perstren>
           <TPERS>E</TPERS>
           <DEPLY>F</DEPLY>
           <STRUC>3</STRUC>
            </Perstren>       
       <PerstrenList>
    </RasDataSet>
    desired Results
    TPERS  DEPLY   LABEL  GENTEXT
    A       B       ABC   Hello World
    A       B       XYZ   Oracle XML
    C       D       EFG   Database
    select uic,
            extractvalue(Column_value,'/Perstren/TPERS') as TPERS,
            extractvalue(Column_value,'/Perstren/DEPLY') as DEPLY,
            extractvalue(Column_value,'/Perstren/SECUR') as SECUR,
            extractvalue(Column_value,'/Perstren/STRUC') as STRUC,
            extractvalue(Column_value,'/Perstren/TIME') as TIME,
            extractvalue(Column_value,'/Perstren/AUTH') as AUTH,
            extractvalue(Column_value,'/Perstren/ASGD') as ASGD,
    from test_ref doc,
        table(XMLSequence(extract(doc.XML_DOC,'/RasDataSet/PerstrenList/Perstren'))) per
    [pre]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Sorry my Pre tag was in the wrong place Text reads:
    I have a table that contains a XMLTYPE Field. How do I query and join nested elements. For example I have a schema that has a PerstrenList element that holds one or more Perstren nodes. The Perstren node will contain a RemarksList node that can contain one or more Remarks nodes. My goal is to query all of the Remarks and join them with the information in it's parent node. Without the parent node information the remark is meaningless. Following is a example document and desire result set. I know how to query the Perstren or the Remarks I just can not figure out how to marry the two. The query should only return the remarks joined with the parent information.
    Sorry my Pre tag was in the wrong place

  • MDIS ValueX XML Structure, element TEXT not found in xml schema

    When you extract ECC Contract through MECCM using port ERP Contract Data Transmission, if your mapping isn't correct 2 exception types are created: StructuralX or ValueX (and ImportX but I haven't seen this type of exception yet).
    Anyone noticed that the structure of the XML messages are actually different? The XSD for structuralX files are the same as the files placed in the "ready" folder, where as the XSD for the valueX files are DIFFERENT, and contain a tag called <TEXT>.
    This raises an issue when we're trying to handle exceptions in Import Manager using the type Port.  We get error "Logon Error: Source file does not conform to XML Schema. Element <TEXT> not found in xml schema".
    We can process exceptions in the structuralX folder, but not in the valuex folder because the xml file structure in the valuex folder is different.
    Just wondering if anyone else has had this issue or has resolved it.  We will open message with SAP.
    Thanks.

    Hello
    What is your MDM version ?
    this issue happened in old MDM 7.1 versions but was fixed in SP-2 unless you mapped Clone fields and in this case the fix is a bit later.
    In MDM 7.1 the latest builds of SP-2 and SP-3 should have the fix for all issues. But if you use MDM 5.5 then some issues regarding XSD conversion for exception where not addressed due to technical issues.
    The workaround for MDM 5.5 (If you use a late build of SP-6 Patch-4 or SP-6 Patch-5)  is to use the original file to fix the exception and not the file in the exception folder.
    Please notice that when you have Structural exception then all the Source XML file will go to the Exception folder.
    But in case of Value Exception - The source XML file will be dropped in the archive folder and another XML file containing VXR's (Virtual Extended Records) will be dropped in the exception folder, Therefore will have a different structure.
    Hope it helps.
    Thanks.
    Best Regards.
    Yaron.

  • Sum1 Please tell me the Table to extract Cost element category (SAP ). Cost

    Sum1 Please tell me the Table to extract Cost element category (SAP ). Cost element category should be unique key?

    Hi,
    I don't see the cost element categ in CSKA (chart of account based).
    Better try CSKB (controlling area based.
    The Domain is KATYP and you can find cost element categ description in its value range
    [genereic extraction possible for these texts...]
    hope that helps...
    Olivier.
    Message was edited by:
            Olivier Cora

  • How to give error message for the screen element text field when wrong i/p

    How to give error message for the screen element text field when wrong i/p
    when wrong input given
    eg. 
    I have a text box with SBOOK-CARRID
    so when user give wrong entry in text box i.e LG
    then I should give some error stating that the the input is invalid or not available ,
    now it showing the error of standard messages,
    i want manual message to be displayed when error comes.
    Thank you,
    Regards,
    Jagrut Bharatkumar Shukla

    Hi all,
    Thank you for your valuable reply,
    but the thing is that its a screen field,
    i.e text box not a selection screen
    i created in screen layout
    with name sbook-carrid
    now i want to get error message display if wrong i/p is given
    thank you.
    Regards,
    Jagrut bharatkumar Shukla,

  • How to Extract the Highlight Text in PDF File

    Hi Scripters,
    i want know, how to extract the hightlight text in pdf files for text only format for (*.txt) file extension save.
    regards
    baby

    Hi,
    Okay i'll try do best.
    thanks for your reply.
    Regards
    Baby

  • Question about xml schemas and the use of unqualified nested elements

    Hello,
    I have the following schema:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns="http://xml.netbeans.org/examples/targetNS"
        targetNamespace="http://xml.netbeans.org/examples/targetNS"
        elementFormDefault="unqualified">
        <xsd:element name="name" type="xsd:string"/>
        <xsd:element name="age" type="xsd:int"/>
        <xsd:element name="person">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element ref="name"/>
                    <xsd:element ref="age"/>
                   <xsd:element name="height" type="xsd:int"/>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:element>
    </xsd:schema>I am just wondering why would someone have a nested element that is unqualified? here the "height" element.
    Can anyone explain this to me please?
    Thanks in advance,
    Julien.
    here is an instance xml document
    <?xml version="1.0" encoding="UTF-8"?>
    <person xmlns='http://xml.netbeans.org/examples/targetNS'
      xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
      xsi:schemaLocation='http://xml.netbeans.org/examples/targetNS file:/E:/dev/java/XML/WebApplicationXML/web/newXMLSchemaThree.xsd'>
    <name>toto</name>
    <age>40</age>
    <height>180</height>
    </person>

    Don't worry about it.
    There are two different styles of schemas. In one style, you define the elements, attributes, etc. at the top, and then use the "ref" form to refer to them. (I call this the "global" style.) The other style is to define elements inline where they are used. ("local" style)
    Within some bounds, they work the same and which you use is a choice of you and the tools that generate the schemas.
    A warning about the local style. It is possible to define an element in two different locations in the schema that are different. It will get past all schema validation, but it seems wrong to my sense of esthetics. With the global style, this will not happen.
    So, how did this happen? Probably one person did the schema when it only had a name and age. Then, someone else added the height element. They either used a different tool, or preferred the other style. I'm aware of no difference in the document you have described between the two styles.
    Dave Patterson

  • Specifying nested element with two different XML Schema

    Hello,
    I am trying to convert one xml file to another file. I figure data services would be great for this.
    My problem relates to how to have a source xml file with a certain xml schema be transformed to one of a different xml schema. I cannot build the nested elements of the target schema.
    From the source xml I only need four fields. But they need to be nested three levels in the target xml.
    Source
    <DRUG_PRODUCT_LST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <DRUG_ITEM>
          <DRUG_PRODUCT_ID>113083</DRUG_PRODUCT_ID>
          <DIN_PDIN>2317559</DIN_PDIN>
          <HC_BRAND_NAME>PMS-SILDENAFIL</HC_BRAND_NAME>
          <HC_ATC_CODE>G04BE03</HC_ATC_CODE>
       </DRUG_ITEM>
    <DRUG_PRODUCT_LST
    Target
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <CODES>
       <CODE_TYPES>
          <CODE_TYPE>
             <COD_CODE>113083</COD_CODE>
             <COD_DESCR>PMS-SILDENAFIL</COD_DESCR>
             <COD_SOURCE>G04BE03</COD_SOURCE>
             <COD_NPSA>2317559</COD_NPSA>
          </CODE_TYPE>
       </CODE_TYPES>
    </CODES>
    I have tried using an xml pipline to unnest the source, then use a query transform to re-nest for the target. But I do not know how to specify the input schemas.

    Hello,
    I am trying to convert one xml file to another file. I figure data services would be great for this.
    My problem relates to how to have a source xml file with a certain xml schema be transformed to one of a different xml schema. I cannot build the nested elements of the target schema.
    From the source xml I only need four fields. But they need to be nested three levels in the target xml.
    Source
    <DRUG_PRODUCT_LST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <DRUG_ITEM>
          <DRUG_PRODUCT_ID>113083</DRUG_PRODUCT_ID>
          <DIN_PDIN>2317559</DIN_PDIN>
          <HC_BRAND_NAME>PMS-SILDENAFIL</HC_BRAND_NAME>
          <HC_ATC_CODE>G04BE03</HC_ATC_CODE>
       </DRUG_ITEM>
    <DRUG_PRODUCT_LST
    Target
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <CODES>
       <CODE_TYPES>
          <CODE_TYPE>
             <COD_CODE>113083</COD_CODE>
             <COD_DESCR>PMS-SILDENAFIL</COD_DESCR>
             <COD_SOURCE>G04BE03</COD_SOURCE>
             <COD_NPSA>2317559</COD_NPSA>
          </CODE_TYPE>
       </CODE_TYPES>
    </CODES>
    I have tried using an xml pipline to unnest the source, then use a query transform to re-nest for the target. But I do not know how to specify the input schemas.

  • How to extract the 'display text' of the URLs?

    Hi,
    I want to extract the 'display text' of a link inside an html page? I am using HTML Toolkit class and the getAttribute method...How can i do that since the text is out of 'Attribute'. How to get this text?
    Thanx in advance

    You should try passing the input stream to a Scanner or a BufferedReader and that way you should be able to read in lines of text.
    HttpURLConnection a = null;
              URL b;
              Scanner in = null;
              try {
                   b = new URL("http://www.google.com");
                   a = (HttpURLConnection) b.openConnection();
                   in = new Scanner(a.getInputStream());
                   while(in.hasNext())
                        System.out.println(in.nextLine());
              } catch (Exception e) {
                   e.printStackTrace();
              }Edited: Something like the above.

  • Xml-fragment Issue retrieving Nested element data

    Hi,
    I've problem retrieving the nested element data from the xml. Using XmlBeans I am getting null when retriving the inner element. I printed the nested element xmlobject it has Xml-Fragment wrapped. I tired using below code it doesn't throw any error but the data is lost
    AAAA TempObj=AAAA.getBXXX().getCXXX(0);
    //remove xml fragment
    XmlOptions xmlOpt = new XmlOptions();
    xmlOpt.setSaveOuter();
    XmlCursor c= TempObj.newCursor();
    c.toFirstChild();
    Myclass myclassObj= Myclass.Factory.parse(c.getObject().xmlText(xmlOpt));
    log.debug("Records: "+myclassObj .getXXArray().length);
    Output:
    length should give aleast 1 or more but I am getting 0. That means the xmltext didn't parse properly.
    Can anybody suggest what could be the problem.
    Thanks in advance.
    -Sri

    no answer

  • How to extract the element name of an XML Document

    This is how my xml file looks like:
    <?xml version="1.0" encoding="UTF-8" ?>
    - <nsiData>
    - <instance timestamp="2011-05-25 19:01:00">
    <AECI>47.00</AECI>
    <EEI>-553.00</EEI>
    <EES>-91.00</EES>
    <EKPC>-22.00</EKPC>
    <LGEE>-140.00</LGEE>
    <MHEB>-1376.00</MHEB>
    <MISO>-4725.00</MISO>
    <MOWR>55.00</MOWR>
    <ONT>-872.00</ONT>
    <OVEC>-144.00</OVEC>
    <PJM>-1438.00</PJM>
    <SPA>-55.00</SPA>
    <SPC>20.00</SPC>
    <SWPP>69.00</SWPP>
    <TVA>-69.00</TVA>
    <WAUE>-158.00</WAUE>
    </instance>
    - <instance timestamp="2011-05-25 19:02:00">
    <AECI>47.00</AECI>
    <EEI>-555.00</EEI>
    <EES>-91.00</EES>
    <EKPC>-22.00</EKPC>
    <LGEE>-148.00</LGEE>
    <MHEB>-1375.00</MHEB>
    <MISO>-4709.00</MISO>
    <MOWR>55.00</MOWR>
    <ONT>-871.00</ONT>
    <OVEC>-144.00</OVEC>
    <PJM>-1426.00</PJM>
    <SPA>-55.00</SPA>
    <SPC>20.00</SPC>
    <SWPP>82.00</SWPP>
    <TVA>-69.00</TVA>
    <WAUE>-158.00</WAUE>
    </instance>
    </nsiData>
    I want to extract the element name and the element value from this file. I was trying to do it this way:
    SELECT datetime,
    loc.aeci_value,
    loc.eei_value
    FROM temp_xmltype txml,
    XMLTABLE ('/nsiData' PASSING xmldata) misolmp,
    XMLTABLE ('/nsiData/instance' PASSING misolmp.object_value
    COLUMNS
    datetime VARCHAR2(100) PATH '/instance/@timestamp') misodt,
    XMLTABLE ('/nsiData/instance' PASSING misolmp.object_value
    COLUMNS
    aeci_value VARCHAR2(100) PATH '/instance/AECI',
    eei_value VARCHAR2(100) PATH '/instance/EEI') loc
    WHERE txml.feed_id = 127
    But doing it this way does not get me AECI as a column value. Is there any way to get the element name as a column value.
    I am on 11gR2

    The SQL statement you wrote returns 4 rows and there is only two AECI values in there. The corrected version of what you wrote should really be
    SELECT loc.datetime,
           loc.aeci_value,
           loc.eei_value
      FROM temp_xmltype txml,
           XMLTABLE ('/nsiData/instance' PASSING txml.xmldata
                     COLUMNS
                     datetime   VARCHAR2(100) PATH '@timestamp',
                     aeci_value VARCHAR2(100) PATH 'AECI',
                     eei_value  VARCHAR2(100) PATH 'EEI') loc
    WHERE txml.feed_id = 127;If you know the element name and want it returned as a column name, why not just hard code it in the SQL statement, such as
    SELECT loc.datetime,
           'AECI' as AECI,
           loc.aeci_value,
           'EEI' AS EEI,
           loc.eei_value
      FROM temp_xmltype txml,
           XMLTABLE ('/nsiData/instance' PASSING txml.xmldata
                     COLUMNS
                     datetime   VARCHAR2(100) PATH '@timestamp',
                     aeci_value VARCHAR2(100) PATH 'AECI',
                     eei_value  VARCHAR2(100) PATH 'EEI') loc
    WHERE txml.feed_id = 127;I suspect you are really looking for something like {message:id=9535532}
    Note: See the FAQ (under your sign-in name) for how to use the code tag to format code as shown above.

  • API extracting keywods from text files

    hi all,
    i will be grateful if any of you can suggest some free java api which can be used to extract keywords from text files.
    thanx in advance
    malls

    java.util.regex - regular expressions API in JDK 1.4

  • Post Element Text

    Hi,
    I'd like to use JavaScript to add some post element text to some form items that is based on the content of the form item.
    I know that I could just add some extra items on my page and condition them but I'm keen to avoid this as I don't want to clutter the page with too many items. I'd rather just have post element text that I can condition in some way.
    Any ideas how I'd do this?
    Cheers
    Yog

    Hello,
    Just add something like this. To your post element attribute
    &lt;span id="after_#CURRENT_ITEM_NAME#">&lt;/span>
    and lets say your item name is
    HELLO
    you javascript should look like this
    $x('after_HELLO').innerHTML = 'After Hello';
    or
    html_GetElement('after_HELLO').innerHTML = 'After Hello';
    Carl
    Message was edited by:
    Carl Backstrom

  • Post Element Text - Checkbox

    Apex 4.0.2
    Suppose I use the Post Element Text attribute of a page item to render a checkbox using <input type="checkbox" .... and a dynamic action to save its state to a database table. I am sure this will work fine but when the page loads how do I go about setting the value of all these checkboxes?
    Any ideas? Thanks

    Hello Vikas,
    >> I am sure this will work fine but when the page loads how do I go about setting the value of all these checkboxes?
    The trick is to use a checkbox that has the same ID and value. Remember that only checked checkboxes are submitted to the server. You can look at the following for a simple example:
    http://htmldb.oracle.com/pls/otn/f?p=52616:30
    Now for some code. I’m using the following as the post-element content for the first checkbox:
       <input type="checkbox" name="f50" id="CB1" value="CB1">Option 1<br />The HTML name will remain the same for all checkboxes; however, the ID and value should be different for each extra checkbox (e.g. CB2, CB3m etc.). In this example, the checked checkboxes will be populated, at submit time, into the G_F50 array. Of course, you can use any other available G_Fxx array.
    I’m using the following table to save the checkboxes state:
    CREATE TABLE  "CB_STATE"
       (     "PAGE" NUMBER(4,0) NOT NULL ENABLE,
         "VALUE" VARCHAR2(4) NOT NULL ENABLE
       ) ;For saving the checkboxes state, I’m using the following after submit PL/SQL process:
    delete from cb_state
    where page = :APP_PAGE_ID;
    for i in 1..apex_application.g_f50.count loop
      insert into cb_state
      values(:APP_PAGE_ID, apex_application.g_f50(i));
    end loop;For setting the checkboxes state, while rendering the page, I’m using the following Before Footer PL/SQL process:
    htp.p('<script type="text/javascript">');
    for x in (select * from cb_state
              where page = :APP_PAGE_ID) loop
      htp.p('$x('''||x.value||''').checked = true;');
    end loop;
    htp.p('</script>');I’m sure you can translate the last snippet of code to a Dynamic Action. If you do, please post it in here.
    Regards,
    Arie.
    &diams; Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.
    &diams; Author of Oracle Application Express 3.2 – The Essentials and More

  • Post-element text with computed value

    I have a page item (P10_X) with post-element text referencing a application level item using &G_ITEM. notation. G_ITEM is computed on the page and the computation needs to take into account the value of P10_X so the firing point is "after footer".
    This leads to a Catch-22 because the item and post-element text is rendered before the computation so the value of G_ITEM is not accurate.
    Any ideas? Thanks

    Not sure I understand. Suppose P10_X=10 when it is rendered. G_ITEM is computed as :P10_X (i.e. 10) + (select ...). The post-element text for P10_X refers to &G_ITEM. so it uses the "stale" value of G_ITEM; the latest value is not computed until after all regions are rendered.
    Edit: Turns out that P10_X obtains it value in an Before Header application process, not via its Source attribute. So I can put the computation for G_ITEM at the After Header point and so everything gets computed and rendered properly.
    Edited by: Vikas2 on Jul 14, 2009 4:05 PM

Maybe you are looking for

  • Can i use an app specific password on multiple macs

    Simple question. I have so far set up 3 app specific passwords.   I have an iMac and an Macbook Air.    I also have an iPad and iPhone.   I have set up the app specific password for Fantastical, which runs on all devices, and BusyContacts.   Do I nee

  • To find which reports uses the tables MKFP & MSEG

    Hi Experts, I have a list predeof reports. I just want to know if these reports uses the table MKFP & MSEG. Is there any predefined function or report available in order to find this one? Valuable answers will be rewarded. Thanks, Satish.

  • Customized AR Statements

    I need to customize the standard AR statements that are produced by ARXSGPO. I've read up on all the xml stuff that's on the forum. But my situation is a little unique. I need to actually customize the content of the statements a little. I have an id

  • How to get current assigned participant id?

    Hi mates, This might be a basic questions, but useful for me :) How to get current assigned participant id from screenflow? Or How to pass it as an argument from interactive activity? Below is what I tried. Participant.id or Instance.participant.id -

  • How to pick dates using Datenavigator UI element.

    Hello, If I use DateNavigator UI element and if I select first date and last date how do i get all the dates in that period. Regards, Rahul