STDMETHODIMP CXMLDOMDocument::get_doctype(IXMLDOMDocumentType **pVal) { ATLTRACE(_T("CXMLDOMDocument::get_doctype\n")); if (NULL == pVal) return E_POINTER; *pVal = NULL; DOMDocumentType* doctype = m_Document->getDoctype(); // // if the document had no doctype then return a null object // if(doctype==NULL) return S_OK; CXMLDOMDocumentTypeObj *pObj = NULL; HRESULT hr = CXMLDOMDocumentTypeObj::CreateInstance(&pObj); if (S_OK != hr) return hr; pObj->AddRef(); pObj->SetOwnerDoc(this); try { pObj->documentType = doctype; } catch(...) { pObj->Release(); return E_FAIL; } hr = pObj->QueryInterface(IID_IXMLDOMDocumentType, reinterpret_cast<LPVOID*> (pVal)); if (S_OK != hr) *pVal = NULL; pObj->Release(); return hr; }
HRESULT wrapNode(IXMLDOMDocument *pDoc, DOMNode* node, REFIID iid, LPVOID *pVal) { HRESULT hr = S_OK; if (NULL == pVal) return E_POINTER; *pVal = NULL; short type = node->getNodeType(); // the way we are constructing the wrappers is kind of fishy but oh well... // the various IBM DOM wrapper classes don't ever add any members or have // any v-tables so what we are doing should be safe. There isn't any other // way as far as I can tell to do this.... switch(type) { case DOMNode::ELEMENT_NODE: { CXMLDOMElement *pObj = NULL; hr = CPooledXMLDOMElementObj::CreateInstance(&pObj); if (S_OK != hr) return hr; pObj->AddRef(); pObj->SetOwnerDoc(pDoc); try { pObj->element = static_cast<DOMElement*> (node); } catch(DOMException& ex) { pObj->Release(); return MakeHRESULT(ex); } catch(...) { pObj->Release(); return E_FAIL; } hr = pObj->QueryInterface(iid, pVal); if (S_OK != hr) *pVal = NULL; pObj->Release(); break; } case DOMNode::ATTRIBUTE_NODE: { CXMLDOMAttribute *pObj = NULL; hr = CPooledXMLDOMAttributeObj::CreateInstance(&pObj); if (S_OK != hr) return hr; pObj->AddRef(); pObj->SetOwnerDoc(pDoc); try { pObj->attr = static_cast<DOMAttr*> (node); } catch(DOMException& ex) { pObj->Release(); return MakeHRESULT(ex); } catch(...) { pObj->Release(); return E_FAIL; } hr = pObj->QueryInterface(iid, pVal); if (S_OK != hr) *pVal = NULL; pObj->Release(); break; } case DOMNode::TEXT_NODE: { CXMLDOMText *pObj = NULL; hr = CPooledXMLDOMTextObj::CreateInstance(&pObj); if (S_OK != hr) return hr; pObj->AddRef(); pObj->SetOwnerDoc(pDoc); try { pObj->text = static_cast<DOMText*> (node); } catch(DOMException& ex) { pObj->Release(); return MakeHRESULT(ex); } catch(...) { pObj->Release(); return E_FAIL; } hr = pObj->QueryInterface(iid, pVal); if (S_OK != hr) *pVal = NULL; pObj->Release(); break; } case DOMNode::CDATA_SECTION_NODE: { CXMLDOMCDATASection *pObj = NULL; hr = CPooledXMLDOMCDATASectionObj::CreateInstance(&pObj); if (S_OK != hr) return hr; pObj->AddRef(); pObj->SetOwnerDoc(pDoc); try { pObj->cdataSection = static_cast<DOMCDATASection*> (node); } catch(DOMException& ex) { pObj->Release(); return MakeHRESULT(ex); } catch(...) { pObj->Release(); return E_FAIL; } hr = pObj->QueryInterface(iid, pVal); if (S_OK != hr) *pVal = NULL; pObj->Release(); break; } case DOMNode::ENTITY_REFERENCE_NODE: { CXMLDOMEntityReference *pObj = NULL; hr = CPooledXMLDOMEntityReferenceObj::CreateInstance(&pObj); if (S_OK != hr) return hr; pObj->AddRef(); pObj->SetOwnerDoc(pDoc); try { pObj->entityReference = static_cast<DOMEntityReference*> (node); } catch(DOMException& ex) { pObj->Release(); return MakeHRESULT(ex); } catch(...) { pObj->Release(); return E_FAIL; } hr = pObj->QueryInterface(iid, pVal); if (S_OK != hr) *pVal = NULL; pObj->Release(); break; } case DOMNode::ENTITY_NODE: { CXMLDOMEntity *pObj = NULL; hr = CPooledXMLDOMEntityObj::CreateInstance(&pObj); if (S_OK != hr) return hr; pObj->AddRef(); pObj->SetOwnerDoc(pDoc); try { pObj->entity = static_cast<DOMEntity*> (node); } catch(DOMException& ex) { pObj->Release(); return MakeHRESULT(ex); } catch(...) { pObj->Release(); return E_FAIL; } hr = pObj->QueryInterface(iid, pVal); if (S_OK != hr) *pVal = NULL; pObj->Release(); break; } case DOMNode::PROCESSING_INSTRUCTION_NODE: { CXMLDOMProcessingInstruction *pObj = NULL; hr = CPooledXMLDOMProcessingInstructionObj::CreateInstance(&pObj); if (S_OK != hr) return hr; pObj->AddRef(); pObj->SetOwnerDoc(pDoc); try { pObj->processingInstruction = static_cast<DOMProcessingInstruction*> (node); } catch(DOMException& ex) { pObj->Release(); return MakeHRESULT(ex); } catch(...) { pObj->Release(); return E_FAIL; } hr = pObj->QueryInterface(iid, pVal); if (S_OK != hr) *pVal = NULL; pObj->Release(); break; } case DOMNode::COMMENT_NODE: { CXMLDOMComment *pObj = NULL; hr = CPooledXMLDOMCommentObj::CreateInstance(&pObj); if (S_OK != hr) return hr; pObj->AddRef(); pObj->SetOwnerDoc(pDoc); try { pObj->comment = static_cast<DOMComment*> (node); } catch(DOMException& ex) { pObj->Release(); return MakeHRESULT(ex); } catch(...) { pObj->Release(); return E_FAIL; } hr = pObj->QueryInterface(iid, pVal); if (S_OK != hr) *pVal = NULL; pObj->Release(); break; } case DOMNode::DOCUMENT_NODE: { CXMLDOMDocumentObj *pObj = NULL; hr = CXMLDOMDocumentObj::CreateInstance(&pObj); if (S_OK != hr) return hr; pObj->AddRef(); pObj->SetOwnerDoc(pDoc); try { pObj->m_Document = static_cast<XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument*> (node); } catch(DOMException& ex) { pObj->Release(); return MakeHRESULT(ex); } catch(...) { pObj->Release(); return E_FAIL; } hr = pObj->QueryInterface(iid, pVal); if (S_OK != hr) *pVal = NULL; pObj->Release(); break; } case DOMNode::DOCUMENT_TYPE_NODE: { CXMLDOMDocumentTypeObj *pObj = NULL; hr = CXMLDOMDocumentTypeObj::CreateInstance(&pObj); if (S_OK != hr) return hr; pObj->AddRef(); pObj->SetOwnerDoc(pDoc); try { pObj->documentType = static_cast<DOMDocumentType*> (node); } catch(DOMException& ex) { pObj->Release(); return MakeHRESULT(ex); } catch(...) { pObj->Release(); return E_FAIL; } hr = pObj->QueryInterface(iid, pVal); if (S_OK != hr) *pVal = NULL; pObj->Release(); break; } case DOMNode::DOCUMENT_FRAGMENT_NODE: { CXMLDOMDocumentFragmentObj *pObj = NULL; hr = CXMLDOMDocumentFragmentObj::CreateInstance(&pObj); if (S_OK != hr) return hr; pObj->AddRef(); pObj->SetOwnerDoc(pDoc); try { pObj->documentFragment = static_cast<DOMDocumentFragment*> (node); } catch(DOMException& ex) { pObj->Release(); return MakeHRESULT(ex); } catch(...) { pObj->Release(); return E_FAIL; } hr = pObj->QueryInterface(iid, pVal); if (S_OK != hr) *pVal = NULL; pObj->Release(); break; } case DOMNode::NOTATION_NODE: { CXMLDOMNotationObj *pObj = NULL; hr = CXMLDOMNotationObj::CreateInstance(&pObj); if (S_OK != hr) return hr; pObj->AddRef(); pObj->SetOwnerDoc(pDoc); try { pObj->notation = static_cast<DOMNotation*> (node); } catch(DOMException& ex) { pObj->Release(); return MakeHRESULT(ex); } catch(...) { pObj->Release(); return E_FAIL; } hr = pObj->QueryInterface(iid, pVal); if (S_OK != hr) *pVal = NULL; pObj->Release(); break; } default: hr = E_NOTIMPL; break; } return hr; }