📄 ixmldomnodeimpl.inl
字号:
/* * Copyright 1999-2000,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: IXMLDOMNodeImpl.inl,v 1.7 2004/09/08 13:55:35 peiyongz Exp $ */#include <xercesc/dom/DOMNode.hpp>#include <xercesc/dom/DOMDocument.hpp>#include <xercesc/dom/DOMText.hpp>#include "XMLDOMNodeList.h"#include "XMLDOMNamedNodeMap.h"#include "XMLDOMUtil.h"#include <xercesc/dom/DOMException.hpp>XERCES_CPP_NAMESPACE_USEtemplate <class T, const IID* piid, class tihclass>HRESULT STDMETHODCALLTYPE IXMLDOMNodeImpl<T,piid,tihclass>::InterfaceSupportsErrorInfo(REFIID riid){ if(riid == *piid) return S_OK; return S_FALSE;}template <class T, const IID* piid, class tihclass>STDMETHODIMPIXMLDOMNodeImpl<T,piid,tihclass>::get_nodeName(BSTR *pVal){ ATLTRACE(_T("IXMLDOMNodeImpl::get_nodeName\n")); if (NULL == pVal) return E_POINTER; *pVal = NULL; try { *pVal = SysAllocString(get_DOMNode()->getNodeName()); } catch(DOMException& ex) { return MakeHRESULT(ex); } catch(...) { return E_FAIL; } return S_OK;}template <class T, const IID* piid, class tihclass>STDMETHODIMPIXMLDOMNodeImpl<T,piid,tihclass>::get_nodeValue(VARIANT *pVal){ ATLTRACE(_T("IXMLDOMNodeImpl::get_nodeValue\n")); if (NULL == pVal) return E_POINTER; ::VariantInit(pVal); try { const XMLCh* val=get_DOMNode()->getNodeValue(); if (val != 0) { V_VT(pVal) = VT_BSTR; V_BSTR(pVal) = SysAllocString(val); } else V_VT(pVal) = VT_NULL; } catch(DOMException& ex) { return MakeHRESULT(ex); } catch(...) { return E_FAIL; } return S_OK;}template <class T, const IID* piid, class tihclass>STDMETHODIMPIXMLDOMNodeImpl<T,piid,tihclass>::put_nodeValue(VARIANT newVal){ ATLTRACE(_T("IXMLDOMNodeImpl::put_nodeValue\n")); try { if(V_VT(&newVal) == VT_BSTR) { get_DOMNode()->setNodeValue(V_BSTR(&newVal)); } // // coerce to BSTR or throw error // else { get_DOMNode()->setNodeValue((BSTR) (_bstr_t) newVal); } } catch(DOMException& ex) { return MakeHRESULT(ex); } catch(...) { return E_FAIL; } return S_OK;}template <class T, const IID* piid, class tihclass>STDMETHODIMPIXMLDOMNodeImpl<T,piid,tihclass>::get_nodeType(DOMNodeType *pVal){ ATLTRACE(_T("IXMLDOMNodeImpl::get_nodeType\n")); if (NULL == pVal) return E_POINTER; *pVal = get_DOMNodeType(); return S_OK;}template <class T, const IID* piid, class tihclass>STDMETHODIMPIXMLDOMNodeImpl<T,piid,tihclass>::get_parentNode(IXMLDOMNode **pVal){ ATLTRACE(_T("IXMLDOMNodeImpl::get_parentNode\n")); if (NULL == pVal) return E_POINTER; *pVal = NULL; HRESULT hr = S_OK; try { DOMNode* n = get_DOMNode()->getParentNode(); if(n!=NULL) { hr = wrapNode(m_pIXMLDOMDocument, n,IID_IXMLDOMNode,reinterpret_cast<LPVOID *> (pVal)); } } catch(DOMException& ex) { return MakeHRESULT(ex); } catch(...) { return E_FAIL; } return hr;}template <class T, const IID* piid, class tihclass>STDMETHODIMPIXMLDOMNodeImpl<T,piid,tihclass>::get_childNodes(IXMLDOMNodeList * *pVal){ ATLTRACE(_T("IXMLDOMNodeImpl::get_childNodes\n")); if (NULL == pVal) return E_POINTER; *pVal = NULL; CXMLDOMNodeListObj *pObj = NULL; HRESULT hr = CXMLDOMNodeListObj::CreateInstance(&pObj); if (S_OK != hr) return hr; pObj->AddRef(); pObj->SetOwnerDoc(m_pIXMLDOMDocument); try { pObj->m_container = get_DOMNode()->getChildNodes(); } catch(DOMException& ex) { pObj->Release(); return MakeHRESULT(ex); } catch(...) { pObj->Release(); return E_FAIL; } hr = pObj->QueryInterface(IID_IXMLDOMNodeList, reinterpret_cast<LPVOID*> (pVal)); if (S_OK != hr) *pVal = NULL; pObj->Release(); return hr;}template <class T, const IID* piid, class tihclass>STDMETHODIMPIXMLDOMNodeImpl<T,piid,tihclass>::get_firstChild(IXMLDOMNode **pVal){ ATLTRACE(_T("IXMLDOMNodeImpl::get_firstChild\n")); if (NULL == pVal) return E_POINTER; *pVal = NULL; HRESULT hr = S_OK; try { DOMNode* n = get_DOMNode()->getFirstChild(); // // returns Nothing if no children // if(n!=NULL) hr = wrapNode(m_pIXMLDOMDocument,n,IID_IXMLDOMNode, reinterpret_cast<LPVOID *> (pVal)); } catch(DOMException& ex) { return MakeHRESULT(ex); } catch(...) { return E_FAIL; } return hr;}template <class T, const IID* piid, class tihclass>STDMETHODIMPIXMLDOMNodeImpl<T,piid,tihclass>::get_lastChild(IXMLDOMNode **pVal){ ATLTRACE(_T("IXMLDOMNodeImpl::get_lastChild\n")); if (NULL == pVal) return E_POINTER; *pVal = NULL; HRESULT hr = S_OK; try { DOMNode* n = get_DOMNode()->getLastChild(); if(n!=NULL) hr = wrapNode(m_pIXMLDOMDocument,n,IID_IXMLDOMNode, reinterpret_cast<LPVOID *> (pVal)); } catch(DOMException& ex) { return MakeHRESULT(ex); } catch(...) { return E_FAIL; } return hr;}template <class T, const IID* piid, class tihclass>STDMETHODIMPIXMLDOMNodeImpl<T,piid,tihclass>::get_previousSibling(IXMLDOMNode * *pVal){ ATLTRACE(_T("IXMLDOMNodeImpl::get_previousSibling\n")); if (NULL == pVal) return E_POINTER; *pVal = NULL; HRESULT hr = S_OK; try { DOMNode* n = get_DOMNode()->getPreviousSibling(); if(n!=NULL) hr = wrapNode(m_pIXMLDOMDocument,n,IID_IXMLDOMNode, reinterpret_cast<LPVOID *> (pVal)); } catch(DOMException& ex) { return MakeHRESULT(ex); } catch(...) { return E_FAIL; } return hr;}template <class T, const IID* piid, class tihclass>STDMETHODIMPIXMLDOMNodeImpl<T,piid,tihclass>::get_nextSibling(IXMLDOMNode * *pVal){ ATLTRACE(_T("IXMLDOMNodeImpl::get_nextSibling\n")); if (NULL == pVal) return E_POINTER; *pVal = NULL; HRESULT hr = S_OK; try { DOMNode* n = get_DOMNode()->getNextSibling(); if(n!=NULL) hr = wrapNode(m_pIXMLDOMDocument,n,IID_IXMLDOMNode, reinterpret_cast<LPVOID *> (pVal)); } catch(DOMException& ex) { return MakeHRESULT(ex); } catch(...) { return E_FAIL; } return hr;}template <class T, const IID* piid, class tihclass>STDMETHODIMPIXMLDOMNodeImpl<T,piid,tihclass>::get_attributes(IXMLDOMNamedNodeMap * *pVal){ ATLTRACE(_T("IXMLDOMNodeImpl::get_attributes\n")); if (NULL == pVal) return E_POINTER; *pVal = NULL; DOMNamedNodeMap* map=NULL; try { map = get_DOMNode()->getAttributes(); } catch(DOMException& ex) { return MakeHRESULT(ex); } catch(...) { return E_FAIL; } if ((map == 0) || (NODE_ELEMENT != get_DOMNodeType())) //&& //NODE_ENTITY != get_DOMNodeType() && //NODE_NOTATION != get_DOMNodeType()) return S_OK; CXMLDOMNamedNodeMapObj *pObj = NULL; HRESULT hr = CXMLDOMNamedNodeMapObj::CreateInstance(&pObj); if (S_OK != hr) return hr; pObj->AddRef(); pObj->SetOwnerDoc(m_pIXMLDOMDocument); pObj->m_container = map; hr = pObj->QueryInterface(IID_IXMLDOMNamedNodeMap, reinterpret_cast<LPVOID*> (pVal)); if (S_OK != hr) *pVal = NULL; pObj->Release(); return hr;}template <class T, const IID* piid, class tihclass>STDMETHODIMPIXMLDOMNodeImpl<T,piid,tihclass>::insertBefore(IXMLDOMNode *newChild, VARIANT refChild, IXMLDOMNode **outNewChild){ ATLTRACE(_T("IXMLDOMNodeImpl::insertBefore\n")); if (NULL == outNewChild) return E_POINTER; *outNewChild = NULL; if (NULL == newChild) return E_INVALIDARG; if (V_VT(&refChild) != VT_DISPATCH && V_VT(&refChild) != VT_NULL) return E_INVALIDARG; if (V_VT(&refChild) == VT_NULL) return appendChild(newChild,outNewChild); CComQIPtr<IIBMXMLDOMNodeIdentity,&IID_IIBMXMLDOMNodeIdentity> pNewChild(newChild); if (!pNewChild) return E_NOINTERFACE; long id = 0; HRESULT hr = pNewChild->get_NodeId(&id); if (S_OK != hr) return hr; DOMNode *pNewChildNode = reinterpret_cast<DOMNode*> (id); if (NULL == pNewChildNode) return E_INVALIDARG; CComQIPtr<IIBMXMLDOMNodeIdentity,&IID_IIBMXMLDOMNodeIdentity> pRefChild(V_DISPATCH(&refChild)); if (!pRefChild) return E_NOINTERFACE; id = 0; hr = pRefChild->get_NodeId(&id); if (S_OK != hr) return hr; DOMNode *pRefChildNode = reinterpret_cast<DOMNode*> (id); if (NULL == pRefChildNode) return E_INVALIDARG; try { DOMNode* n = get_DOMNode()->insertBefore(pNewChildNode, pRefChildNode); hr = wrapNode(m_pIXMLDOMDocument,n,IID_IXMLDOMNode, reinterpret_cast<LPVOID *> (outNewChild)); } catch(DOMException& ex) { return MakeHRESULT(ex); } catch(...) { return E_FAIL; } return hr;}template <class T, const IID* piid, class tihclass>STDMETHODIMPIXMLDOMNodeImpl<T,piid,tihclass>::replaceChild(IXMLDOMNode *newChild, IXMLDOMNode *oldChild, IXMLDOMNode * *outNewChild){ ATLTRACE(_T("IXMLDOMNodeImpl::replaceChild\n")); if (NULL == outNewChild) return E_POINTER; *outNewChild = NULL; if (NULL == oldChild) return E_INVALIDARG; if (NULL == newChild) return removeChild(oldChild,outNewChild); CComQIPtr<IIBMXMLDOMNodeIdentity,&IID_IIBMXMLDOMNodeIdentity> pNewChild(newChild); if (!pNewChild) return E_NOINTERFACE; long id = 0; HRESULT hr = pNewChild->get_NodeId(&id); if (S_OK != hr) return hr; DOMNode *pNewChildNode = reinterpret_cast<DOMNode*> (id);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -