2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #ifndef __SaxNamespaceSupport_H__
24 #define __SaxNamespaceSupport_H__
26 #import <Foundation/NSObject.h>
28 @class NSString, NSEnumerator, NSArray;
31 New in SAX2, defined in helpers/NamespaceSupport
33 Encapsulate Namespace logic for use by SAX drivers.
35 This class encapsulates the logic of Namespace processing: it tracks
36 the declarations currently in force for each context and automatically
37 processing raw XML 1.0 names into their Namespace parts.
39 Namespace support objects are reusable, but the reset method must be
40 invoked between each session.
42 Here is a simple session:
44 String parts[] = new String[3];
45 SaxNamespaceSupport support;
47 support = [[SaxNamespaceSupport alloc] init];
49 [support pushContext];
50 [support declarePrefix:@"" uri:@"http://www.w3.org/1999/xhtml"];
51 [support declarePrefix:@"dc" uri:@"http://www.purl.org/dc#"];
53 String parts[] = support.processName("p", parts, false);
54 System.out.println("Namespace URI: " + parts[0]);
55 System.out.println("Local name: " + parts[1]);
56 System.out.println("Raw name: " + parts[2]);
58 String parts[] = support.processName("dc:title", parts, false);
59 System.out.println("Namespace URI: " + parts[0]);
60 System.out.println("Local name: " + parts[1]);
61 System.out.println("Raw name: " + parts[2]);
65 Note that this class is optimized for the use case where most elements
66 do not contain Namespace declarations: if the same prefix/URI mapping
67 is repeated for each context (for example), this class will be somewhat
71 extern NSString *SaxXMLNS;
73 @interface SaxNamespaceSupport : NSObject
78 /* start a new ns context */
81 /* revert to previous ns context */
84 /* Declare a Namespace prefix. */
85 - (BOOL)declarePrefix:(NSString *)_prefix uri:(NSString *)_uri;
87 /* Return an enumeration of all prefixes declared in this context. */
88 - (NSEnumerator *)prefixEnumerator;
90 /* Look up a prefix and get the currently-mapped Namespace URI. */
91 - (NSString *)getUriForPrefix:(NSString *)_prefix;
93 /* Reset this Namespace support object for reuse. */
97 Process a raw XML 1.0 name.
99 This method processes a raw XML 1.0 name in the current context by
100 removing the prefix and looking it up among the prefixes currently
101 declared. The return value will be the array supplied by the caller,
102 filled in as follows:
104 parts[0] The Namespace URI, or an empty string if none is in use.
105 parts[1] The local name (without prefix).
106 parts[2] The original raw name.
108 All of the strings in the array will be internalized. If the raw name
109 has a prefix that has not been declared, then the return value will be
112 Note that attribute names are processed differently than element names:
113 an unprefixed element name will received the default Namespace (if any),
114 while an unprefixed element name will not.
116 - (NSArray *)processName:(NSString *)_rawName
117 parts:(NSArray *)_parts
118 isAttribute:(BOOL)_isAttribute;
122 #endif /* __SaxNamespaceSupport_H__ */