2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE 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 SOPE 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 SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #ifndef __SaxNamespaceSupport_H__
23 #define __SaxNamespaceSupport_H__
25 #import <Foundation/NSObject.h>
27 @class NSString, NSEnumerator, NSArray;
30 New in SAX2, defined in helpers/NamespaceSupport
32 Encapsulate Namespace logic for use by SAX drivers.
34 This class encapsulates the logic of Namespace processing: it tracks
35 the declarations currently in force for each context and automatically
36 processing raw XML 1.0 names into their Namespace parts.
38 Namespace support objects are reusable, but the reset method must be
39 invoked between each session.
41 Here is a simple session:
43 String parts[] = new String[3];
44 SaxNamespaceSupport support;
46 support = [[SaxNamespaceSupport alloc] init];
48 [support pushContext];
49 [support declarePrefix:@"" uri:@"http://www.w3.org/1999/xhtml"];
50 [support declarePrefix:@"dc" uri:@"http://www.purl.org/dc#"];
52 String parts[] = support.processName("p", parts, false);
53 System.out.println("Namespace URI: " + parts[0]);
54 System.out.println("Local name: " + parts[1]);
55 System.out.println("Raw name: " + parts[2]);
57 String parts[] = support.processName("dc:title", parts, false);
58 System.out.println("Namespace URI: " + parts[0]);
59 System.out.println("Local name: " + parts[1]);
60 System.out.println("Raw name: " + parts[2]);
64 Note that this class is optimized for the use case where most elements
65 do not contain Namespace declarations: if the same prefix/URI mapping
66 is repeated for each context (for example), this class will be somewhat
70 extern NSString *SaxXMLNS;
72 @interface SaxNamespaceSupport : NSObject
77 /* start a new ns context */
80 /* revert to previous ns context */
83 /* Declare a Namespace prefix. */
84 - (BOOL)declarePrefix:(NSString *)_prefix uri:(NSString *)_uri;
86 /* Return an enumeration of all prefixes declared in this context. */
87 - (NSEnumerator *)prefixEnumerator;
89 /* Look up a prefix and get the currently-mapped Namespace URI. */
90 - (NSString *)getUriForPrefix:(NSString *)_prefix;
92 /* Reset this Namespace support object for reuse. */
96 Process a raw XML 1.0 name.
98 This method processes a raw XML 1.0 name in the current context by
99 removing the prefix and looking it up among the prefixes currently
100 declared. The return value will be the array supplied by the caller,
101 filled in as follows:
103 parts[0] The Namespace URI, or an empty string if none is in use.
104 parts[1] The local name (without prefix).
105 parts[2] The original raw name.
107 All of the strings in the array will be internalized. If the raw name
108 has a prefix that has not been declared, then the return value will be
111 Note that attribute names are processed differently than element names:
112 an unprefixed element name will received the default Namespace (if any),
113 while an unprefixed element name will not.
115 - (NSArray *)processName:(NSString *)_rawName
116 parts:(NSArray *)_parts
117 isAttribute:(BOOL)_isAttribute;
121 #endif /* __SaxNamespaceSupport_H__ */