2 * Copyright 2001-2007 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 * Representing XML namespace attributes
23 #if !defined(__xmltooling_namespace_h__)
24 #define __xmltooling_namespace_h__
26 #include <xmltooling/unicode.h>
28 namespace xmltooling {
31 * A data structure for encapsulating XML Namespace attributes
33 class XMLTOOL_API Namespace
38 * @param uri namespace URI
39 * @param prefix namespace prefix (without the colon)
40 * @param alwaysDeclare true iff the namespace should always be declared regardless of in-scope declarations
42 Namespace(const XMLCh* uri=NULL, const XMLCh* prefix=NULL, bool alwaysDeclare=false);
47 * Deep copy constructor
49 Namespace(const Namespace& src);
52 * Deep assignment operator
54 Namespace& operator=(const Namespace& src);
59 * Returns the namespace prefix
60 * @return Null-terminated Unicode string containing the prefix, without the colon
62 const XMLCh* getNamespacePrefix() const { return m_prefix.c_str(); }
65 * Returns the namespace URI
66 * @return Null-terminated Unicode string containing the URI
68 const XMLCh* getNamespaceURI() const { return m_uri.c_str(); }
71 * Returns the namespace prefix
72 * @return Null-terminated Unicode string containing the prefix, without the colon
74 const XMLCh* getNamespacePrefix() const { return m_prefix; }
77 * Returns the namespace URI
78 * @return Null-terminated Unicode string containing the URI
80 const XMLCh* getNamespaceURI() const { return m_uri; }
84 * Returns true iff the namespace should always be declared regardless of in-scope declarations
85 * @return the alwaysDeclared setting
87 const bool alwaysDeclare() const { return m_pinned; }
90 * Sets the namespace prefix
91 * @param prefix Null-terminated Unicode string containing the prefix, without the colon
93 void setNamespacePrefix(const XMLCh* prefix);
96 * Sets the namespace URI
97 * @param uri Null-terminated Unicode string containing the URI
99 void setNamespaceURI(const XMLCh* uri);
102 * Sets the alwaysDeclared property
103 * @param alwaysDeclare true iff the namespace should always be declared regardless of in-scope declarations
105 void setAlwaysDeclare(bool alwaysDeclare) { m_pinned = alwaysDeclare; }
119 * Returns true iff op1's namespace lexically compares less than op2's namespace,
120 * or if equal, iff op1's prefix lexically compares less than op2's prefix.
122 * Needed for use with sorted STL containers.
124 * @param op1 First namspace to compare
125 * @param op2 Second namespace to compare
127 extern XMLTOOL_API bool operator<(const Namespace& op1, const Namespace& op2);
129 #ifndef HAVE_GOOD_STL
131 * Returns true iff op1's namespace and prefix are equal to op2's namespace and prefix.
132 * @param op1 First namspace to compare
133 * @param op2 Second namespace to compare
135 extern XMLTOOL_API bool operator==(const Namespace& op1, const Namespace& op2);
140 #endif /* __xmltooling_namespace_h__ */