2 * Copyright 2001-2010 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.
18 * @file xmltooling/QName.h
20 * Representing XML QNames
23 #ifndef __xmltooling_qname_h__
24 #define __xmltooling_qname_h__
26 #include <xmltooling/unicode.h>
29 namespace xmltooling {
31 #if defined (_MSC_VER)
32 #pragma warning( push )
33 #pragma warning( disable : 4251 )
37 * A data structure for encapsulating XML QNames.
38 * The Xerces class is too limited to use at the moment.
40 class XMLTOOL_API QName
46 * @param uri namespace URI
47 * @param localPart local name
48 * @param prefix namespace prefix (without the colon)
50 QName(const XMLCh* uri=nullptr, const XMLCh* localPart=nullptr, const XMLCh* prefix=nullptr);
55 * @param uri namespace URI
56 * @param localPart local name
57 * @param prefix namespace prefix (without the colon)
59 QName(const char* uri, const char* localPart, const char* prefix=nullptr);
64 * Indicates whether the QName has a prefix.
65 * @return true iff the prefix is non-empty
67 bool hasPrefix() const { return !m_prefix.empty(); }
70 * Indicates whether the QName has a non-empty namespace.
71 * @return true iff the namespace is non-empty
73 bool hasNamespaceURI() const { return !m_uri.empty(); }
76 * Indicates whether the QName has a non-empty local name.
77 * @return true iff the local name is non-empty
79 bool hasLocalPart() const { return !m_local.empty(); }
82 * Returns the namespace prefix
83 * @return Null-terminated Unicode string containing the prefix, without the colon
85 const XMLCh* getPrefix() const { return m_prefix.c_str(); }
88 * Returns the namespace URI
89 * @return Null-terminated Unicode string containing the URI
91 const XMLCh* getNamespaceURI() const { return m_uri.c_str(); }
94 * Returns the local part of the name
95 * @return Null-terminated Unicode string containing the local name
97 const XMLCh* getLocalPart() const { return m_local.c_str(); }
100 * Sets the namespace prefix
101 * @param prefix Null-terminated Unicode string containing the prefix, without the colon
103 void setPrefix(const XMLCh* prefix);
106 * Sets the namespace URI
107 * @param uri Null-terminated Unicode string containing the URI
109 void setNamespaceURI(const XMLCh* uri);
112 * Sets the local part of the name
113 * @param localPart Null-terminated Unicode string containing the local name
115 void setLocalPart(const XMLCh* localPart);
118 * Sets the namespace prefix
119 * @param prefix Null-terminated ASCII string containing the prefix, without the colon
121 void setPrefix(const char* prefix);
124 * Sets the namespace URI
125 * @param uri Null-terminated ASCII string containing the URI
127 void setNamespaceURI(const char* uri);
130 * Sets the local part of the name
131 * @param localPart Null-terminated ASCII string containing the local name
133 void setLocalPart(const char* localPart);
136 * Gets a string representation of the QName for logging, etc.
137 * Format is prefix:localPart or {namespaceURI}localPart if no prefix.
139 * @return the string representation
141 std::string toString() const;
149 #if defined (_MSC_VER)
150 #pragma warning( pop )
154 * Returns true iff op1's namespace lexically compares less than op2's namespace,
155 * or if equal, iff op1's prefix lexically compares less than op2's prefix.
157 * Needed for use with sorted STL containers.
159 * @param op1 First qname to compare
160 * @param op2 Second qname to compare
162 extern XMLTOOL_API bool operator<(const QName& op1, const QName& op2);
165 * Returns true iff op1's components are equal to op2's components, excluding prefix.
166 * @param op1 First qname to compare
167 * @param op2 Second qname to compare
169 extern XMLTOOL_API bool operator==(const QName& op1, const QName& op2);
172 * Returns true iff op1's components are not equal to op2's components, excluding prefix.
173 * @param op1 First qname to compare
174 * @param op2 Second qname to compare
176 extern XMLTOOL_API bool operator!=(const QName& op1, const QName& op2);
180 #endif /* __xmltooling_qname_h__ */