www.webdeveloper.com
Results 1 to 9 of 9

Thread: Help Regarding Html Parser

  1. #1
    Join Date
    Jun 2006
    Posts
    32

    Help Regarding Html Parser

    Hi all,

    Does anybody know about parsing HTML file?

    i.e.,
    similar to the one we can do in Javascript.

    For example, in javascript,
    we can get the textbox object value by using
    var val = document.getElementById('txt').value;

    Simply, I am in need of HTML DOM Parser in java?

    Is there any? Please help. Its Urgent.

    Thanks in advance for any help,

    Regards,
    Suresh.
    Regards,
    Suresh.

  2. #2
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,120
    I could be wrong, I think you may need to write one for yourself...
    On the second thought you may not need such thing at all, what exactly is you intent to do?
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  3. #3
    Join Date
    Jun 2006
    Posts
    32
    Hi Khalid,
    Thanks for your reply.

    I intend to do,

    1) I have a html file test.html
    ############
    -------------
    test.html
    -------------
    <html>
    <head>
    <script>
    function getXmlhttp() {
    if(window.XMLHttpRequest) {
    var xmlhttp = new XMLHttpRequest();
    } else {
    try {
    var xmlhttp = new ActiveXObject( 'Microsoft.XMLHTTP' );
    } catch(ee) {
    try {
    var xmlhttp = new ActiveXObject( 'Microsoft.XMLDOM' );
    } catch(e) {
    var xmlhttp = new ActiveXObject( 'Msxml2.XMLHTTP' );
    }
    }
    }
    return xmlhttp;
    }

    function updatehtml(val) {
    /* I am sending this value through ajax to update it in the temporary html file like test.html~*/
    var xmlhttp = new getXmlhttp();
    xmlhttp.open("POST", "update.do" , true);
    xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4) {
    alert(xmlhttp.responseText);
    }
    }
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8');
    xmlhttp.send("value="+val);
    }

    function savehtml() {
    /* I am copying the temp html file to original html file and then delete the temp html file through ajax*/
    var xmlhttp = new getXmlhttp();
    xmlhttp.open("POST", "save.do" , true);
    xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4) {
    alert(xmlhttp.responseText);
    }
    }
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8');
    xmlhttp.send(null);
    }

    </script>
    </head>
    <body>
    <table>
    <tr>
    <td>
    <input type="text" id="txt1" onblur="updatehtml(this.value);">
    </td>
    </tr>
    <tr>
    <td>
    <input type="text" id="txt2" onblur="updatehtml(this.value);">
    </td>
    <td>
    <input type="button" id="btnSave" onclick="savehtml();">
    </td>
    </tr>
    </table>
    </body>
    </html>
    ############

    Can u understand the code?

    For updating the values in the temp html file, I am in need of HTML parser.(i.e., parse the html file and then update the correspoding value)

    Like I told in the last post,
    How can I achieve it in Java?
    document.getElementById('txt1').value = updatedvalue;

    I used this method since if I have large html file, save is costlier.

    Is there any html parser to meet this requirement?
    Let me know if u have any doubts.

    Regards,
    Suresh
    Regards,
    Suresh.

  4. #4
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    try the org.w3c.dom package...
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  5. #5
    Join Date
    Jun 2006
    Posts
    32
    ok
    thanks for the reply.

    How to use the org.w3c.dom package?
    do u have any sample source? Please send it to me.

    Its really urgent.

    Regards,
    Suresh.
    Regards,
    Suresh.

  6. #6
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,120
    I wonder if org.w3c.dom would work. Th reason I say that is because the said package is mainly used for XML parsing and a good likely hood is that html document is not well formed xml document, therefore it will have problem loading that doc.
    I'd like to see it work though cus I never used it with HTML and it will be a good info.
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  7. #7
    Join Date
    Jun 2006
    Posts
    32
    hi khalid,
    thanx for ur reply.

    i used org.w3c.dom for xml parsing. i tried with html parsing, it didn't work.

    is there any other way to achieve this?

    Regards,
    Suresh.
    Regards,
    Suresh.

  8. #8
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,120
    org.w3c.dom works for xml its one of the popular API used in Java for this purpose...you will have to post your code, the file to help us see what u have done and why it doesn't work. In addition to that, post what errors you got.
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  9. #9
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    post your code and your XHTML (as Khalid mentioned). Don't use HTML anymore for stuff like this if you want to use DOM... it's just about standards and having well formatted pages. if your HTML isn't well formatted..then how can you really manipulate it?
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles