2 * Copyright 2001-2009 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 QNames
26 using namespace xmltooling;
29 using xercesc::XMLString;
31 QName::QName(const XMLCh* uri, const XMLCh* localPart, const XMLCh* prefix)
34 setLocalPart(localPart);
38 QName::QName(const char* uri, const char* localPart, const char* prefix)
41 setLocalPart(localPart);
49 void QName::setPrefix(const XMLCh* prefix)
57 void QName::setNamespaceURI(const XMLCh* uri)
65 void QName::setLocalPart(const XMLCh* localPart)
73 void QName::setPrefix(const char* prefix)
76 auto_ptr_XMLCh temp(prefix);
83 void QName::setNamespaceURI(const char* uri)
86 auto_ptr_XMLCh temp(uri);
93 void QName::setLocalPart(const char* localPart)
96 auto_ptr_XMLCh temp(localPart);
103 bool xmltooling::operator==(const QName& op1, const QName& op2)
107 return (!XMLString::compareString(op1.getNamespaceURI(),op2.getNamespaceURI()) &&
108 !XMLString::compareString(op1.getLocalPart(),op2.getLocalPart()));
111 bool xmltooling::operator!=(const QName& op1, const QName& op2)
116 bool xmltooling::operator<(const QName& op1, const QName& op2)
118 int i=XMLString::compareString(op1.getNamespaceURI(),op2.getNamespaceURI());
122 return (XMLString::compareString(op1.getLocalPart(),op2.getLocalPart())<0);
127 string QName::toString() const
131 auto_ptr_char local(getLocalPart());
133 auto_ptr_char pre(getPrefix());
134 return string(pre.get()) + ':' + local.get();
136 else if (hasNamespaceURI()) {
137 auto_ptr_char ns(getNamespaceURI());
138 return string("{") + ns.get() + '}' + local.get();