XML parsing (KXml) - how to save parser's position for later use?

Hello.
I am parsing an xml file using KXmlParser and i want to keep the position of the parser for later use so i can continue from that same position.
int eventType = parser.getEventType();
        if (coupletForm!=null) {
            coupletForm.deleteAll();
        while (eventType != KXmlParser.END_DOCUMENT) {
            if (eventType == KXmlParser.START_TAG ){
                String element_name = parser.getName();
                if (element_name.equals("couplet")) {
                    coupletForm = new Form("Couplet 1");
                else if (element_name.equals("lead_one")) {
                    while (eventType != KXmlParser.TEXT || (eventType == KXmlParser.TEXT && parser.isWhitespace()) ){
                        eventType = parser.next();
                    //Now reached <description> element
                    coupletOptions = null;
                    coupletOptions = new ChoiceGroup("Choose lead:", Choice.EXCLUSIVE);
                    coupletOptions.append(parser.getText(), null);
                    parser_stack.push(parser);
                else if (element_name.equals("lead_two")) {
                    while (eventType != KXmlParser.TEXT || (eventType == KXmlParser.TEXT && parser.isWhitespace()) ){
                        eventType = parser.next();
                   //Now reached <description> element
                    coupletOptions.append(parser.getText(), null);                  
                    coupletForm.append(coupletOptions);                  
                    parser_stack.push(parser);
                    coupletForm.addCommand(CMD_NEXT);
                    coupletForm.setCommandListener(this);
                    display.setCurrent(coupletForm);
                    break;
            eventType = parser.next();
    }What i am doing here is parsing the xml file. When the parser finds an element with name <lead_one> it continues parsing until it finds the next element (<description>) and then creates a ChoiceGroup with the first option as the text found in the next element. I want to keep this position of the parser. The parser then continues until it finds element <lead_two> and does the same thing as <lead_one>. I want to save the positions of the parser when it stops at the <description> element. I am trying to do this using a stack, but this doesn't work.

If you want to select nodes based on changing criteria, you should use XPath.
If you have relatively fixed criteria, iterate over the nodes and pick out the ones that you want. For example:
  public static List<Element> getChildren(Element parent, String tagname) {
    List<Element> result = new ArrayList<Element>();
    NodeList children = parent.getChildNodes();
    for (int ii = 0 ; ii < children.getLength() ; ii++) {
      Node child = children.item(ii);
      if ((child.getNodeType() == Node.ELEMENT_NODE) && tagname.equals(child.getNodeName()) {
        result.add((Element)child);
    return result;
  }

Similar Messages

  • How to save the data to sap abap using Adobe Flex

    Hi Everybody......
    I am new to Adobe flex with sap abap.
          How to save the data in sap abap using Adobe Flex coding is Action Script and using RFC web service.
    Please give me any suggisions on that.
    Thank you
    Venkatesh V

    Hi Venkatesh,
    Try with folowing coding...
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
         initialize="initApp()">
         <mx:Label x="10" y="23" text="Airline" width="90" id="lblAirline"/>
         <mx:TextInput x="108" y="21" id="txtAirline"/>
         <mx:Button x="10" y="49" label="Get Data" id="btnGetData" enabled="false" click="getData()"/>
         <mx:DataGrid x="10" y="97" id="dgFlightData" dataProvider="">
         </mx:DataGrid>
           <mx:Script>
              <![CDATA[
                   import mx.collections.ArrayCollection;
                   import mx.rpc.AbstractOperation;
                   import mx.rpc.events.FaultEvent;
                   import mx.rpc.soap.LoadEvent;
                   import mx.rpc.events.ResultEvent;
                   import mx.rpc.soap.WebService;
                   [Bindable] public var flightData:ArrayCollection;
        private var flightWS:WebService;
         private function initApp():void{
              flightWS = new WebService();
              flightWS.wsdl = "http://uscib20.wdf.sap.corp:50021/sap/bc/soap/wsdl11?services=ZGTEST&sap-client=000";
            flightWS.addEventListener(FaultEvent.FAULT,onWSError);
              flightWS.addEventListener(LoadEvent.LOAD,onWSDLLoaded);
             flightWS.addEventListener(ResultEvent.RESULT,onFlightWSGotResult);
              flightWS.loadWSDL();
    private function getData():void{
              var operation:AbstractOperation = flightWS.getOperation("ZGTEST");
              var input:Object = new Object();
              input.Airline = txtAirline.text.toUpperCase();
              operation.arguments = input;
              operation.send();
         private function onWSError  (event:FaultEvent):void{
         private function onWSDLLoaded(event:LoadEvent):void{
              btnGetData.enabled = true;
         private function onFlightWSGotResult(event:ResultEvent):void{
              flightData = event.result.SFLIGHT;
              ]]>
         </mx:Script>
    </mx:Application>
    Regards,
    Vinoth

  • How to save HR data in Active Directory using ABAP i.e thru LDAP Connector

    Hi All,
           Can any one please help me out how
           to save HR data in Active directory
           using LDAP Connector ?             
           Please help ASAP as it is very urgent .
    Thanks
    Jitendra

    There are 100 of such scripts are there online.
    here are few tips and codes. you will get more.  
    https://gallery.technet.microsoft.com/scriptcenter/Feeding-data-to-Active-0227d15c
    http://blogs.technet.com/b/heyscriptingguy/archive/2012/10/31/use-powershell-to-modify-existing-user-accounts-in-active-directory.aspx
    http://powershell.org/wp/forums/topic/ad-import-csv-update-attributes-script/
    Please mark this as answer if it helps

  • How to save hr data in Active directory  using abap

    Hi all
    can any one please help me out how to save hr data in Active directory using LDAP connector
    please help as this is very urgent requirement
    thanks in advance
    Thanks
    Chanti

    What form do you have the user's name in ?
    ANTIPODES\alberteString searchFilter = "(&(objectClass=user)(samAccountName=alberte))";[email protected] searchFilter = "(&(objectClass=user)(userPrincipalName=[email protected]))";Albert EinsteinString searchFilter = (&(objectClass=user)(givenName=Albert)(sn=Einstein))";or using Ambiguous Name Resolution (anr)String searchFilter = "(&(objectClass=user)(anr=Albert Einstein))";or it's even clever enough to useString searchFilter = "(&(objectClass=user)(anr=Einstein Albert))";

  • How to save a new value for Set command variable

    I am using SET [variable = [String]] to update Set variable. It works fine. But when I restart MSDOS Prompt, I get old value for variable.
    How to save a new value for SET command variable?
    I am using Windows XP.

    And this has to do with java how?

  • How to save a list template and make use of it in another website as webpart ?

    How to save a list template and make use of it in another website as webpart ?
    1. Save As "List A" as .STP
    2. Go to another website, in the document workspace I try to Add webpart -> Browse -> Upload the STP file, but after that the List A webpart still doesn't appear.
    Any clue which part went wrong? 

    Hi,
    firstly you need to upload the .STP file to a list solution gallery of the site and then you can add the list (under custom name) to the webpage
    see here for how to-
    http://office.microsoft.com/en-us/sharepoint-server-help/copy-or-move-a-list-by-using-a-list-template-HA101782479.aspx
    Hope this helps!
    Ram - SharePoint Architect
    Blog - SharePointDeveloper.in
    Please vote or mark your question answered, if my reply helps you

  • Hi, I am going to an exhibition where there is no internet access but would like to show people around my website. I have added "scrapbook" but cannot work out how to 'save' an entire site for viewing off-line.

    Hi, I am going to an exhibition where there is no internet access but would like to show people around my website. I have added "scrapbook" but cannot work out how to 'save' an entire site for viewing off-line. I thought there was a way to specify 1/2/3 clicks from home page etc. Please help. DAVID

    OK, solved my own problem, but am posting here in case someone else has the same problem. It totally does not make sense, especially considering that it stopped after I reinstalled Lion, but the good thing is I have my files back.
    I scoured the web and found a lot of other people are having the same problem. Most of them didn't have a clue how to fix it. This discussion was the most helpful to me: https://discussions.apple.com/thread/2569766?start=30&tstart=90
    So, I went to the WD page and followed the instructions. The first suggestion was to plug it directly into a wall, because it may not be getting enough power from a power cord. I did this and it fixed the problem. Who would have guessed?
    Anyway, if anyone else is having this problem, go to your manufacturer's website for help. Here's WD's help: http://wdc.custhelp.com/app/answers/detail/a_id/1164/related/1/session/L2F2LzEvd GltZS8xMzI2MzIzMjUwL3NpZC82dmo0blZOaw%3D%3D

  • How to get the baselinegrid position for a line?

    Hi All,
    How to get the baselinegrid position for a line in a paragraph?

    Hi,
    2nd line baseline grid for yourPara paragraph is:
    yourPara.lines[1].baseline;
    last line baseline is:
    yourPara.endBaseline;
    Jarek

  • How to compile your flex application for Iphone Using Adobe Flash CS5?

    How to compile your flex application for Iphone Using Adobe Flash CS5?

    I'm so sorry, I'm not really familiar with the codes.

  • Is it possible to save a Photoshop project with multiple tabs (inducing images) for later use. Now, when I close Photoshop, it ask to save each tab separately and they are not staying in the project for later usage. Thanks in advance for you help.

    Is it possible to save a Photoshop project with multiple tabs (inducing images) for later use. Now, when I close Photoshop, it ask to save each tab separately and they are not staying in the project for later usage. Thanks in advance for you help.

    You should ask in Photoshop General Discussion
    The Cloud forum is not about using individual programs
    The Cloud forum is about the Cloud as a delivery & install process
    If you will start at the Forums Index https://forums.adobe.com/welcome
    You will be able to select a forum for the specific Adobe product(s) you use
    Click the "down arrow" symbol on the right (where it says All communities) to open the drop down list and scroll

  • How long is normal battery life for late 2011 macbook air?

    How long is normal battery life for late 2011 macbook air?

    I would also note that the 11" and 13" have different lives.  While the 11" has a smaller screen to drive (and thus, in theory, less power) it also has less space for a battery.  So it turns out the 13" has a longer battery life, all other things being equal (same usage and the like).
    Clearly what's "average" will vary by user.  Depending on what I'm doing, I can get Apple's rated life (or darned close) or I could end up well short of that life.  The "rated" life is 5 hours for the 11" and 7 hours for the 13" but that is, at best, a very rough approximation.  As the picture in captfred's response makes clear, the actual usage of the machine has a huge influence.

  • How to save macros in excel for all workbooks permanently?

    HI all,
    I have created macros in the Excel 2007 and have saved it. And its working fine. But i open the same excel sheet again, I cant see any macros in the excel sheet?
    Can anyone pls let me know how to save the macros permanently in the Excel Sheet ?
    Thanks
    Pooja

    Hi ,
    I have saved as .xslx format but still the same unable to see the macros in the same excel sheet.
    My intention is that when ever i open any excel sheet in the my computer those macros should be available for me!!
    Thanks
    Pooja

  • How to save Charts to a word document using LabVIEW Report Genereration toolkit?

    I just started using the LabVIEW Report Genereration toolkit, but I can't figure out how to save Waveform Charts (one dimensional data versus time, instead of Graphs) to a Word document. Can somebody give a suggestion? Thanks!

    Nina,
    In MS Word, you have 2 options when you select Insert Object:
    Microsoft Excel Chart
    Microsoft Graph 2000 Graph
    If you select Insert Picture, you can choose Chart. This is the same chart as when you select Microsoft Excel Chart.
    To insert this chart, you will use Word Insert Graph.vi. This VI calls Word_Insert_Chart.vi, that uses ADO object Graph.Chart and its properties and methods.
    From the Microsoft Help:
    Create a chart by using Microsoft Graph
    When you create a chart by using Microsoft Graph, a chart and its associated data are displayed in a table called a "datasheet."
    Zvezdana S.
    National Instruments

  • How to save the session states for a tabular form WITHOUT using check boxs?

    Greeting guys,
    As you know that we can use collections to save the session states of a tabular forms, described in the how-to doc of manual tabular forms. However, what I am trying to do ( or have to do) is to provide a manual tabular form, and save the session states for validation, without using the check boxes. Because a user can put contents into some columns in a row without checking the corresponding checkbox, according to the requirements. So basically what I tried is to loop over all the rows and save Every entry into a collection. However, sometimes I got "no data found" error with unknown reasons.
    My current solution is to use the "dirty" Retry button that gets back the history, which IMO is not a good workabout. So, I'd appreciate if somebody can shed some light on a better solution, especially if it is close to the one in that how-to doc.
    Thanks in advance.
    Luc

    The following is the first collection solutin I've tried:
    htmldb_collection.create_or_truncate_collection('TEMP_TABLE');
    for i in 1..p_row_num loop -- Loop on the whole form rows
    if (htmldb_application.g_f01(i) is not null) or (htmldb_application.g_f05(i) <> 0)
    --If either of them has some input values, the row should be saved into the colleciton.
    then
    htmldb_collection.add_member(
    p_collection_name => 'TEMP_TABLE',
    p_c001 => htmldb_application.g_f01(i),
    p_c002 => htmldb_application.g_f03(i),
    p_c003 => htmldb_application.g_f04(i),
    p_c004 => htmldb_application.g_f05(i),
    p_c005 => htmldb_application.g_f06(i),
    p_c006 => htmldb_application.g_f08(i)
    end if;
    end loop;
    Some of columns have null values, but I don't think that's the reason. Because once I clicked all the check boxes, there would be no error no matter what values were in other columns.
    Another issue would be extract the values FROM the collection, which has been tried because I had problem to store the data into the collection. I used "decode" functions inside the SQL to build the tabular form. I am not sure whether it will be the same as a regular SQL for a tabular form, like the example in the How-to doc.
    Also I didn't use the checksum, for it is not an issue at the current stage. I am not sure whether that's the reason which caused the NO DATA FOUND error.

  • How to save landscape print layout for report designed in SQL Server 2005

    How to save page setup for a report wich was designed in SQL Server 2005 RS?  Each time report is previewed, I have to change portrate to landscape orientation and left and right marging from 0,5 to 0,25, to be able to see all fieldas on the report.
    Thanks!

    Hi, Marina;
    Which version of Crystal Reports are you using? Once you set a report to Landscape, and save the report, it should stay that way, unless you change to a different printer.
    Regards,
    Jonathan

Maybe you are looking for

  • Aging in AP

    Dear All Can anybody provide some guidance about aging in AP. How it works and how to implement it.... I shall be really grateful. Regards Habib

  • FileAdapter to JaxRpc web service, all or nothing

    I've managed to use the File Adapter to read batch files (both positional and delimited) and for each record invoke a synchronous Web Service exposed by my J2EE app to update that application with my data. Now I would like to do the same thing, but h

  • Edit with errors

    I'm trying to "edit with" (i.e. right click on an image link, select edit with> photoshop CS4) images with Indesign CS4 and Photoshop CS4. Wierdly my system opens powerpoint and tries to edit with powerpoint instead (it fails obviosuly) Any idea what

  • Help! iPod won't work - started with iPod updater

    Hi, I tried updating my iPod nano today as suggested. It installed and everything fine. But when I tried updating it, it gave me an error and I couldn't use my iPod. So I tried restoring it with the updater. Nothing worked. The "Do not disconnect" si

  • Trusted.certs question with regards to Installation and Upgrading Java

    Greetings, Thank you to all who take the time to read this especially those who can provide some answers! Question #1: I read that trusted.certs was not backwards compatible for Java. By this I mean that a "Java Runtime 6 Update 11" generated trusted