1
// XMLElement.cpp : Implementation of CXMLElement
3
//#include "Activexml.h"
4
#include "XMLElement.h"
7
CXMLElement::CXMLElement()
14
CXMLElement::~CXMLElement()
19
HRESULT CXMLElement::SetParent(IXMLElement *pParent)
21
// Note: parent is not refcounted
27
HRESULT CXMLElement::PutType(long nType)
34
HRESULT CXMLElement::ReleaseAll()
36
// Release all children
42
/////////////////////////////////////////////////////////////////////////////
46
// Return the element's tag name
47
HRESULT STDMETHODCALLTYPE CXMLElement::get_tagName(/* [out][retval] */ BSTR __RPC_FAR *p)
54
*p = SysAllocString(A2OLE(m_szTagName.c_str()));
60
HRESULT STDMETHODCALLTYPE CXMLElement::put_tagName(/* [in] */ BSTR p)
67
m_szTagName = OLE2A(p);
72
// Returns the parent element
73
HRESULT STDMETHODCALLTYPE CXMLElement::get_parent(/* [out][retval] */ IXMLElement __RPC_FAR *__RPC_FAR *ppParent)
83
return m_pParent->QueryInterface(IID_IXMLElement, (void **) ppParent);
90
// Set the specified attribute value
91
HRESULT STDMETHODCALLTYPE CXMLElement::setAttribute(/* [in] */ BSTR strPropertyName, /* [in] */ VARIANT PropertyValue)
93
if (strPropertyName == NULL || PropertyValue.vt != VT_BSTR)
99
std::string szPropertyName = OLE2A(strPropertyName);
100
std::string szPropertyValue = OLE2A(PropertyValue.bstrVal);
101
m_cAttributes[szPropertyName] = szPropertyValue;
107
// Return the requested attribute
108
HRESULT STDMETHODCALLTYPE CXMLElement::getAttribute(/* [in] */ BSTR strPropertyName, /* [out][retval] */ VARIANT __RPC_FAR *PropertyValue)
110
if (strPropertyName == NULL || PropertyValue == NULL)
116
std::string szPropertyName = OLE2A(strPropertyName);
117
StringMap::iterator i = m_cAttributes.find(szPropertyName);
118
if (i == m_cAttributes.end())
123
PropertyValue->vt = VT_BSTR;
124
PropertyValue->bstrVal = SysAllocString(A2OLE((*i).second.c_str()));
129
// Find and remove the specified attribute
130
HRESULT STDMETHODCALLTYPE CXMLElement::removeAttribute(/* [in] */ BSTR strPropertyName)
132
if (strPropertyName == NULL)
138
std::string szPropertyName = OLE2A(strPropertyName);
139
StringMap::iterator i = m_cAttributes.find(szPropertyName);
140
if (i == m_cAttributes.end())
145
m_cAttributes.erase(i);
151
// Return the child collection for this element
152
HRESULT STDMETHODCALLTYPE CXMLElement::get_children(/* [out][retval] */ IXMLElementCollection __RPC_FAR *__RPC_FAR *pp)
154
CXMLElementCollectionInstance *pCollection = NULL;
155
CXMLElementCollectionInstance::CreateInstance(&pCollection);
156
if (pCollection == NULL)
158
return E_OUTOFMEMORY;
161
// Add children to the collection
162
for (ElementList::iterator i = m_cChildren.begin(); i != m_cChildren.end(); i++)
164
pCollection->Add(*i);
167
pCollection->QueryInterface(IID_IXMLElementCollection, (void **) pp);
173
HRESULT STDMETHODCALLTYPE CXMLElement::get_type(/* [out][retval] */ long __RPC_FAR *plType)
184
HRESULT STDMETHODCALLTYPE CXMLElement::get_text(/* [out][retval] */ BSTR __RPC_FAR *p)
190
HRESULT STDMETHODCALLTYPE CXMLElement::put_text(/* [in] */ BSTR p)
196
HRESULT STDMETHODCALLTYPE CXMLElement::addChild(/* [in] */ IXMLElement __RPC_FAR *pChildElem, long lIndex, long lReserved)
198
if (pChildElem == NULL)
203
// Set the child's parent to be this element
204
((CXMLElement *) pChildElem)->SetParent(this);
206
if (lIndex < 0 || lIndex >= m_cChildren.size())
209
m_cChildren.push_back(pChildElem);
213
// TODO m_cChildren.insert(&m_cChildren[lIndex]);
214
m_cChildren.push_back(pChildElem);
221
HRESULT STDMETHODCALLTYPE CXMLElement::removeChild(/* [in] */ IXMLElement __RPC_FAR *pChildElem)