File: xmlparse.m

package info (click to toggle)
gnustep-base 1.31.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,580 kB
  • sloc: objc: 239,446; ansic: 36,519; cpp: 122; sh: 112; makefile: 100; xml: 32
file content (113 lines) | stat: -rw-r--r-- 3,092 bytes parent folder | download | duplicates (2)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/** This tool parses and validates xml documents.

   <title>xmlparse ... a tool to parse xml documents</title>
   Copyright (C) 2003 Free Software Foundation, Inc.

   Written by:  Richard Frith-Macdonald <richard@brainstorm.co.uk>
   Created: May 2003

   This file is part of the GNUstep Project

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; either
   version 3 of the License, or (at your option) any later version.

   You should have received a copy of the GNU General Public
   License along with this program; see the file COPYINGv3.
   If not, write to the Free Software Foundation,
   31 Milk Street #960789 Boston, MA 02196 USA.

   */

#include <stdio.h>

#import "common.h"
#import	"Foundation/NSArray.h"
#import	"Foundation/NSAutoreleasePool.h"
#import	"Foundation/NSPathUtilities.h"
#import	"Foundation/NSProcessInfo.h"
#import	"Foundation/NSUserDefaults.h"
#import "GNUstepBase/Additions.h"

@interface GSXMLParse : GSXMLParser 
+ (NSString*) loadEntity: (NSString*)publicId
                      at: (NSString*)location;
@end
@implementation	GSXMLParse : GSXMLParser 
+ (NSString*) loadEntity: (NSString*)publicId
                      at: (NSString*)location
{
  char		buf[BUFSIZ];
  NSString	*str;
  int		len;

  GSPrintf(stdout, @"Enter filename to load entity '%@' at '%@': ",
    publicId, location);
  fgets(buf, sizeof(buf)-1, stdin);
  buf[sizeof(buf)-1] = '\0';
  len = strlen(buf);
  // Strip trailing space
  while (len > 0 && buf[len-1] <= ' ')
    {
      buf[--len] = '\0';
    }
  str = [NSString stringWithUTF8String: buf];
  return str;
}
@end

/** <p>This tool error-checks and validates xml documents.  The parse
    is simply discarded after checking.
</p> */
int
main(int argc, char **argv, char **env)
{
  NSProcessInfo		*proc;
  NSArray		*files;
  unsigned int		count;
  unsigned int		i;
  CREATE_AUTORELEASE_POOL(pool);

#ifdef GS_PASS_ARGUMENTS
  GSInitializeProcess(argc, argv, env);
#endif

#ifndef HAVE_LIBXML
  NSLog(@"ERROR: The GNUstep Base Library was built\n"
@"        without an available libxml library. xmlparse needs the libxml\n"
@"        library to function. Aborting");
  exit(EXIT_FAILURE);
#endif

  proc = [NSProcessInfo processInfo];
  if (proc == nil)
    {
      NSLog(@"unable to get process information!");
      exit(EXIT_FAILURE);
    }

  files = [proc arguments];
  count = [files count];
  for (i = 1; i < count; i++)
    {
      NSString		*file = [files objectAtIndex: i];
      GSXMLNode		*root;
      GSXMLParser	*parser;

      parser = [GSXMLParse parserWithContentsOfFile: file];
      [parser substituteEntities: NO];
      [parser doValidityChecking: YES];
      [parser keepBlanks: NO];
      [parser saveMessages: YES];
      if ([parser parse] == NO)
	{
	  NSLog(@"WARNING %@ is not a valid document", file);
	  NSLog(@"Errors: %@", [parser messages]);
	}
      root = [[parser document] root];
      NSLog(@"Document is %@", [root name]);
    }
  RELEASE(pool);
  return 0;
}