about summary refs log tree commit diff stats
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
0 files changed, 0 insertions, 0 deletions
'/ahoang/Nim/commit/examples/htmltitle.nim?h=devel&id=08bc9ac03c49db7bfcdee82f46aadf95a324e015'>08bc9ac03 ^
b559285b7 ^
08bc9ac03 ^
db4f617af ^
08bc9ac03 ^




















08bc9ac03 ^
0d63b2519 ^
08bc9ac03 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
                                             

                                                                 





                                          
                                              
                                       
                                                     




















                                                                                
         
                                  
 
# Example program to show the parsexml module
# This program reads an HTML file and writes its title to stdout.
# Errors and whitespace are ignored.

import os, streams, parsexml, strutils

if paramCount() < 1: 
  quit("Usage: htmltitle filename[.html]")

var filename = addFileExt(ParamStr(1), "html")
var s = newFileStream(filename, fmRead)
if s == nil: quit("cannot open the file " & filename)
var x: TXmlParser
open(x, s, filename)
while true:
  x.next()
  case x.kind
  of xmlElementStart: 
    if cmpIgnoreCase(x.elementName, "title") == 0: 
      var title = ""
      x.next()  # skip "<title>"
      while x.kind == xmlCharData: 
        title.add(x.charData)
        x.next()
      if x.kind == xmlElementEnd and cmpIgnoreCase(x.elementName, "title") == 0:
        Echo("Title: " & title)
        quit(0) # Success!
      else:
        echo(x.errorMsgExpected("/title"))
  
  of xmlEof: break # end of file reached
  else: nil # ignore other events

x.close()
quit("Could not determine title!")