[SOLVED]Need to parse output data

I have a program that outputs data to the console in this format:
[1] banana
[2] orange
[7] apple
[17] grape
[42] strawberry
I would like to strip this output and only get the values for [2] and [17]. So my output would be:
orange
grape
My first idea was to pipe the output to grep and then possibly use sed to strip the preceding numbers and brackets. What is the recommended way to do this and why? Is there a better suited utility that I'm not aware of?
Last edited by nadman10 (2013-11-06 16:48:54)

Trilby wrote:grep + (cut/sed) = awk.
Very true.
Trilby wrote: awk '/\[(2|17)\]/ { print $2; }'
I wanted OP to google / RTFM this himself
The idea to use sed was correct, nadman10. You should have googled
remove "square brackets" sed
and you would have found out the answer yourself: http://www.unix.com/showthread.php?t=159143
The slightly tricky part with the square brackets is that they have special meaning, so you have to escape them i.e. precede them with '\'.

Similar Messages

  • Parsing stopwatch data

    I need to parse stopwatch data from a textfile in a beautifull way.
    Data is represented in a "5.25.12" way, where 5 stands for 5 minutes, 25 stands for 25 seconds and 12 stands for 120 milliseconds.
    Is there a way to parse such a date with a SimpleDateFormat?
    I tried to do so using "mm.ss.SSS" pattern, but failed (result was a negative value).
    1) is it possible to parse "5.25.12" data by using SimpleDateFormat?
    1a) which pattern should I use to parse such a string to date?
    2) May be there is a more beautiful way to parse such a data?
    Message was edited by:
    Nikita_Koselev

    The pattern you give is valid and using it you can construct a SimpleDateFormat which will convert a String like "5.25.12" into a date whose toString() representation is like "Thu Jan 01 00:05:25 NZST 1970".
    Note: you get 12 milliseconds, not 120. If your data records centiseconds you may have to add a zero. Also it does give a date. If you are more interested in an interval of time you could split() the string and use the components separately.

  • In JDBC Sender Adapter , the server is Microsoft SQL .I need to pass current date as the input column while Executing stored procedure, which will get me 10 Output Columns. Kindly suggest me the SQL Query String

    In JDBC Sender Adapter , the server is Microsoft SQL .I need to pass current date as the input column while Executing stored procedure, which will get me 10 Output Columns. Kindly suggest me the SQL Query String , for executing the Stored Procedure with Current date as the input .

    Hi Srinath,
    The below blog might be useful
    http://scn.sap.com/community/pi-and-soa-middleware/blog/2013/03/06/executing-stored-procedure-from-sender-adapter-in-sap-pi-71
    PI/XI: Sender JDBC adapter for Oracle stored procedures in 5 days
    regards,
    Harish

  • I need help parsing a  swift data string

    i need to parse swift financial data
    is there a way to use split or stringtokenizer for ::
    and keep the :: as part of the new seperated data.
    i want to put each string starting with :: on a seperate line in a text box.
    i gave up and tried it with a loop and a stringbuffer , and indexof.
    if (line.indexOf("::") == Strpos ){
    frame.jTextArea1.append(displayline.toString());
    displayline = new StringBuffer();
    displayline.append(line.substring(Strpos, (Strpos + 2)));
    Strpos += 2;
    if (line.indexOf("::") != Strpos ) {
    displayline.append(line.substring(Strpos, Strpos + 1));
    System.out.println( displayline);
    Strpos++;
    but i cant get that to work either.
    if anyone knows how to parse swift data please give me your email address.
    i've been doing it in cobol for 15 yrs and i just cant get the cobol techniques to translate to java.
    thanks.

    as i said
    i am really a cobol guy
    and yes as you see i did try to use indexof in my code.
    but there must be something about indexof that i'm not getting.
    it works the first time in the loop but then as i increment my start position(strpos)
    the indsex of no longer works.
    am i using the correct technique to increment the start position thru the string buffer.
    thanks guys.

  • Need to parse Japanese Full Date Format

    Hi,
    Locale japanLocale = Locale.JAPAN;
    SimpleDateFormat fullDateFormat = (SimpleDateFormat) SimpleDateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, japanLocale);
    String dateValue = 2010'?'09'?'12'?' 1'?'15'?'45'?'GMT // Here Japanese character will come instead of ?
    DateFormat initialDateFormat = new SimpleDateFormat(fullPattern, japanLocale);
    Date date = initialDateFormat.parse(dateValue);
    String formattedDate = fullDateFormat.format(date);
    This throws Exception java.text.ParseException: Unparseable date: "2010'?'09'?'12'?' 1'?'15'
    ?'45'?'GMT"
    If you send some good suggestions, it will be appreciable.
    Thanks in Advance
    Suresh

    Japanese full pattern is:
    "yyyy'年'M'月'd'日' (EEEE)
    H'時'mm'分'ss'秒' z"
    I need to parse this string.
    OK:
    String pattern = "yyyy'年'M'月'd'日' (EEEE) H'時'mm'分'ss'秒' z";
    String date = "2004年8月12日 (木曜日) 13時56分01秒 EEST";
    SimpleDateFormat parser = new SimpleDateFormat(pattern, Locale.JAPAN);
    Date d = parser.parse(date);
    System.out.println(d); // prints Thu Aug 12 13:56:01 EEST 2004
    Note that for the sake of portability the two first lines should be written asString pattern = "yyyy'\u5e74'M'\u6708'd'\u65e5' (EEEE) H'\u6642'mm'\u5206'ss'\u79d2' z";
    String date = "2004\u5e748\u670812\u65e5 (\u6728\u66dc\u65e5) 13\u664256\u520601\u79d2 EEST";This is to make it possible to compile your code on a platform that doesn't support Japanese script.
    Can i have your Yahoo / AOL ID?What makes you think I have one? :)

  • I need to get SSIS Data profiler output in Excel.

    Hi,
    I need to get SSIS Data profiler output in Excel. Tried importing XML generated by SSIS Profiler in Excel but data is getting lost. Can anybody please help on this.
    Thanks,
    Manoj

    Hi Manoj,
    The Data Profiling task outputs the selected profiles into XML file. We can specify the result to any extensions of file, the generated file is valid for the built-in Profile Viewer but invalid for other file viewer applications. So when we specify the output
    to Excel file, we can export the excel file and make analyzing without any problems through the Profile Viewer. But when we use Microsoft Excel open it, it says ‘The file format and extension of’’ don’t match’, then it needs us select one option to open the
    XML file. So we cannot directly export Data Profiling task outputs to Excel file.
    If we still want to export Data profiling task outputs to Excel, we can use the XML Source to extract data from the generated XML file, and then export it to Excel destination in a Data Flow Task.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • How can I convert output data (string?) from GPIB-read to an 1D array?

    Hello all,
    I am reading a displayed waveform from my Tektronix Oscilloscope (TDS3032) via the GPIB Read VI. The format of the waveform data is: positive integer data-point representation with the most significant byte transferred first (2 bytes per data point).
    The output data of GPIB-Read looks like a string(?) where the integer numbers and a sign like the euro-currency sign are seperated by spaces e.g. #5200004C3 4 4 4 4 3C3C3........ (C represents the euro-currency sign).
    How can I convert this waveform data into a 1D/2D array of real double floatingpoint numbers (DBL) so I can handle the waveform data for data-analysis?
    It would be very nice if someone know the solution for this.
    t
    hanks

    Hi,
    First of all, I'm assuming you are using LabVIEW.
    The first you need to do is parse the string returned by the instrument. In this case you need to search for the known symbols in the string (like the euro sign) and chop the string to get the numeric strings. Here are some examples on parsing from www.ni.com:
    Keyword Search: parsing
    Once you parse the numeric strings you can use the "String/number conversion VIs" in the String pallette.
    Hope this helps.
    DiegoF.Message Edited by Molly K on 02-18-2005 11:01 PM

  • Need help in converting date format

    Hi,
    Need help in converting date format from 'DD-MON-YYYY' to 'YYYY-MM-DD' in an .rtf template as I believe xml publisher supports the date format as 'YYYY-MM-DD' only.
    Thanks,
    Raj.

    I got the same problem, anyone know how to solve this problem? I allready found some date functions on http://blogs.oracle.com/xmlpublisher/2008/09/date_functions.html . I also tried <?xdoxslt:month_name(xdoxslt:get_month(xdofx:substr(NEED_BY_DATE, 4,3)), $_XDOLOCALE), 0, 'nl-NL')?>, but then it returns a namespace error (Caused by: oracle.xdo.parser.v2.XPathException: Namespace prefix 'xdofx' used but not declared.). Anyone know how to fix this?
    Edited by: user11165753 on 7-dec-2009 23:50

  • Parsing a date string

    I need to parse a bunch of date strings in 'UTCG' format (whatever that really means).
    They all look like:
    1 Jan 2001 00:00:00.00
    I can't figure out which of the Java date formats parse this. I've tried many varients of:
    DateFormat.getTimeInstance(DateFormat.MEDIUM,Locale.GERMANY)
    without success.
    Help!!!!

    Here is a bit of info from the API doc - notice in the first paragraph it talks about the Date object, format seems similar. At the bottom of info is the Short, Long, etc, format tyoes, check those out... - Bart
    public abstract class DateFormat
    extends Format
    DateFormat is an abstract class for date/time formatting subclasses which formats and parses dates or time in a language-independent manner. The date/time formatting subclass, such as SimpleDateFormat, allows for formatting (i.e., date -> text), parsing (text -> date), and normalization. The date is represented as a Date object or as the milliseconds since January 1, 1970, 00:00:00 GMT.
    DateFormat provides many class methods for obtaining default date/time formatters based on the default or a given locale and a number of formatting styles. The formatting styles include FULL, LONG, MEDIUM, and SHORT. More detail and examples of using these styles are provided in the method descriptions.
    DateFormat helps you to format and parse dates for any locale. Your code can be completely independent of the locale conventions for months, days of the week, or even the calendar format: lunar vs. solar.
    To format a date for the current Locale, use one of the static factory methods:
    myString = DateFormat.getDateInstance().format(myDate);
    If you are formatting multiple dates, it is more efficient to get the format and use it multiple times so that the system doesn't have to fetch the information about the local language and country conventions multiple times.
    DateFormat df = DateFormat.getDateInstance();
    for (int i = 0; i < a.length; ++i) {
    output.println(df.format(myDate) + "; ");
    To format a date for a different Locale, specify it in the call to getDateInstance().
    DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.FRANCE);
    You can use a DateFormat to parse also.
    myDate = df.parse(myString);
    Use getDateInstance to get the normal date format for that country. There are other static factory methods available. Use getTimeInstance to get the time format for that country. Use getDateTimeInstance to get a date and time format. You can pass in different options to these factory methods to control the length of the result; from SHORT to MEDIUM to LONG to FULL. The exact result depends on the locale, but generally:
    SHORT is completely numeric, such as 12.13.52 or 3:30pm
    MEDIUM is longer, such as Jan 12, 1952
    LONG is longer, such as January 12, 1952 or 3:30:32pm
    FULL is pretty completely specified, such as Tuesday, April 12, 1952 AD or 3:30:42pm PST.

  • Parse Serial Data

    I am communicating with an instrument that takes a query and puts out a status packet. I have to parse the data and get information about the instrument status. The status packet is a multi byte data with MSB first and all bytes are 8 bit.
    I get a string output with that says something like this..."CC\B0\CC\B0\CC\D0\CC\D0\CC\B0\CC\D0\00\...". I have not posted the entire string. But I need to parse thsi string and get meaningful values out of it.
    I read some of the previous posts which suggest using the Type Cast function. But I am not sure how it works and how to use it. Also tried using the String to Byte Array function but do not know how to use the array to obatin values that correspond to a voltage.
    Thanks.

    LabVIEW uses Big Endian format for its binary numbers, while most Windows programs use Little Endian format. LabVIEW uses Big Endian, because that is what the MacOS uses, and LabVIEW was created first for the Macintosh. So must test and see what is correct.  In my example I have assumed that the datatype is I16, but it could also be U16
    Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
    (Sorry no Labview "brag list" so far)
    Attachments:
    demo.vi ‏9 KB

  • SimpleDateFormat parses wrong date successfully (lenient = false). Why?

    Hi
    I've got a problem validating date by SimpleDateFormat. Format "yyyy" successfully parses string like "2009-78" into date 01.01.2009. Can you please help me with it?
    Here is my code:
    SimpleDateFormat format = new SimpleDateFormat("yyyy");
    format.setLenient(false);
    String dateStr = "2009-78";
    Date date;
    try {
        date = format.parse(dateStr);
    } catch (ParseException e) {
        date = null;
        e.printStackTrace();
    System.out.println(String.format("String '%s' parsed to date %s", dateStr, date));Output:
    String '2009-78' parsed to date Thu Jan 01 00:00:00 MSK 2009I need an exception to be thrown in such situation. How can I check where the string represents a correct date?
    Thanks for your help.
    Evgeny
    Edited by: su.eug on Apr 13, 2009 12:56 AM

    Read the comments in the API:
    [http://java.sun.com/javase/6/docs/api/java/text/DateFormat.html#parse(java.lang.String)|http://java.sun.com/javase/6/docs/api/java/text/DateFormat.html#parse(java.lang.String)]
    You could try the other overload of parse, if you want to test whether the whole String was used:
    [http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html#parse(java.lang.String, java.text.ParsePosition)|http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html#parse(java.lang.String,%20java.text.ParsePosition)]
    (Sorry--the second link doesn't go to the right place. There is a version of "parse" with two parameters, which you can use to determine if the whole String was used.)

  • Script for parsing xml data and inserting in DB

    Thank you for reading.
    I have the following example XML in an XML file. I need to write a script that can insert this data into an Oracle table. The table does not have primary keys. The data just needs to be inserted.
    I do not have xsd file in this scenario. Please suggest how to modify Method 1 https://community.oracle.com/thread/1115266?tstart=0 mentioned so that I can call the XML mentioned below and insert into a table
    Method 1
    Create or replace procedure parse_xml is 
      l_bfile   BFILE; 
      l_clob    CLOB; 
      l_parser  dbms_xmlparser.Parser; 
      l_doc     dbms_xmldom.DOMDocument; 
      l_nl      dbms_xmldom.DOMNodeList; 
      l_n       dbms_xmldom.DOMNode; 
      l_file      dbms_xmldom.DOMNodeList; 
      l_filen       dbms_xmldom.DOMNode; 
      lv_value VARCHAR2(1000); 
       l_ch      dbms_xmldom.DOMNode; 
    l_partname varchar2(100); 
    l_filename varchar2(1000); 
      l_temp    VARCHAR2(1000); 
      TYPE tab_type IS TABLE OF tab_software_parts%ROWTYPE; 
      t_tab  tab_type := tab_type(); 
    BEGIN 
      l_bfile := BFileName('DIR1', 'SoftwareParts.xml'); 
      dbms_lob.createtemporary(l_clob, cache=>FALSE); 
      dbms_lob.open(l_bfile, dbms_lob.lob_readonly); 
      dbms_lob.loadFromFile(dest_lob => l_clob,    src_lob  => l_bfile,    amount   => dbms_lob.getLength(l_bfile)); 
      dbms_lob.close(l_bfile);  
      dbms_session.set_nls('NLS_DATE_FORMAT','''DD-MON-YYYY'''); 
      l_parser := dbms_xmlparser.newParser; 
      dbms_xmlparser.parseClob(l_parser, l_clob); 
      l_doc := dbms_xmlparser.getDocument(l_parser); 
        dbms_lob.freetemporary(l_clob); 
      dbms_xmlparser.freeParser(l_parser); 
      l_nl := dbms_xslprocessor.selectNodes(dbms_xmldom.makeNode(l_doc),'/PartDetails/Part'); 
        FOR cur_emp IN 0 .. dbms_xmldom.getLength(l_nl) - 1 LOOP 
        l_n := dbms_xmldom.item(l_nl, cur_emp); 
        t_tab.extend; 
        dbms_xslprocessor.valueOf(l_n,'Name/text()',l_partname); 
        t_tab(t_tab.last).partname := l_partname; 
        l_file := dbms_xslprocessor.selectNodes(l_n,'Files/FileName'); 
        FOR cur_ch IN 0 .. dbms_xmldom.getLength(l_file) - 1 LOOP 
          l_ch := dbms_xmldom.item(l_file, cur_ch); 
          lv_value := dbms_xmldom.getnodevalue(dbms_xmldom.getfirstchild(l_ch)); 
          if t_tab(t_tab.last).partname is null then t_tab(t_tab.last).partname := l_partname; end if; 
          t_tab(t_tab.last).filename := lv_value; 
        t_tab.extend; 
       END LOOP; 
       END LOOP; 
        t_tab.delete(t_tab.last); 
      FOR cur_emp IN t_tab.first .. t_tab.last LOOP 
      if t_tab(cur_emp).partname is not null and  t_tab(cur_emp).filename is not null then 
        INSERT INTO tab_software_parts 
        VALUES 
        (t_tab(cur_emp).partname, t_tab(cur_emp).filename); 
        end if; 
      END LOOP; 
      COMMIT; 
      dbms_xmldom.freeDocument(l_doc); 
    EXCEPTION 
      WHEN OTHERS THEN 
        dbms_lob.freetemporary(l_clob); 
        dbms_xmlparser.freeParser(l_parser); 
        dbms_xmldom.freeDocument(l_doc); 
    END; 
    <TWObject className="TWObject">
      <array size="240">
        <item>
          <variable type="QuestionDetail">
            <questionId type="String"><![CDATA[30]]></questionId>
            <questionType type="questionType"><![CDATA[COUNTRY]]></questionType>
            <country type="String"><![CDATA[GB]]></country>
            <questionText type="String"><![CDATA[Please indicate]]></questionText>
            <optionType type="String"><![CDATA[RadioButton]]></optionType>
            <answerOptions type="String[]">
              <item><![CDATA[Yes]]></item>
              <item><![CDATA[No]]></item>
            </answerOptions>
            <ruleId type="String"><![CDATA[CRP_GB001]]></ruleId>
            <parentQuestionId type="String"></parentQuestionId>
            <parentQuestionResp type="String"></parentQuestionResp>
          </variable>
        </item>
        <item>
          <variable type="QuestionDetail">
            <questionId type="String"><![CDATA[40]]></questionId>
            <questionType type="questionType"><![CDATA[COUNTRY]]></questionType>
            <country type="String"><![CDATA[DE]]></country>
            <questionText type="String"><![CDATA[Please indicate]]></questionText>
            <optionType type="String"><![CDATA[RadioButton]]></optionType>
            <answerOptions type="String[]">
              <item><![CDATA[Yes]]></item>
              <item><![CDATA[No]]></item>
            </answerOptions>
            <ruleId type="String"><![CDATA[CRP_Q0001]]></ruleId>
            <parentQuestionId type="String"></parentQuestionId>
            <parentQuestionResp type="String"></parentQuestionResp>
          </variable>
        </item>
      </array>
    </TWObject>

    Reposted as
    Script to parse XML data into Oracle DB

  • Parsing XML data stored as CLOB in DB and save attribute values in table

    Hello,
    I have a CLOB column in table that is holding XML data as follows,
    <banners>
    <banner-image id="0">
    <type>BANNER</type>
    <local-path>http.gif</local-path>
    <click-through-url>www</click-through-url>
    <make>Acura</make>
    </banner-image>
    <banner-image id="1">
    <type>BANNER</type>
    <local-path>http.gif</local-path>
    <click-through-url>gfrty</click-through-url>
    <make>BMW</make>
    </banner-image>
    </banners>
    Now I need to parse thru the above XML data and pull the attribute values to store in another table as follows,
    BANNER_IMAGE_ID | TYPE | LOCAL_PATH | CLICK_URL | MAKE
    0 | BANNER | http.gif | www | Acura
    1 | BANNER | http.gif | gfrty | BMW
    And XML data doesn't always end up with 2 rows in this table....some times it may be 3 or 4 as well. It is just that in this example it ended up with 2 rows.
    So, I would appreciate if someone can help me find a generic way of doing this,
    Thank you in advance,
    Madhu.

    This is not a reply.. sorry.
    I took have a similar problem only..
    can you pls help me
    XML structure.
    <PODetails>
    <POHeader>
    <CurrencyID>INR</CurrencyID>
    <ExchangeRate>1</ExchangeRate>
    <RefNo>0080000110</RefNo>
    <VendorID>1200</VendorID>
    <TransDate>2006-12-20</TransDate>
    <DocRelationshipId>PURCHASE</DocRelationshipId>
    <LocationID>0000102327</LocationID>
    </POHeader>
    <POItemDetails>
    <ItemID>ARSH1332</ItemID>
    <Size>L HS</Size>
    <Quality>Q1</Quality>
    <CustPO>rush order</CustPO>
    <UOM>PC</UOM>
    <Quantity>3.000</Quantity>
    <PriceValue>2509.5</PriceValue>
    <TaxAmount>0.00</TaxAmount>
    </POItemDetails>
    <POItemDetails>
    <ItemID>ARSH1332</ItemID>
    <Size>M HS</Size>
    <Quality>Q1</Quality>
    <CustPO>rush order</CustPO>
    <UOM>PC</UOM>
    <Quantity>2.000</Quantity>
    <PriceValue>1673</PriceValue>
    <TaxAmount>0.00</TaxAmount>
    </POItemDetails>
    <POItemDetails>
    <ItemID>ARSH1556</ItemID>
    <Size>39FS</Size>
    <Quality>Q1</Quality>
    <CustPO>rush order</CustPO>
    <UOM>PC</UOM>
    <Quantity>1.000</Quantity>
    <PriceValue>836.5</PriceValue>
    <TaxAmount>0.00</TaxAmount>
    </POItemDetails>
    </PODetails>
    The DB is ORACLE 9i
    This is stored in a XML table of type XMLTYPE.
    THIS I USED THE .extract function to get the values of the nodes.
    POHeader details are working fine. But when i get the POItemDetails i am getting 'ARSH1332ARSH1332ARSH1556' when i issue the command
    select a.extract('/PODetails/POItemDetails/ItemID/text()').getStringVal() ItemID
    FROM xmltable a
    WHERE a.existsnode('//POItemDetails/ItemID')=1
    Pls Help..
    Regds,
    Santhoshkumar.G.

  • How do you store parsed XML data in an array

    Hi, i am trying to complete a small program which implements the SAX parser to parse an XML file. My problem is that i am writing a custom class to store the parsed data into an array, and then make the array available to the main program via a simple method which returns the array. I know this must be very simple to do, but i seem to have developed a mental block with this part of the program. I can parse the data and print all the elements to the screen, but i just cant figure out how to store all the data elements into the array. I will post the class which is supposed to do this, and ask anyone out there if they know what i'm doing wrong, and also, if there is a more effeicient way of achieving this ( i expect there definitely is!! but i have never used the SAX parser before and am getting confused by the API docs on it!!) Any help very much appreciated.
    Here is my attempt at coding the class to handle the parsed XML data
    class Sink extends org.xml.sax.helpers.DefaultHandler
         implements org.xml.sax.ContentHandler{
    Customer[] customers = new Customer[20];
         int count = 1;
         int x = 0;
         int tagCount = 0;
         String name;
    String custID;
         String username;
         String address;
         String phoneNum;
    public void startElement(String uri, String localName, String rawName, final org.xml.sax.Attributes attributes)throws org.xml.sax.SAXException{
    //count the number of <name> tags in the XML file
         if(rawName.equals("name")){
              tagCount++;
    public void characters(char[] ch, int start, int len){
    //get the current string
         String text = new String(ch, start, len);
         String text1 = text.trim();
    //there are 5 elements for each customer found in the XML file so when the count reaches 6
    // i reset this to 1
         if(count == 6){
         count = count - 5;
         if(text1.length()>0 && count == 1){
              name = text1;
              System.out.println(name);
              }else{
         if(text1.length()>0 && count == 2){
              custID = text1;
              System.out.println(custID);
                   }else{
                   if(text1.length()>0 && count == 3){
                   username = text1;
                   System.out.println(username);
                   }else{
                        if(text1.length()>0 && count == 4){
                        address = text1;
                        System.out.println(address);
                        }else{
                        if(text1.length()>0 && count == 5){
                             phoneNum = text1;
                             System.out.println(phoneNum);
                             //add data to the customer array
                             customers[x] = new Customer(name, custID, username, address, phoneNum);
    // increment the array index counter
                        x = x+1;
                        }//end of if
                        }//end else
                        }//end else
                   }//end else
              }//end else
    }//end of characters method
    public void endDocument(){
         System.out.println("There are " + tagCount +
         " <name> elements.");
    }//end of class Sink
    Before the end of this class i also need to make the array available to the calling program!!
    Any help would be much appreciated
    Thanks
    Iain

    Ok, yer going about this all the wrong way. You shouldn't have to maintain a count of all the elements. Basically you are locking yourself into the XML tags not only all being there but are assuming they are all in the same order. What you should do is in your characters() method, put all of the characters into a string buffer. Then, in endElement() (which you dont use btw, you should) you grab the information that is in the string buffer and store it into your Customer object depending on what the tagName is.
    Also, you should probably use a List to store all the Customer objects and not an single array, it's more dynamic and you arent locked into a set number of Customers.
    I wont do it all for you, but I'll give you a good outline to use.
    public class CustomerHandler extends DefaultHandler {
        private java.util.List customerList;  // List of Customer objects
        private java.util.StringBuffer buf;   // StringBuffer to store the string of characters between the start and end tags
        private Customer customer;  // Customer object that is initialized with each entry.
        public CustomerHandler() {
            customerList = new java.util.ArrayList();   // Initialize the List
            buf = new java.util.StringBuffer();   // Initialize the string buffer
        //  Make your customer list available to other classes
        public java.util.List getCustomerList() {
            return customerList;
        public void startElement(String nsURI, String sName, String tagName, Attributes attributes) throws SAXException {
            // Clear the String Buffer
            //  If the tagName is "Customer" then create a new Customer object
        public void characters(char[] ch, int start, int length) {
            //  append the characters into the string buffer
        public void endElement(String nsURI, String sName, String tagName) throws SAXException {
            // If the tagName is "Customer" add your customer object to the List
            // Place the data from the String Buffer into a String
            //  Depending on the tagName, call the appropriate set method on your customer object
    }

  • Error parsing output

    Hi There,
    New to the Java World and Im getting the following error when submitting this java program for compilation and output. Output is Via a html page
    // just import the BufferedReader and inputstream reader
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    class addtwonumbers
        public static void main(String[] args)
        // system.in reader (e.g. the input from the console)
        InputStreamReader ISR = new InputStreamReader(System.in);
        // buffer the console reader
        BufferedReader BR = new BufferedReader(ISR);
        // the default values for the two numbers
        int val1 = 0;
        int val2 = 0;
        try
            // output the question.
            System.out.print("Enter two Numbers:\n");
            // read in the console intput one line (BR.readLine) and then convert to a integer
            val1 = Integer.parseInt(BR.readLine());
            val2 = Integer.parseInt(BR.readLine());
        catch (Exception ex)
            //if the input was a string.
            System.out.println(ex.toString());
        // output the answer of adding both of the values together and * by 3
        System.out.println("The result is " + (val1 + val2) * 3 );
    The error message is "Error parsing output, please try again"
    Thanks In advance.
    Edited by: Conor O'Neill on Mar 16, 2009 4:11 PM

    >
    Conor O'Neill wrote:
    > Hi Ayyapparaj
    >
    > Thanks for getting back to me: yes I already have done what you suggested and it works fine, but I'm trying to output in an HTML page (in a table).
    Hi,
    What you mean by HTML page(in a table)?
    Code what you have written above is a pure application that need to be run in the way i have mentioned above.
    If you are interested to create a HTML page where you can enter two numbers and print their out put. You need to change the code altogether.
    Regards
    Ayyapparaj

Maybe you are looking for

  • Error getting drill information in OBIEE 11.1.1.5

    Guru's, in OBIEE 11.1.1.5 I created a simple report with 3 columns: the year column from a time dimension table, a measure from a fact table and column from another dimension table. The report shows the results as expected. But when I try to drill do

  • I had to get a new hard drive for my laptop.  Need help?

    I had to get a new hard drive for my laptop. Downloaded iTunes and now it says "this ipod it synced with another itunes library.Do you want to erase this ipod and sync with this itunes library."   Will it erase everything on my touch?

  • Macbook pro chimes but black screen

    I have a MacBook Pro with 15 in Retina Display. When I go to turn on my Mac, it chimes, like usually, but the screen apparently stays black (lighting up a little). The apple logo in the back is lit as well, as if the computer is on. I have tried PRAM

  • Can't find an option of Init Delta when creating InfoPackage.

    Hi Experts, I am working on BW 7.0 implementing HCM. I am creating InfoPackages for both Master and Transaction data. My concern is... I don't find an option of selecting 'Init Delta' while creating the InfoPackages. I have setup Deltas for all the D

  • Adobe CS5 in Thin VDI environment

    My company is moving to a thin client VDI environment.  Our shop is a graphic, photo, and video shop currently using Adobe CS5 Master Collection.  We primarily use Photoshop, Illustrator, and Premier Pro.  Will these programs be fully functional in a