1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

help me to validate a html file..to check for tag matching nd nesting..

Discussion in 'C' started by satya_11, Jan 23, 2008.

  1. satya_11

    satya_11 New Member

    Joined:
    Jan 23, 2008
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    i need to write a program to open a given file and see if the nesting is fine,
    assuming that all the tags in the html string are correctly formed,
    that is when an angle bracket is seen,
    assuming that it is followed by the remainder of a complete tag.

    basically like validating infix expression..
    but i dn ve a clear idea..
    help me out!!
     
  2. Salem

    Salem New Member

    Joined:
    Nov 15, 2007
    Messages:
    133
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Please don't PM me for 1:1 support.
    Code:
    <head>
    </head>
    <body>
      <td>
        <tr>
        </tr>
      </td>
    </body>
    
    Use a stack.
    Opening tag pushed onto the stack
    Closing tag pops the stack and compares (they should be the same).
     
    shabbir likes this.
  3. satya_11

    satya_11 New Member

    Joined:
    Jan 23, 2008
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    ya..k..ll try wth tat..
     
  4. satya_11

    satya_11 New Member

    Joined:
    Jan 23, 2008
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    my prob is in pushing the html tag onto the stack..
    In start tag, once i find '<' i need to store the characters as a string till it reaches '>'..
    so that i ll be able to match d string wth d end tag..
    dono hw to extract it..:(
     
  5. Salem

    Salem New Member

    Joined:
    Nov 15, 2007
    Messages:
    133
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Please don't PM me for 1:1 support.
    while ( ch != '>' )
    perhaps?
     
  6. satya_11

    satya_11 New Member

    Joined:
    Jan 23, 2008
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    i dn get u..
    if i do so,wont i be pushing as characters into stack..
    i wanna extract as substring..
    like..


    <html>
    <body>
    sdfg
    </body>
    </html>

    In this code,
    once i reach '<' in <html>,i need to store "html" as a string..
    again wen i reach <body>,push "body" again as a string..
    and wen i reach '</',in </body>,i pop d earlier n check whether both r same..


    so,i need 2 push "html" as a singl string..
     
  7. Salem

    Salem New Member

    Joined:
    Nov 15, 2007
    Messages:
    133
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Please don't PM me for 1:1 support.
    So separate the steps,
    - read characters until you reach >
    - push the resulting string onto a stack.

    This should be a trivial problem compared to the rest of the task.
     
  8. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
    But there are some tags that don't have a closing tags like IMG which is closed with />. As an example

    <IMG src="path/to/image/file/name" />
     

Share This Page