XML StAX - How to extract text and elements?

Hello,
I'm using StAX to parse this XML document (heavily reduced):
<?xml version="1.0" encoding="utf-8"?>
<html>
  <head>
    <title>Foo</title>
  </head>
  <body>
    <p>loading ...</p>
  </body>
</html>I need to extract the data between the <body> element i.e "<p>loading...</p>". My problem is that I can only find methods that extracts the text and not the elements. Is there an easy way to do this using the XMLStreamReader instance, or do I have to use another class?
Thanks

Thanks for your reply. But does that really mean that I have to create my own method, which will collect both text and elements information in a StringBuffer as I parse through the enclosing element? I just think it is strange that there isn't a convenient method to extract all data (text & elements) between one element.
Something like this?:
private void handleBody(XMLStreamReader parser,XMLEventAllocator allocator) throws XMLStreamException {
          StringBuffer body = new StringBuffer();               
          while(true){
               String value = null;
               parser.next();               
               if (parser.getEventType() == XMLStreamConstants.START_ELEMENT){
                    String name = parser.getLocalName();
                    if (!name.equalsIgnoreCase("body")){
                         StartElement startElement = getXMLEvent(allocator,parser).asStartElement();                         
                         value = startElement.toString();
               else if (parser.getEventType() == XMLStreamConstants.END_ELEMENT){
                    String name = parser.getLocalName();
                    if (name.equalsIgnoreCase("body")){
                         break;
                    else{                         
                         EndElement endElement = getXMLEvent(allocator,parser).asEndElement();                         
                         value = endElement.toString();
               else if (parser.hasText()){                    
                    value = parser.getText();
               if (value != null){
                    body.append(value);               
     }

Similar Messages

  • How to extract text and image information from postscript file

    I want to write a programe,and extract text and image information from postscript file using Java.Is it possible? How to extract ?
    Thank!

    First of all, PostScript is not a "text" file. It can and often does contain binary data. Since PostScript streams often contain nested procedures, unless you process the procedure definitions and can "execute" them, you cannot simply "scan" a file to get what you want. No, I can't talk about this in detail since it is quite complex. But Adobe does have the
    PostScript Language Reference Manual on-line for download at
    . Look that over and you will have a fairly healthy respect as to the task involved.
    - Dov

  • 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 read text and it's font details (Family and size) using Acrobat plugin?

    Hello,
           I have query about reading PDF, I wanted to extract text and it's font details (Family and size) using Acrobat plugin. How can I achieve that?
    Any suggestions are welcome.
    Thanks
    Rohit Shinde

    Look at the samples in the SDK around PDFEdit and the PDEdit APIs.

  • How to extract TEXT for archived Purchase Orders ?

    Hi Friends,
    Can any one tell me how to extract TEXT for archived Purchase Orders ?
    I have used READ_TEXT but that is not fetching texts for archived PO's. Whenever I am trying to fetch data from STXH against archived PO, no value is coming and resulting SY_SUBRC <> 0.
    Any demo code will be highly appreciated.
    Thanks in advance..
    Sivaji

    Hi,
    You can see that table STXH is linked to archiving object MM_EKKO (you can see it in tcode DB15).
    My suggest is that you must get the data. See the demo object BC_SBOOK in tcode AOBJ. You can see the report to reload data. The object is get the data in an internal table. So for report SBOOKR you can see this function module:
    *   get data records from the data container
    *   SBOOK
        CALL FUNCTION 'ARCHIVE_GET_TABLE'
          EXPORTING
            archive_handle        = lv_handle
            record_structure      = 'SBOOK'
            all_records_of_object = 'X'
          TABLES
            table                 = lt_sbook_tmp
          EXCEPTIONS
            end_of_object         = 0.         "not entries of this type
    *   check lt_sbook_tmp entries against selections. Delete not
    *   requested entries
        LOOP AT lt_sbook_tmp ASSIGNING <ls_sbook>
                             WHERE carrid IN s_carrid
                               AND connid IN s_connid
                               AND fldate IN s_fldate.
          APPEND <ls_sbook> TO lt_sbook.
        ENDLOOP.
        REFRESH lt_sbook_tmp.
    The idea is that you get the same data that you handle in READ_TEXT (because you don't have the data in database) and recovery the text.
    I hope this helps you
    REgards
    Eduardo

  • How to extract text of info object

    how to extract text of info object ?
    Example text of project defination from 0PROJECT

    Hi Siri,
    I think you can't display the text element if you display the data in the dso.
    In the dso, you will see only the key part.
    So you don't have to load the infoobject text into the DSO, you just have to load the infoobject.
    In Bex you have the option to see either key,text or both.
    Refet the below thread for details.
    Link: [Loading Master Data Text to DSO.;
    Hope it helps you in clearing your doubt.
    Regards,
    Nikhil Joy

  • 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 Extract data and reports from the SAP BW warehouse

    Hi to All Guru's
    I am new to SAP BW. Can any one help me to know, How to Extract data and reports from SAP BW. Do we use any tools.  After Extracting the data from SAP BW how can we move all the data to Cognos.  It would be kind enough to provide me with any documentation or links.  Step by step procedure would be very much helpfull to me.
    Thanks
    Venu

    Hi Voodi
    Thanks for the quick response. I think Open hub is to extract the data from SAP BW, but what about sending this data into Cognos.  Can you please let me know in detail regarding answer. If possible send me any documentation or links regarding this.  Thanks for your concern.
    Venu

  • Guide: how to extract text from any iOS notes app backup on your Mac

    Scenario: you had a sweet notes app like DailyNotes, perhaps one that your girlfriend installed while you weren't looking. So it was on her iTunes account, lets say. Then one day you upgrade to a new iOS version and backup all your data. For whatever reason you erase your iPad, install the new version, and recover back all the apps from the backup. (Maybe you were beta testin g prior to that so you wanted to wipe it clean.) Still your data is gone! Or is it?
    "Fortunately" you backed up. However all that this means is that the text you entered into DailyNotes is stored somewhere in your backup, inside of a file named something like
    "8f5d7ff4111c9b9e4c8dbb7395efdce9c260e0de-20110814-232318", encoded in a .sqlite database file wrapped inside that data.
    Now, if you reinstall the DailyNotes app (or whatever) off of the app store under your own user account, will you get your data back as well? I honestly don't know. But I tried to find out, and I could get no straight answers. Most people said I'd lose my data, and the only way to get back my data would be to restore from the old backup, which of course would erase my current data! So I'd have to backup, then restore from the older backup, then restore from the newer backup again. Does anyone realize how LONG these backups and restores take? FOREVER! I don't have that much time guys. I just need a fast way to access a simple text file. Why does iOS make this such a chore? It's my own content, my own data, which is mine, my copyright, my intellectual property, and the iOS is hiding it from me inside an anonymously-named text file.
    SO HERE'S WHAT YOU DO:
    Download mono framework here and install it: (free)
    http://www.go-mono.com/mono-downloads/download.html
    (this can be easily uninstalled later, it has an uninstaller app)
    Download iPhone Backup Extractor here and extract it in your Downloads directory: (free)
    http://www.iphonebackupextractor.com./free-download/
    (this can be easily uninstalled later, just delete the folder)
    Download SQLite Database Browser 2.0 b1, and extract it in your Downloads directory: (free)
    http://sourceforge.net/projects/sqlitebrowser/
    (this can easily be uninstalled later, just delete the app)
    You can move the two apps to your Applications directory if you intend to keep them long-term, but you can run them just fine from the Downloads directory which will make them easier to identify and erase after you're done, if you don't plan to keep them around.
    Go to Finder and open the iPhone Backup Extractor directory. Resize that window to the side of your screen.
    Go to Terminal and set the window where you can see part of it if the previously mentioned Finder window from the last step was floating on top of it.
    Type "cd " (yes that's c, d, space) in Terminal then hit command-Tab to switch to Finder.
    Drag the folder icon from the title bar of the finder window into the Terminal window that's now in the background. For you newbies, the "title bar" is the VERY topmost edge of the window (the frame of the window) which should have a folder next to the words, "iPhone Backup Extractor" visible in it. You're clicking and dragging THAT folder icon into the terminal window in the background. HIT ALT-TAB AGAIN WHEN DONE.
    Now you're back in the Terminal and it should say:
    "cd /Users/yourname/Downloads/iphonebackupextractor-latest" after the unix prompt. HIT ENTER.
    Now type:
    mono iPhoneBackupExtractor.exe
    This will run the iPhone Backup Extractor app. It takes a few minutes to load because mono is slow (it's emulating Windows basically). Be patient.
    NOTE: The Backup Extractor can only see backups stored on your boot drive that are in the users folder of whatever user you're currently logged in as. So if your backup is on an external drive or a CD, etc., just copy it to the desktop.
    Once iPhone Backup Extractor loads, you'll see its window where you can select the backup. Select whichever one you want to work with. Then hit Expert mode. Each app that was on your device at the time you made the backup will have a directory shown. It will be named something like:
    com.ramki.dailynotes
    Expand the one you want to recover data from by clicking the plus sign next to it. Then expand the Documents directory for it. You'll see a file called something like Daily_Notes.sqlite. Click the dark black box next to this and a checkmark should appear.
    Once you've checked the file to recover, click "Extract selected" below and save to your Desktop (or wherever!).
    Now quit iPhone Backup Extractor unless you have other data to also extract.
    NEXT... OPEN the app SQLite Database Browser 2.0 b1.
    Once it loads, open your Daily_Notes.sqlite file (or whatever .sqlite file you extracted, not necessarily Daily_Notes, that's just my example). If you followed my previous steps that file will be on your Desktop.
    Once it loads you'll see three buttons at the center of the window near the top called, "Database Structure," "Browse Data," and "Execute SQL." CLICK ON "Browse Data."
    Now on the left-hand side of the window there is a pop-up menu with the word "Table: [POP-UP-MENU-IS-HERE] "... CLICK on the pop-up menu. It will actually say the name of one of the database files that's within the SQLite database, something like "ZAPPSTATE" or "ZDAYDATA" or whatever (not "POP-UP-MENU-IS-HERE", that was just text I put as a placeholder since it could be anything really).
    Now that you've clicked the pop-up menu, select each item one by one and look at the data that appears in the table.
    (Don't worry, you're just working with a COPY of the file, so if you accidentally delete anything it's not a real problem, just delete the .sqlite file and start the steps over from the beginning of this message.)
    You should eventually find a table that has the text that you're looking for! Mine was called "ZDAYCONTENT".
    WHEN YOU ARE LOOKING AT THE DATABASE TABLE, it looks like an Excel spreadsheet. That means you may have to double-click on the database cell to get it to show you the entire contents of that part. (It only shows a truncated text string in each cell, but if you double-click, a new window will open on top of the current window, showing the full text that was in there.) Now you can copy the text out and paste it into another app like Text Edit or MS Word or Pages, etc. You can also export the data in the File Menu > Export to an SQL or CSV file. (CSV is a text file where the data is all there, just separated by commas. This can then be imported into Excel or Numbers or another database or printed, etc., or just opened into Pages or Word or BBEdit etc.)
    CAVEATS: Dates will often be shown as a weird number like 3780 or 2863 etc. You may have to figure out on your own what this date means. I honestly have no clue. SQLite Database Browser does not seem to support viewing or exporting PNG and image files.
    Other than that good luck. Post any questions here.
    AND HEY, APPLE: MAKE THIS EASIER! FILES BELONG IN FOLDERS, NOT INSIDE FOLDERS THAT ARE INSIDE APPS!!!

    Restore iPad data from backup files, with the help of iPad Data Extractor:
    1. Settings>General>Reset>Erase all content and settings
    2. You'll be asked twice to confirm
    3. You'll see Apple logo and progress bar
    4. You'll see a big iPad logo on screen
    5. Configuration start
    6. Set language
    7. Set country
    8. Select Network and input Password>Join
    9. Enable Location Service>Next
    10. You'll be given 3 options (a) Setup as New iPad (b) Restore from iCloud Backup (c) Restore from iTune Backup
    11. Select Restore from iTune Backup
    12. You will see picture of USB cable pointing towards iPad
    13. Connect iPad to iTune (make sure iTune is on standby)
    14. Tap Continue (computer)
    15. Restore iPad from Backup (computer)
    16. See progress bar with estimated time (computer)
    17. See Restore in Progress on iPad
    18. See Apple logo
    19. See Apple and Progress Bar
    20. Slide to Unlock
    21. Copying Apps back to iPad (computer)
    22. You'll see Loading/Installing/Waiting below the Apps (iPad)
    23. Sync Music/Podcast/Movies to iPad (computer)
    24. Sync completed (computer)

  • How to extract a particulat element details which has more references ???

    Hi All,
    I'm having many schema files (.xsd). Each schema files may include one or two external schema files.
    Example, <xs:include schemaLocation="wait-advanced.xsd"/>
    1) Assume that there are 50 elements in each schema file.
    2) Assume many complex types defined in each schema file
    3) Each elements has inner elements, attributes and refer complex types from the same file or a different file (i.e refer the complex elements defined in another schema file)
    Need to extract the following:
    a) Now let us assume a schema file name is "WaitingRequest.xsd" and it has element name called "waiting-details".
    b) waiting-details element internally has elements which refers to complex types of the same schema file as well as from different schema files.
    c) Now if the user gives the "waiting-details" i want to extract all the elements, referred elements, referred complex types etc., in a separate schema file.
    Can anyone please help and let me how we can do this via Java?
    Thanks,
    Kathir

    Hi All,
    I'm having many schema files (.xsd). Each schema files may include one or two external schema files.
    Example, <xs:include schemaLocation="wait-advanced.xsd"/>
    1) Assume that there are 50 elements in each schema file.
    2) Assume many complex types defined in each schema file
    3) Each elements has inner elements, attributes and refer complex types from the same file or a different file (i.e refer the complex elements defined in another schema file)
    Need to extract the following:
    a) Now let us assume a schema file name is "WaitingRequest.xsd" and it has element name called "waiting-details".
    b) waiting-details element internally has elements which refers to complex types of the same schema file as well as from different schema files.
    c) Now if the user gives the "waiting-details" i want to extract all the elements, referred elements, referred complex types etc., in a separate schema file.
    Can anyone please help and let me how we can do this via Java?
    Thanks,
    Kathir

  • How to extract Cleared and Open Items from SAP R/3?

    Hi experts,
    I have a requirement from user to extract cleared and open invoice items from SAP R/3.
    Can someone tell me how to do that?
    Thanks!

    Hi,
    Use the Data source 0FI_AR_4 to Know the status (0FI_DOCSTAT) of payment to be done by customer.
    OR
    Enhance the 2LIS_13_VDITM with VBUP fields which will give the status of Billing.
    With rgds,
    Anil Kumar Sharma .P

  • Cannot view content text and elements in Dreamweaver

    Hi,
    I am not an expert in Dreamweaver, still learning. Would anyone tell me why when I open up the template in Dreamweaver's design view I cannot see the content text and other elements to edit or view? However, all those are still viewable in browsers. I can edit content only through code mode in Dreamweaver, not in design view. I am attaching the whole template for you to see.
    I would greatly appreciate your feedbacks.
    Ed

    Found it in the last line of the code, it's a Joomla template.
    The only real way to use this with dreamweaver is with one of the extensions for dreamweaver (not 100% required, but difficult without one), there are a number of extensions available (sorry, but none are free that I know of).
    Try - http://www.justdreamweaver.com/dreamweaver-joomla-tools.html , or do a search for  Joomla and dreamweaver extension.
    PZ

  • How to extract username and password from CRMOD

    I have a requirement where i have make a jsp paget hru which user can upload doc in UCM and embed in CRMOD using Web Applet.But at the backend the UCM requires CRMOD username and password.How can i extract username and password frm crmod using java.

    You can get this info from your ISP. This one may help.
    Create a Broadband connection using PPPoE in Windows Vista and Windows Server 2008
    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows]
    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.

  • How to extract *.sar and *.car

    hi all .,
               can u help me out in this ..
    how to uncar *.sar and *.car

    Hello Raja,
    you can find the SAPCAR file on this location
    /usr/sap/SID/SYS/exe/run
    you can extract the .sar or .car files through SAPCAR
    sapcar -xvf <filename>
    Regards
    Subhash

  • How to set text and background color of current row in a adf table?

    Hi,
    In jdev 11.1.2.3,
    How to set text fond and background color of current row in a adf table?
    I tried to set Background color in table property, but that is not what i want.
    Thanks.

    Hi,
    We almost had the same requirement, but we just needed to color a specific column.
    Here goes the solution to that, you might do the same for your row highlighting
    Changes are required in jsff and one method to be added in backing bean
    1. JSFF :
    <af:column headerText="Amount"
                     id="c4" width="100"
                     inlineStyle="#{backingBeanScope.BackingBean.cellColor}">2. Backing Bean
    //searchResultTableVO is Table's VO
    public String getCellColor() {
          FacesContext ctx = FacesContext.getCurrentInstance();
          ExpressionFactory ef = ctx.getApplication().getExpressionFactory();
          ValueExpression ve = ef.createValueExpression(ctx.getELContext(), "#{row}", FacesCtrlHierNodeBinding.class);
          FacesCtrlHierNodeBinding node = (FacesCtrlHierNodeBinding)ve.getValue(ctx.getELContext());
          Row row = node.getRow();
        if(row.equals(searchResultTableVO.getCurrentRow())){
    //You can add your inline style for font-style too
          return "background-color:Red;";
             return null;
      }Hope this is helpful :)
    Regards,
    Neha..

Maybe you are looking for

  • Scan multiple pages from 5520 to windows 8

    I own an HP 5520 all in one. I recently bought a new Dell all in one computer with Windows 8 OS. I am having problems with scanning. I need to be able to scan two or more pages into a single PDF document. The app indicated for SCAN on this new fangle

  • Can two iphones on different accounts sync from the same itunes account?

    I have an iphone through work. The iphone along with four other various types of ipods sync with my accounts on iTunes, including thousands of purchased songs. My wife is getting an iphone but she had to do if through her work. How do I make sure she

  • The operation can't be completed because an unexpected error occurred (error code -8060).

    Hi, I want to copy a folder from desktop to my document (or anywhere else on a MAC) I got this error "The operation can't be completed because an unexpected error occurred (error code -8060)." everytime at the same position when it's about to finish

  • Should I use Flash Builder to develop for iOS?

    We have a sizable AIR application built using Flash Builder 4.5 that is deployed on Windows and Mac. We tried to package it for Android and it simply failed to run at all. Apparently there are many namespaces not supported on Android. We've since sto

  • Authorizations - songs reverting to old accounts

    Hello-  I am having songs that I've purchased with my current account revert back to old accounts that no longer exist.  It says I am not authorized to play the file, so I am losing library slowly and surely.  Any help? Thanks, KP