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 QNames
26 using namespace xmltooling;
29 using xercesc::XMLString;
31 QName::QName(const XMLCh* uri, const XMLCh* localPart, const XMLCh* prefix)
34 m_uri=m_prefix=m_local=NULL;
37 setLocalPart(localPart);
41 QName::QName(const char* uri, const char* localPart, const char* prefix)
44 m_uri=m_prefix=m_local=NULL;
47 setLocalPart(localPart);
54 XMLString::release(&m_uri);
55 XMLString::release(&m_prefix);
56 XMLString::release(&m_local);
60 void QName::setPrefix(const XMLCh* prefix)
69 XMLString::release(&m_prefix);
70 m_prefix=XMLString::replicate(prefix);
74 void QName::setNamespaceURI(const XMLCh* uri)
83 XMLString::release(&m_uri);
84 m_uri=XMLString::replicate(uri);
88 void QName::setLocalPart(const XMLCh* localPart)
97 XMLString::release(&m_local);
98 m_local=XMLString::replicate(localPart);
102 void QName::setPrefix(const char* prefix)
106 auto_ptr_XMLCh temp(prefix);
113 XMLString::release(&m_prefix);
114 m_prefix=XMLString::transcode(prefix);
118 void QName::setNamespaceURI(const char* uri)
122 auto_ptr_XMLCh temp(uri);
129 XMLString::release(&m_uri);
130 m_uri=XMLString::transcode(uri);
134 void QName::setLocalPart(const char* localPart)
138 auto_ptr_XMLCh temp(localPart);
145 XMLString::release(&m_local);
146 m_local=XMLString::transcode(localPart);
150 #ifndef HAVE_GOOD_STL
151 QName::QName(const QName& src)
153 m_uri=XMLString::replicate(src.getNamespaceURI());
154 m_prefix=XMLString::replicate(src.getPrefix());
155 m_local=XMLString::replicate(src.getLocalPart());
158 QName& QName::operator=(const QName& src)
160 m_uri=XMLString::replicate(src.getNamespaceURI());
161 m_prefix=XMLString::replicate(src.getPrefix());
162 m_local=XMLString::replicate(src.getLocalPart());
167 bool xmltooling::operator==(const QName& op1, const QName& op2)
171 return (!XMLString::compareString(op1.getNamespaceURI(),op2.getNamespaceURI()) &&
172 !XMLString::compareString(op1.getLocalPart(),op2.getLocalPart()));
175 bool xmltooling::operator!=(const QName& op1, const QName& op2)
180 bool xmltooling::operator<(const QName& op1, const QName& op2)
182 int i=XMLString::compareString(op1.getNamespaceURI(),op2.getNamespaceURI());
186 return (XMLString::compareString(op1.getLocalPart(),op2.getLocalPart())<0);
191 string QName::toString() const
195 auto_ptr_char local(getLocalPart());
197 auto_ptr_char pre(getPrefix());
198 return string(pre.get()) + ':' + local.get();
200 else if (hasNamespaceURI()) {
201 auto_ptr_char ns(getNamespaceURI());
202 return string("{") + ns.get() + '}' + local.get();