xmlattr.cpp
来自「IBM的解析xml的工具Xerces的源代码」· C++ 代码 · 共 172 行
CPP
172 行
/* * Copyright 1999-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *//** * $Id: XMLAttr.cpp,v 1.8 2004/09/08 13:55:58 peiyongz Exp $ */// ---------------------------------------------------------------------------// Includes// ---------------------------------------------------------------------------#include <xercesc/framework/XMLAttr.hpp>#include <xercesc/framework/MemoryManager.hpp>#include <xercesc/util/OutOfMemoryException.hpp>XERCES_CPP_NAMESPACE_BEGIN// ---------------------------------------------------------------------------// XMLAttr: Constructors and Destructor// ---------------------------------------------------------------------------XMLAttr::XMLAttr(MemoryManager* const manager) : fSpecified(false) , fType(XMLAttDef::CData) , fValueBufSz(0) , fValue(0) , fAttName(0) , fMemoryManager(manager) , fDatatypeValidator(0) , fIsSchemaValidated(false){ fAttName = new (fMemoryManager) QName(fMemoryManager);}XMLAttr::XMLAttr( const unsigned int uriId , const XMLCh* const attrName , const XMLCh* const attrPrefix , const XMLCh* const attrValue , const XMLAttDef::AttTypes type , const bool specified , MemoryManager* const manager , DatatypeValidator * datatypeValidator , const bool isSchema ): fSpecified(specified) , fType(type) , fValueBufSz(0) , fValue(0) , fAttName(0) , fMemoryManager(manager) , fDatatypeValidator(datatypeValidator) , fIsSchemaValidated(isSchema){ try { // // Just call the local setters to set up everything. Too much // work is required to replicate that functionality here. // fAttName = new (fMemoryManager) QName(attrPrefix, attrName, uriId, fMemoryManager); setValue(attrValue); } catch(const OutOfMemoryException&) { throw; } catch(...) { cleanUp(); }}XMLAttr::XMLAttr( const unsigned int uriId , const XMLCh* const rawName , const XMLCh* const attrValue , const XMLAttDef::AttTypes type , const bool specified , MemoryManager* const manager , DatatypeValidator * datatypeValidator , const bool isSchema ): fSpecified(specified) , fType(type) , fValueBufSz(0) , fValue(0) , fAttName(0) , fMemoryManager(manager) , fDatatypeValidator(datatypeValidator) , fIsSchemaValidated(isSchema){ try { // Just call the local setters to set up everything. Too much // work is required to replicate that functionality here. fAttName = new (fMemoryManager) QName(rawName, uriId, fMemoryManager); setValue(attrValue); } catch(const OutOfMemoryException&) { throw; } catch(...) { cleanUp(); }}// ---------------------------------------------------------------------------// XMLAttr: Getter methods// ---------------------------------------------------------------------------const XMLCh* XMLAttr::getQName() const{ return fAttName->getRawName();}// ---------------------------------------------------------------------------// XMLAttr: Setter methods// ---------------------------------------------------------------------------void XMLAttr::setName( const unsigned int uriId , const XMLCh* const attrName , const XMLCh* const attrPrefix){ fAttName->setName(attrPrefix, attrName, uriId);}void XMLAttr::setURIId(const unsigned int uriId){ fAttName->setURI(uriId);}void XMLAttr::setValue(const XMLCh* const newValue){ const unsigned int newLen = XMLString::stringLen(newValue); if (!fValueBufSz || (newLen > fValueBufSz)) { fMemoryManager->deallocate(fValue); //delete [] fValue; fValueBufSz = newLen + 8; fValue = (XMLCh*) fMemoryManager->allocate((fValueBufSz+1) * sizeof(XMLCh)); //new XMLCh[fValueBufSz + 1]; } XMLString::moveChars(fValue, newValue, newLen + 1);}// ---------------------------------------------------------------------------// XMLAttr: Private, helper methods// ---------------------------------------------------------------------------void XMLAttr::cleanUp(){ delete fAttName; fMemoryManager->deallocate(fValue); //delete [] fValue;}XERCES_CPP_NAMESPACE_END
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?