2003-05-08 10:04:02 +00:00
|
|
|
/** 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 2
|
|
|
|
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 COPYING.LIB.
|
|
|
|
If not, write to the Free Software Foundation,
|
|
|
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <stdio.h>
|
2004-01-15 04:07:08 +00:00
|
|
|
#ifdef NeXT_Foundation_LIBRARY
|
|
|
|
#include <Foundation/Foundation.h>
|
|
|
|
#include <GNUstepBase/GSCategories.h>
|
|
|
|
#else
|
2003-05-08 10:04:02 +00:00
|
|
|
#include <Foundation/NSArray.h>
|
|
|
|
#include <Foundation/NSAutoreleasePool.h>
|
|
|
|
#include <Foundation/NSObjCRuntime.h>
|
|
|
|
#include <Foundation/NSProcessInfo.h>
|
2004-01-15 04:07:08 +00:00
|
|
|
#endif
|
2003-07-31 23:49:32 +00:00
|
|
|
#include <GNUstepBase/GSXML.h>
|
2003-05-08 10:04:02 +00:00
|
|
|
|
|
|
|
@interface GSXMLParser (Loader)
|
|
|
|
+ (NSString*) loadEntity: (NSString*)publicId
|
|
|
|
at: (NSString*)location;
|
|
|
|
@end
|
|
|
|
@implementation GSXMLParser (Loader)
|
|
|
|
+ (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 stringWithCString: buf];
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2004-03-29 03:37:46 +00:00
|
|
|
/** <p>This tool error-checks and validates xml documents. The parse
|
|
|
|
is simply discarded after checking.
|
|
|
|
</p> */
|
2003-05-08 10:04:02 +00:00
|
|
|
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
|
|
|
|
[NSProcessInfo initializeWithArguments: argv count: argc environment: 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");
|
2003-05-12 20:42:47 +00:00
|
|
|
exit(EXIT_FAILURE);
|
2003-05-08 10:04:02 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
proc = [NSProcessInfo processInfo];
|
|
|
|
if (proc == nil)
|
|
|
|
{
|
|
|
|
NSLog(@"unable to get process information!");
|
2003-05-12 20:42:47 +00:00
|
|
|
exit(EXIT_FAILURE);
|
2003-05-08 10:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
files = [proc arguments];
|
|
|
|
count = [files count];
|
|
|
|
for (i = 1; i < count; i++)
|
|
|
|
{
|
|
|
|
NSString *file = [files objectAtIndex: i];
|
|
|
|
GSXMLNode *root;
|
|
|
|
GSXMLParser *parser;
|
|
|
|
|
|
|
|
parser = [GSXMLParser parserWithContentsOfFile: file];
|
|
|
|
[parser substituteEntities: NO];
|
|
|
|
[parser doValidityChecking: YES];
|
|
|
|
[parser keepBlanks: NO];
|
2003-05-22 17:00:03 +00:00
|
|
|
[parser saveMessages: YES];
|
2003-05-08 10:04:02 +00:00
|
|
|
if ([parser parse] == NO)
|
|
|
|
{
|
|
|
|
NSLog(@"WARNING %@ is not a valid document", file);
|
2003-05-22 17:00:03 +00:00
|
|
|
NSLog(@"Errors: %@", [parser messages]);
|
2003-05-08 10:04:02 +00:00
|
|
|
}
|
|
|
|
root = [[parser document] root];
|
|
|
|
NSLog(@"Document is %@", [root name]);
|
|
|
|
}
|
|
|
|
RELEASE(pool);
|
|
|
|
return 0;
|
|
|
|
}
|