Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to parse an HTML-like file??

How to parse an HTML-like file??

Scheduled Pinned Locked Moved C / C++ / MFC
htmlxmltutorialquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Paolo Ponzano
    wrote on last edited by
    #1

    hello, I need to parse a text file and take some tag as or , I need it to be written in C, do you think I better use an XML parser ( if yes, which one should I use?, I premitt that I've not got much experience with XML) or should I better so it sequentially by doing if( strcmp(line,"<cover..............)??? thanks in advance Paolo

    J R J 3 Replies Last reply
    0
    • P Paolo Ponzano

      hello, I need to parse a text file and take some tag as or , I need it to be written in C, do you think I better use an XML parser ( if yes, which one should I use?, I premitt that I've not got much experience with XML) or should I better so it sequentially by doing if( strcmp(line,"<cover..............)??? thanks in advance Paolo

      J Offline
      J Offline
      Johan Rosengren
      wrote on last edited by
      #2

      Easiest will be to process the input char-by-char. Use a state machine, switching states when you reach a '<' or a '>', adding the finished tags or between-tag-content to arrays as appropriate. As a matter of a fact, you should have state changes for spaces and '='s inside the tags as well.

      1 Reply Last reply
      0
      • P Paolo Ponzano

        hello, I need to parse a text file and take some tag as or , I need it to be written in C, do you think I better use an XML parser ( if yes, which one should I use?, I premitt that I've not got much experience with XML) or should I better so it sequentially by doing if( strcmp(line,"<cover..............)??? thanks in advance Paolo

        R Offline
        R Offline
        Ravi Bhavnani
        wrote on last edited by
        #3

        You can use the static string parsing methods in this[^] article to do exactly that. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

        1 Reply Last reply
        0
        • P Paolo Ponzano

          hello, I need to parse a text file and take some tag as or , I need it to be written in C, do you think I better use an XML parser ( if yes, which one should I use?, I premitt that I've not got much experience with XML) or should I better so it sequentially by doing if( strcmp(line,"<cover..............)??? thanks in advance Paolo

          J Offline
          J Offline
          Jorgen Sigvardsson
          wrote on last edited by
          #4

          A SAX-parser would probably be the best solution for you. They're fast and they don't require lots of memory. Parsing XML using SAX-parsers is kind of like recursive descent parsing if I'm not mistaken. When the parser finds an element <img, it'll call your callback, notifying you of that. Then when it finds href="img", it'll call your callback notifying you of that. So, basically you need two (possibly three) callbacks. One for notifying you that you've <img has begun, one that tells you href="img" was found, and possibly one that says </img>. Here's one such parser: libxml2[^]. It's licensed under the MIT License, so there's no problem using it in a closed source/commercial application. -- Ich bin Joachim von Hassel, und ich bin Pilot der Bundeswehr. Welle: Erdball - F104-G Starfighter

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups