How to extract elements from a document

I'm new to Java and I'm using JDOM in a JSP page. I've a document like this:
<OFFERTA>
<FACOLTA idFacolta="F1">
<CORSO value="xxx"/>
<CORSO value="yyy"/>
</FACOLTA>
<FACOLTA idFacolta="F2">
<CORSO value="zzz"/>
</FACOLTA>
<FACOLTA idFacolta="F3">
</FACOLTA>
<FACOLTA idFacolta="F4">
</FACOLTA>
</OFFERTA>
I'd like to get a document with the same structure but with the only FACOLTA elements that match a requested value for the idFacolta attribute.
For example, if the requested idFacolta is "F2", I'd like to get:
<OFFERTA>
<FACOLTA idFacolta="F2">
<CORSO value="zzz"/>
</FACOLTA>
</OFFERTA>
I check in a loop if the element matches the idFacolta requested but when I find and try to delete it I get:
java.util.ConcurrentModificationException
     at org.jdom.ContentList$FilterListIterator.checkConcurrentModification(ContentList.java:1230)
     at org.jdom.ContentList$FilterListIterator.hasNext(ContentList.java:942)
Here's my code:
Document doc = builder.build(file);
Element root = doc.getRootElement();
List children = root.getChildren();
Iterator facoltaIterator = children.iterator();
// Check if there's a request
if (id!=null) {
     while (facoltaIterator.hasNext()) {
          Element facolta = (Element) facoltaIterator.next();
          if (!facolta.getAttribute("idFacolta").getValue().equalsIgnoreCase(id)) {
               // Delete
               root.removeContent(facolta);
All seems to be right, except the line
root.removeContent(facolta);
So, I tried to make a new document for the results, adding the element facolta:
Document doc = builder.build(file);
Element root = doc.getRootElement();
// Create a new document with the same root
Element rootRisultati = new Element("OFFERTA");
Document docRisultati = new Document(rootRisultati);
List children = root.getChildren();
Iterator facoltaIterator = children.iterator();
if (id!=null) {
     while (facoltaIterator.hasNext()) {
          Element facolta = (Element) facoltaIterator.next();
          if (facolta.getAttribute("idFacolta").getValue().equalsIgnoreCase(id)) {
               // Add the element to the new document
               rootRisultati.addContent(facolta);
but this causes a different exception:
org.jdom.IllegalAddException: The element already has an existing parent "OFFERTA"
     at org.jdom.ContentList.add(ContentList.java:190)
     at org.jdom.ContentList.add(ContentList.java:146)
     at java.util.AbstractList.add(AbstractList.java:84)
     at org.jdom.Element.addContent(Element.java:1062)
I'm not able to find a solution.
There's a commonly used procedure to select elements maintaing the structure of the document?
Can anyone help please? Thanks in advance.
Stefano

maybe you could try posting this in a JDOM forum? JDOM is not a standard XML tool from Sun / for Java... therefore out of the scope of this forum!

Similar Messages

  • Extract element from PDF document from automatized process

    Hi
    I have never worked on PDF document and I am looking a solution for :
    extracting elements (simply text in a first time) in a PDF document in paragraph and/or in table
    after this I could manipulated them in another processing
    Have you any idea or information about my need (what should be the best way for doing this ?)
    SDK package : possible for doing this, if yes : which one ?
    another solution than SDK package
    PDF version supported : latest ones ?
    any advice about best developpement language : java (I prefer), or other ?
    Thanks for all you advices !!!
    Lst

    Well, if you want Java - then Adobe only has server-side options for you. We don't offer desktop Java APIs.  Our server-side options are part of the Adobe LiveCycle family of products.
    For client-side, we have the Adobe Acrobat SDK (which also requires Adobe Acrobat to be installed) or the PDFLibrary SDK (for stand-alone applications).  Both are C/C++ based.

  • How to extract elements from an HTML page?

    Hi:
    If we have the following returned page which is the web query result from a library: http://library.fsi.uiuc.edu/dbtw-wpd/exec/dbtwpub.dll?XC=%2Fdbtw-wpd%2Fexec%2Fdbtwpub.dll&BU=http%3A%2F%2Flibrary.fsi.uiuc.edu%2Fdbtw-wpd%2FnewWeb%2Fauthor.asp&submit=Submit+Query&QB0=AND&QF0=Author&QI0=william&QB1=AND&QF1=Corporate+Author&QI1=&MR=20&TN=Catalog&DF=Display-Web&RF=Brief+Title+-+Web&DL=1&RL=1&NP=1&AC=QBE_QUERY
    If we want to store all the returned information in the local memory,
    how can Java be used to extract the records out of the html page?
    What kind of classes should be used?
    For example, should I just use regular expression to do this (java.util.regex class),
    build-in html parser (javax.swing.text.html.parser.Parser, or even javax.swing.text.html.HTMLEditorKit.Parser), or any other classes? Thanks.

    I been working on a simular project but i might not be using a method that you would want.
    I am reading the webpage code and then getting the data by looking for certain words. The problem with this is that it is reading the page "blindly" so it could read the wrong data or screw up on an error on the page. but here is a bit of code i am using. I am using ti to get data that appears in " " (quotes) so i can get urls, images, etc
    This code isnt totaly mine, i amended it from some one and dont know the original owner :(
    try {
            is =                    new BufferedInputStream(new URL(jTextField1.getText()).openStream());
          while ((record = is.read()) != -1) {
            buffer.append((char) record);
            length++;
            System.out.print((char)record);
          }     is.close();
    } catch // error management herei am using a seperate thread running at same time to enter data
    do {
            while (lengthposition != length) {
              //System.out.print(buffer.charAt(lengthposition));
              temp[0] = "" + buffer.charAt(lengthposition);
              if (buffer.charAt(lengthposition) != /*34*/64 && tolist == true)
                temp[1] += ""+ buffer.charAt(lengthposition);
              else if (buffer.charAt(lengthposition) == /*34*/64 && tolist == false)
                tolist = true;
              else if (buffer.charAt(lengthposition) == /*34*/64 && tolist == true) {
                tolist = false;
                list1.addItem(temp[1]);
                temp[1] = "";
              lengthposition++;
          } while (buffer.charAt(lengthposition) != 32);I hope you find out a solution to your problem :)

  • How to extract the actual XML document from soap message?

    My problem is " how to extract the actual XML document from soap message? "
    i just want to extract the attachment i.e. (pure XML document without any soap header or envolope).
    i could be ver thank full if u could solve my problem.
    [email protected]

    Hi,
    This is some skeleton code for extracting an attachment from a SOAPMessage.
    import javax.activation.DataHandler.;
    import javax.xml.soap.*;
    import javax.xml.message.*;
    Iterator allAttachments = message.getAttachments();
    AttachmentPart ap1 = null;
    while(allAttachments.hasNext()){
    ap1 = (AttachmentPart)allAttachments.next();
    //Check that the attachment is correct one. By looking at its mime headers
    //Convert the attachment part into its DOM representation:
    if(ap1.getContentType() == "text/xml"){
    //Use the activation dataHandler class to extract the content, then create a StreamSource from
    //the content.
    DataHandler attachmentContent = ap1.getDataHandler();
    StreamSource attachmentStream = new StreamSource(attachmentContent.getInputStream());
    DOMResult domAttachment = getDOMResult(attachmentStream);
    domAttachment holds an xml representation of the attachment.
    Hope this helps.

  • How to extract data from SAP in FDM 11121

    I came across some documents from version 11113, says there is a SAP adapter, however ,when I check 11121 there's no such adapter, does anyone know how to extract data from SAP in FDM 11121?

    I download a package from Bristlecone, but I dont see any xml files in it, just a bunch of dll and I didn't find any instructions on how to set up/configure in FDM, it just explained how to register in SAP app server and client.
    Hyperion 11113 has readme on sap adapter(Hyperion Readme Template), but I cannot find the same readme file in 11121, all I can find is ERP Integration Adapter document. any idears where I can find at least a readme document?

  • How to extract data from planning book

    nu t apo. need help regarding how to extract data from planning book givn the planning book name , view name & some key figures.
    Total Demand (Key Figure DMDTO):
    o     Forecast
    o     Sales Order
    o     Distribution Demand (Planned)
    o     Distribution Demand (Confirmed)
    o     Distribution Demand (TLB-Confirmed)
    o     Dependent Demand
    Total Receipts (Key Figure RECTO):
    o     Distribution Receipt (Planned)
    o     Distribution Receipt (Confirmed)
    o     Distribution Receipt (TLB-Confirmed)
    o     In-Transit
    o     Production (Planned)
    o     Production (Confirmed)
    o     Manufacture of Co-Products
    Stock on Hand (Key Figure STOCK):
    o     Stock on Hand (Excluding Blocked stock)
    o     Stock on Hand (Including Blocked stock)
    In-Transit Inventory (Cross-company stock transfers)
    Work-in-progress (Planned orders / Process orders with start date in one period and finish date in another period)
    Production (Planned), Production (Confirmed) and Distribution Receipt elements need to be converted based on Goods Receipt date for projected inventory calculation.

    Hello Debadrita,
    Function Module BAPI_PBSRVAPS_GETDETAIL2 or BAPI_PBSRVAPS_GETDETAIL can help you.
    For BAPI BAPI_PBSRVAPS_GETDETAIL, the parameters are:
    1) PLANNINGBOOK - the name of your planning book
    2) DATA_VIEW - name of your data view
    3) KEY_FIGURE_SELECTION - list of key figures you want to read
    4)  SELECTION - selection parameters which describe the attributes of the data you want to read (e.g. the category or brand). This is basically a list of characteristics and characteristic values.
    BAPI_PBSRVAPS_GETDETAIL2 is very similar to BAPI_PBSRVAPS_GETDETAI but is only available from SCM 4.1 onwards.
    For the complete list of parameters, you can go to transaction SE37, enter the function module names above and check out the documentation.
    Please post again if you have questions.
    Hope this helps.

  • How to Extract data from Oracle DB to BW via DBConncet interface.

    HI All,
    Do you know how to extract data from ORACLE data base to BW, using DBConnect.
    Here we are not using R/3 Business content structures.
    How to do it in both source system  and BW side?
    How to define structures on both sides.
    Please provide any documents on that.
    Thanks in Advance.
    Sri.

    Hi Srilaxmi
    Have a look at these links
    http://help.sap.com/saphelp_nw04/helpdata/en/58/54f9c1562d104c9465dabd816f3f24/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/a1/89786c3df35c4ea930a994e884bb4c/content.htm
    http://help.sap.com/saphelp_bw30b/helpdata/en/80/1a618ae07211d2acb80000e829fbfe/content.htm
    and  this thread
    Extract from Oracle View with DB connect
    regards
    KR

  • How to extract text from a PDF file?

    Hello Suners,
    i need to know how to extract text from a pdf file?
    does anyone know what is the character encoding in pdf file, when i use an input stream to read the file it gives encrypted characters not the original text in the file.
    is there any procedures i should do while reading a pdf file,
    File f=new File("D:/File.pdf");
                   FileReader fr=new FileReader(f);
                   BufferedReader br=new BufferedReader(fr);
                   String s=br.readLine();any help will be deeply appreciated.

    jverd wrote:
    First, you set i once, and then loop without ever changing it. So your loop body will execute either 0 times or infinitely many times, writing the same byte every time. Actually, maybe it'll execute once and then throw an ArrayIndexOutOfBoundsException. That's basic java looping, and you're going to need a firm grip on that before you try to do anything as advanced as PDF reading. the case.oops you are absolutely right that was a silly mistake to forget that,
    Second, what do the docs for getPageContent say? Do they say that it simply gives you the text on the page as if the thing were a simple text doc? I'd be surprised if that's the case.getPageContent return array of bytes so the question will be:
    how to get text from this array? i was thinking of :
        private void jButton1_actionPerformed(ActionEvent e) {
            PdfReader read;
            StringBuffer buff=new StringBuffer();
            try {
                read = new PdfReader("d:/getjobid2727.pdf");
                read.getMetaData();
                byte[] data=read.getPageContent(1);
                int i=0;
                while(i>-1){ 
                    buff.append(data);
    i++;
    String str=buff.toString();
    FileOutputStream fos = new FileOutputStream("D:/test.txt");
    Writer out = new OutputStreamWriter(fos, "UTF8");
    out.write(str);
    out.close();
    read.close();
    } catch (Exception f) {
    f.printStackTrace();
    "D:/test.txt"  hasn't been created!! when i ran the program,
    is my steps right?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to extract text from a PDF file using php?

    How to extract text from a PDF file using php?
    thanks
    fabio

    > Do you know of any other way this can be done?
    There are many ways. But this out of scope of this forum. You can try this forum: http://forum.planetpdf.com/

  • How to delete elements from a cluster?

    Hello. I would like to know how to delete elements from a cluster. I got stuck with this problem. There is its own order of each element in a cluster. I tried to initiate an array but it seems like too complicated. In the attached file, I want to obtain only the data from "flow" not "pressure". I try to use array programming but it doesn't work. Would be nice if you help me to fix the file. Thanks
    Solved!
    Go to Solution.
    Attachments:
    test 1.vi ‏16 KB

    Bombbooo wrote:
    What about if I want to store data into the pressure array too? Do I have to create another loop or it can be done in the same loop as the flow loop?
    Try this, for example. Modify as needed.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    test1MOD2.vi ‏9 KB
    SelectFlowOrPressure.png ‏7 KB

  • How to extract data from web URL

    I was doing one project which need to extract data from web pages and then analyze these data. the question is how to extract data from there, using html parser? need help, thanks a lot

    I was doing one project which need to extract data
    from web pages and then analyze these data. the
    question is how to extract data from there, using
    html parser? need help, thanks a lotTry this:
    http://java.sun.com/docs/books/tutorial/networking/urls/readingURL.html
    Or, like you said yourself, use an HTML parser:
    http://java-source.net/open-source/html-parsers

  • How to extract data from Chart History?

    Dear all, I have read a lot of posts, but still don't understand how to extract data from Chart history.
    Suppose you acquired 1024 points of data every time, then use "build array" to build an array, then send to intensity chart to show, then save the history into a .txt file,  but how to extact data from the file?
    How Labview store the data in the 2D history buffer?
    Anybody has any examples?

    The simplest would be to save the 2D array as a spreadsheet file, the read it back the same way.
    Maybe the attached simple example can give you some ideas (LabVIEW 7.1). Just run it. At any time, press "write to file". At any later time, you can read the save data into the second history chart.
    If you are worried about performance, it might be better to use binary files, but it will be a little more complicated. See how far you get.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    IntensityChartHistorySave.vi ‏79 KB

  • How to extract data from ODS to non-SAP system

    Hi,
    Can anybody tell me, step by step, how to extract data from ODS to a non-SAP system?
    Is it possible to do it without programming effort? And is there volume limits for this kind of extraction?
    The non-SAP system is an unix system.
    Thanks in advance
    Ella

    Ella,
    You can look at it from the concept of a BADI / Infospoke
    Extract the data from the ODS to a Flat file / RDBMS using an infospoke. I am not sure as to how the infospoke loads data into the RDBMS ( did it very long ago ) but then you can push it into an RDBMS and I am sure it will be system neutral.
    Hope this helps...
    Arun
    Assign points if it helps

  • How to extract data from custom made Idoc that is not sent

    Hi experts,
    Could you please advise if there is a way how to extract data from custom made idoc (it collects a lot of data from different SAP tables)? Please note that this idoc is not sent as target system is not fully maintained.
    As by now, we would like to verify - what data is extracted now.
    Any help, would be appreciated!

    Hi,
    The fields that are given for each segment have their length given in EDSAPPL table. How you have to map is explained in below example.
    Suppose for segment1, EDSAPPL has 3 fields so below are entries
    SEGMENT          FIELDNAME           LENGTH
    SEGMENT1         FIELD1                   4
    SEGMENT1         FIELD2                   2
    SEGMENT1         FIELD3                   2
    Data in EDID4 would be as follows
    IDOC           SEGMENT                          APPLICATION DATA
    12345         SEGMENT1                        XYZ R Y
    When you are extracting data from these tables into your internal table, mapping has to be as follows:
    FIELD1 = APPLICATIONDATA+0(4)        to read first 4 characters of this field, because the first 4 characters in this field would belong to FIELD1
    Similarly,
    FIELD2 = APPLICATIONDATA+4(2).
    FIELD3 = APPLICATIONDATA+6(2).  
    FIELD1 would have XYZ, FIELD2 = R, FIELD3 = Y
    This would remain true in all cases. So all you need to do is identify which fields you want to extract, and simply code as above to extract the data from this table.
    Hope this was helpful in explaining how to derive the data.

  • How to extract data from oracle database directly in to bi7.0 (net weaver)

    how to extract data from oracle database directly in to bi7.0 (net weaver)? is it something do with EDI? can anybody explain me in detail?
    Thanks
    York

    You can use UDConnect to get from Oracle database in to BW
    <b>Data Transfer with UD Connect -</b>
    http://help.sap.com/saphelp_nw04/helpdata/en/78/ef1441a509064abee6ffd6f38278fd/content.htm
    <b>Prerequisites</b>
    You have installed the SAP WAS J2EE Engine with BI Java components.  You can find more information on this in the SAP BW installation guide on the SAP Service Marketplace at service.sap.com/instguides.
    Hope it Helps
    Chetan
    @CP..

Maybe you are looking for

  • Who's Who : does not at all show of "Placeholder" of Photo

    Dear Experts We have SAP_ESS with 600 SP16    on   SAP NW 7.00 SP20  Java System (inlcudes Application Server Java + Enterprise Portal + Enterprise Portal Core Components) When we browse thry SAP Standard " Who's Who" - It just display the employee i

  • Recovery disc for pavilion/dvl6604cl

    Please tell me how to order a recovery disc for the pavilion dl6604cl notebook.  My harddrive has failed and the Geek squad needs the recovery disc to get my notebook back on line.  I can't find where to order the disc.

  • Connecting to specific routers within a WDS network

    I have two routers that are successfully operating on a WDS network. The primary router is a linksys WRT54G v2.2 with dd-wrt firmware and the secondary router is an airport express. The express has my xbox connected to it allowing me to connect to th

  • I can't merge my mobileME account with iCloud.

    I am having problems, and seem to keep going in circles when trying to merge my mobile Me account to iCloud.  I have an iphone that I want to be able to synch my photostream with.  It just won't seem to allow me to see those pics.  I can't figure it

  • [svn:osmf:] 15988: asdocs build fix (missing closing /p added x 3)

    Revision: 15988 Revision: 15988 Author:   [email protected] Date:     2010-05-10 09:32:06 -0700 (Mon, 10 May 2010) Log Message: asdocs build fix (missing closing </p> added x 3) Modified Paths:     osmf/trunk/framework/OSMF/org/osmf/elements/Lightwei