2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
22 * @file xmltooling/QName.h
24 * Representing XML QNames
27 #ifndef __xmltooling_qname_h__
28 #define __xmltooling_qname_h__
30 #include <xmltooling/unicode.h>
33 namespace xmltooling {
35 #if defined (_MSC_VER)
36 #pragma warning( push )
37 #pragma warning( disable : 4251 )
41 * A data structure for encapsulating XML QNames.
42 * The Xerces class is too limited to use at the moment.
44 class XMLTOOL_API QName
50 * @param uri namespace URI
51 * @param localPart local name
52 * @param prefix namespace prefix (without the colon)
54 QName(const XMLCh* uri=nullptr, const XMLCh* localPart=nullptr, const XMLCh* prefix=nullptr);
59 * @param uri namespace URI
60 * @param localPart local name
61 * @param prefix namespace prefix (without the colon)
63 QName(const char* uri, const char* localPart, const char* prefix=nullptr);
68 * Indicates whether the QName has a prefix.
69 * @return true iff the prefix is non-empty
71 bool hasPrefix() const { return !m_prefix.empty(); }
74 * Indicates whether the QName has a non-empty namespace.
75 * @return true iff the namespace is non-empty
77 bool hasNamespaceURI() const { return !m_uri.empty(); }
80 * Indicates whether the QName has a non-empty local name.
81 * @return true iff the local name is non-empty
83 bool hasLocalPart() const { return !m_local.empty(); }
86 * Returns the namespace prefix
87 * @return Null-terminated Unicode string containing the prefix, without the colon
89 const XMLCh* getPrefix() const { return m_prefix.c_str(); }
92 * Returns the namespace URI
93 * @return Null-terminated Unicode string containing the URI
95 const XMLCh* getNamespaceURI() const { return m_uri.c_str(); }
98 * Returns the local part of the name
99 * @return Null-terminated Unicode string containing the local name
101 const XMLCh* getLocalPart() const { return m_local.c_str(); }
104 * Sets the namespace prefix
105 * @param prefix Null-terminated Unicode string containing the prefix, without the colon
107 void setPrefix(const XMLCh* prefix);
110 * Sets the namespace URI
111 * @param uri Null-terminated Unicode string containing the URI
113 void setNamespaceURI(const XMLCh* uri);
116 * Sets the local part of the name
117 * @param localPart Null-terminated Unicode string containing the local name
119 void setLocalPart(const XMLCh* localPart);
122 * Sets the namespace prefix
123 * @param prefix Null-terminated ASCII string containing the prefix, without the colon
125 void setPrefix(const char* prefix);
128 * Sets the namespace URI
129 * @param uri Null-terminated ASCII string containing the URI
131 void setNamespaceURI(const char* uri);
134 * Sets the local part of the name
135 * @param localPart Null-terminated ASCII string containing the local name
137 void setLocalPart(const char* localPart);
140 * Gets a string representation of the QName for logging, etc.
141 * Format is prefix:localPart or {namespaceURI}localPart if no prefix.
143 * @return the string representation
145 std::string toString() const;
153 #if defined (_MSC_VER)
154 #pragma warning( pop )
158 * Returns true iff op1's namespace lexically compares less than op2's namespace,
159 * or if equal, iff op1's prefix lexically compares less than op2's prefix.
161 * Needed for use with sorted STL containers.
163 * @param op1 First qname to compare
164 * @param op2 Second qname to compare
166 extern XMLTOOL_API bool operator<(const QName& op1, const QName& op2);
169 * Returns true iff op1's components are equal to op2's components, excluding prefix.
170 * @param op1 First qname to compare
171 * @param op2 Second qname to compare
173 extern XMLTOOL_API bool operator==(const QName& op1, const QName& op2);
176 * Returns true iff op1's components are not equal to op2's components, excluding prefix.
177 * @param op1 First qname to compare
178 * @param op2 Second qname to compare
180 extern XMLTOOL_API bool operator!=(const QName& op1, const QName& op2);
184 #endif /* __xmltooling_qname_h__ */