How do I parse this string?

I have a string of html , which looks like this:
<head></head><body><p>Stringof<strong><em>tags</em></strong>inhtml</p>
I have to go ahead a search for the tags and put them into a tree.
for instance.
<head> would be the root, then I would go to <p> and get the contents thereof, where <em> and <strong> would be child nodes.
I am not sure how to look throw a string and search for these things. can anyone suggest a good way of doing this?
Originally I was thinking of going through it like an array, but apparently that is illegal.
Thanks.

You're throwing away the first line of the file.
This line of code:
               String line = in.readLine();reads in the first line, but then you ignore what's in line.
You should change it to just:
               String line;Similarly, you're throwing away alternate lines of input with this line of code:
                    line = in.readLine();You should just remove that.
[add] ...you're too fast for me
Edited by: paulcw on Oct 18, 2008 5:44 PM

Similar Messages

  • Anyone know how I can parse this string?

    Hello everyone!
    I'm using the Scanner class (which is like the StringTokenizer class but suppose to be more powerful).
    Anyways, I have the following String:
    OP '1.3.12.2.1004.212'.'1.3.12.2.1004.195'
    I want to parse the String so I have the following:
    '1.3.12.2.1004.212'
    '1.3.12.2.1004.195'
    so basically just parse it by the middle dot, I tried useDelimeter function and it doesn't parse it up at all. You would think it would have parsed every occurance of . but that isn't the case.
    Here is my code:
    else if(line.contains("OP"))
                             System.out.println("HIT THE SUBFIELD PART lulz");
                             String subClassName = "";
                             String subFieldName = "";
                             scan = new Scanner(line);
                             scan.useDelimiter(".");
                             System.out.println("LINE: " + line);
                             while(scan.hasNext())
                                  System.out.println("Token: " + scan.next());
                             }The output is the following:
    HIT THE SUBFIELD PART LOL
    LINE: OP '1.3.12.2.1004.212'.'iPAddress'
    Token:
    Token:
    Token:
    Token:
    Token:
    Token:
    Token:
    Any ideas what I can do to parse it up the way I mentioned above? thanks!

    hm..it just occured to me I could do the following
    else if(line.contains("OP"))
                             System.out.println("HIT THE SUBFIELD PART lulz");
                             String subClassName = "";
                             String subFieldName = "";
                             scan = new Scanner(line);
                             scan.skip("OP");
                             scan.useDelimiter("'.'");
                             System.out.println("LINE: " + line);
                             while(scan.hasNext())
                                  System.out.println("LOOK HERE: " + scan.next());
                             }I get the following output:
    LINE: OP '1.3.12.2.1004.212'.'iPAddress'
    LOOK HERE: '1.3.12.2.1004.212
    LOOK HERE: iPAddress'
    So I guess I can just manually manipulate that last token and readd the ' character!
    I think thats what I will do but if you can find a bettter solution let me know! thanks! :D

  • How can I parse a String to Timestamp type??

    Hi, I receive a String time="07.05.2007 12:30:20", I want to parse this String to a Timestamp type, how to do that?

    I use the following code to parse String to Date, but it throw unhandled exception, type parse exception. It seems the parse source "07.05.2007 12:30:10" has problem.
    SimpleDateFormat sdfTest=new SimpleDateFormat("dd.mm.YYYY HH:mm:ss");
         Date newDate=sdfTest.parse("07.05.2007 12:30:10");
    Please give me some suggestion.
    Message was edited by:
    Mellon

  • How do i parse a string

    Can somebody tell me the function used to parse a string and how it works? All I want to do is seperate the string 'AG-01' into another string 'AG-' and an int '01'. I have been through numerous resources and have found nothing at all on parsing functions.

    This in one way:
    String txt = "AG-01";
    String first = txt.substring(0,3);
    int second = Integer.parseInt(txt.substring(3,5));
    %>
    First string:<%=first%>
    Second int :<%=second%>
    Bye
    Beck74

  • How do i parse this, using JDOM?!

    This xml is in the form of a String, can someone tell me how to use JDOM to parse this, i've actually made a start:
    SAXBuilder builder = new SAXBuilder();
    Reader r = new StringReader(str1);
    Document doc = builder.build(r);
    <StockQuotes>
    <Stock>
    <Symbol>IBM</Symbol>
    <Last>111.32</Last>
    <Date>8/1/2007</Date>
    <Change>+0.67</Change>
    <Open>110.39</Open>
    <High>111.95</High>
    <Low>110.06</Low>
    </Stock>
    </StockQuotes>
    and then im kinda lost... please help! really need it!
    cheers,
    Shivek Sachdev

    hey,
    thanks a lot for the reply.
    i get the idea now, to be able to trace to the childrens
    but it would be really helpful if u can give me a more complete version of the code, im really new to this stuff.
    i did wat u told:
    List stock = root.getChildren();
    //now im at the 2nd level
    how do i get to <Symbol> so that i can print out the value of that tag.
    cheers,
    Shivek Sachdev

  • How can I write this string to a file as the ASCII representation in Hex format?

    I need to convert a number ( say 16000 ) to Hex string ( say 803E = 16,000) and send it using Visa Serial with the string control in Hex Mode. I have no problem with the conversion (see attached). My full command in the hex display must read AA00 2380 3E...
    I can easily get the string together when in Normal mode to read AA0023803E... but how can I get this to hex mode without converting? (i.e. 4141 3030 3233 3830 3345 3030 3030 3031 )
    Attachments:
    volt to HEX.vi ‏32 KB

    Sorry, The little endian option was probably introduced in 8.0 (?).
    In this special case it's simple, just reverse the string before concatenating with the rest.
    It should be in the string palette, probably under "additional string functions".
    (note that this only works in this special case flattening a single number as we do here. If the stat structure is more complex (array, cluster, etc.) you would need to do a bit more work.
    Actually, you might just use typecast as follows. Same difference.
    I only used the flatten operation because of the little endian option in my version.
    Message Edited by altenbach on 11-16-2007 11:53 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    littleendian71.png ‏4 KB
    littleEndiancast71.png ‏4 KB

  • How do I change this string  Please someone help this newbie :)

    Hi All
    I have a string which is a list of file in a folder. I am putting this list into a submenu. The files are formated like this
    Jesse_Smith_08_08_2001
    Jackie_Test_04_04_2000
    I would like to view them like this
    Jesse Smith 08.08.01
    Jackie Test 04.04.00
    How can I do this
    PLEASE HLEP ME
    I have spent 2 days trying to do this
    Craig

    Thanks for the code tolmark
    Can I ask one more this?
    How can I integrate your code into this code ??
    private void addItem(JMenu menu, char a)
        //Get file names from folder "Epod Configuration/Orders To Upload/"
        File dir = new File("Epod Configuration/Orders To Upload");
        File[] files = dir.listFiles();
        for (int j=0; j < files.length; j++)
          String trim = ""+files[j];
          int ndx;
          if ((ndx = trim.lastIndexOf('/')) != -1) trim = trim.substring(ndx+1);
          if (trim.charAt(0) == a);
          String s = trim;
          int idx = s.lastIndexOf('.');
          // remove extension
          if (idx != -1)
            s = s.substring(0, idx);
          System.out.println(s);
            JMenuItem mi = new JMenuItem(s);
            menu.add(mi);
      }sorry to have to ask but I just can't seam to do it .
    Thanks
    Craig

  • How can I parse this date format?

    Hey,
    i am trying to write an interface between two applications. One application gives me the following date:
         Wed Jul 16 12:18:20 CEST 2003
    but I need it to look like this:
         16.07.03 12.18:20
    I tryed to use Date and DateFormat to parse and change it but the Date was unparseable.
    I hope somebody can point me to the right direction or show me how I can do the formating.
    Thanx a lot!
    Martin

    If this isn't a well-known date format, I can't see any solution but to write small function yourself which doe the job.
    you can start with :
    String source = "Wed Jul 16 12:18:20 CEST 2003";
    String[] elements = source.split();//splits source around spaces
    then you write functions that map day of week with numbers
    "Mon" --> 1
    "Tue" --> 2
    etc...
    it won't take you days to write this.
    Sometimes it's faster to write the stuff yourself than spending days looking for something pre-defined that may or may not exist.

  • How can I parser a String with javax.xml.parsers.DocumentBuilder?

    Normally the DocumentBuilder can parse files, InputSource,InputStream or uri. but what if I want to parse an editing String the user created in an EditPane or JTextComponent?

    new InputSource(new StringReader(theString))

  • How do you convert this String into a double?

    Hi, in this code I want to convert String arg into a double. I'm trying to do this so that I can convert some string into a double in this calculator that I'm making. Here is the code:
    public class par {
    public static void main(String[] args) {
    String str = "351";
    double arg = new double(str); // should convert the string into a double
         System.out.println(arg);
         System.out.println(str);
    I keep getting errors in line 4, if any of you could help me out here I'll be thankful, i'm kinda new to java and my search for java's equivalent of alof() (its a function in C libraries that converts char[] into a double)lead me to this.
    Tony L.

    Use the Following:
    String num = "123.2";
    double d = Double.parseDouble(num);

  • How can  parse this xml tag " Cell ID="0" Type="String" Afghanistan cell "

    Hi,
    I have to parse this type of xml file.
    so how can i parse this type of xml file like
    <Row ID="1">
    <Cell ID="0" Type="String" >Afghanistan</Cell>
    <Cell ID="1" Type="Number" >93</Cell>
    <Cell ID="2" Type="Number" >0</Cell>
    <Cell ID="3" Type="Number" >1</Cell>
    </Row>

    You haven't given us enough information. Is this for iPhone or Mac OS X? What language are you using? etc.

  • How to Break this String and put into a Table

    Hi all,
    Currently i working on the Reading of Csv file.THe Csv file wil be stored as BLOB in one table.
    The Format of the Csv file is
    EMPCODE :DATEOFBIRTH
    312089 ,12/01/1984
    321456 ,03/05/1980
    120212 ,04/08/1987
    312456 ,23/12/1977
    311110 ,12/04/1998
    323232 ,20/06/1990
    UPLOAD_BLOB
    column     Datatype
    UploadId Number
    File_details BLOB
    And i reading the BLOB in one procedure and i m getting the String as like this ---->
    "312089 ,12/01/1984
    321456 ,03/05/1980
    120212 ,04/08/1987
    312456 ,23/12/1977
    311110 ,12/04/1998
    323232 ,20/06/1990"
    I am Dont know how to Parse this String and put in table
    While 1<STRING.LENGTH
    LOOP
    EMPCODE=SUBSTRING();
    DATEOFBIRTH=SUBSTRING();
    INSERT INTO TABLE VALID_EMPCODE(EMPCODE,DATEOFBIRTH)VALUES(......);END LOOP
    VALID_EMPCODE
    EMPCODE VARCHAR2(30)
    DATEOFBIRTH VARCHAR2(15)
    Can any one tell me how to parse this whole string and break them

    Duplicate post
    How to Break this String and put into a Table

  • Parsing formatted String to Int

    How can I parse formatted string to Integer ?
    I have a formated string like this $900,000 and I need to convert it to 900000 so I could do calculations with it.
    I tried something like this
    NumberFormat nf = NumberFormat.getIntegerInstance(request.getLocale());
    ttlMargin=nf.parse(screenVal);I got this exception
    "java.lang.NumberFormatException: For input string: "$1,050,000""

    I am working on the JSP file that provides
    margins,sales etc. I am reading this data off the
    screen where it is beeing displayed according to the
    accounting practices.
    That's why I get it as a formatted string and why I
    am trying covert that string to the numberScreen-scraping is a problematic, bad design. It sounds like what you really want is to call a web service which returns its results as data that a program can understand (XML, for example), not HTML (which is meant more for humans to read). I know, you probably can't change the design at this point... just food for thought. In the meantime, you'll probably have to manually parse those strings yourself by stripping out the '$' and ',' characters and then use parseInt on the result.

  • Parse a String to boolean

    How do you parse a String to boolean, isn't like this? I get this inconertible types error, that require boolean
    boolean all = (boolean)tokens.nextToken();
    Thanks!

    What string means true, and what string means false? The string "true" or "false"? In that case, you can simply use the Boolean.valueOf(String) method:
    public static Boolean valueOf(String s)
        Returns a Boolean with a value represented by the specified String. The Boolean returned represents the value true if the string argument is not null and is equal, ignoring case, to the string "true".
        Example: Boolean.valueOf("True") returns true.
        Example: Boolean.valueOf("yes") returns false.
        Parameters:
            s - a string.
        Returns:
            the Boolean value represented by the string.Otherwise, you can use something like:
      boolean b = string.equals("true");or if string can be null to also mean false:
      boolean b = "true".equals(string);

  • Parsing a string in a given order

    Hi All,
    I want to parse a string and rank it in a given order.
    Eg : i have a string as 'A | B | C | D'. I would like to parse this string and give a rank in order.
    It should appear as below.
    Parsed string order
    D 1
    C 2
    B 3
    A 4
    Any help is greatly appreciated..

    A database version would help us providing you with a relevant solution.
    Starting with 10g, you can do :
    SQL> var my_str varchar2(30)
    SQL> exec :my_str := 'A|B|C|D'
    PL/SQL procedure successfully completed
    SQL> select item
      2       , row_number() over(order by item desc) as rank
      3  from (
      4    select regexp_substr(:my_str,'[^|]+',1,level) as item
      5    from dual
      6    connect by level <= length(regexp_replace(:my_str,'[^|]+')) + 1
      7  );
    ITEM                    RANK
    D                          1
    C                          2
    B                          3
    A                          4
    In 11.2 :
    SQL> select *
      2  from xmltable(
      3       'for $i in ora:tokenize($str,"\|") order by $i descending return $i'
      4       passing 'A|B|C|D' as "str"
      5       columns item varchar2(10) path '.'
      6             , rank for ordinality
      7       )
      8  ;
    ITEM             RANK
    D                   1
    C                   2
    B                   3
    A                   4
    Edited by: odie_63 on 11 janv. 2012 12:56 - added 11.2

Maybe you are looking for

  • How can I use spotlight on ipad air to find docs in pages?

    I was hoping the spotlight would find doc with terms (e.g. Shawl, HOA) in the title, it it doesn't seem to search that deep into apps.  Is this not possible or am I missing something in settings?   I would like to find all docs or PDF files in Pages

  • How to execute this procedure(having out parameters)

    PROCEDURE emp_cursor ( v_deptno IN VARCHAR2, v_doj OUT DATE, v_empno OUT NUMBER, v_sal OUT NUMBER );

  • Does Final Cut Pro Studio work on old powerbook?

    I'm planning to buy the Final Cut Pro Studio package, but before I want to be sure that it will work fine on my PowerBook. I have enough Processor (G4 1Ghz) and RAM (1Gb) as apple suggest, but I'm worried about the supported graphics cards listed on

  • Move music to new computer

    I need to move music from ipod to a new computer

  • Rec's to convert PAL DVDs to NTSC?

    Hello, I've run into a video conversion issue and was hoping to get some guidance. So a friend mistakenly gifted me a DVD that was not NTSC/Region 1; I didn't realize this at first when I inserted and tried playing it in my Macbook, but unfortunately