本文整理汇总了C++中msxml::IXMLDOMElementPtr::setAttribute方法的典型用法代码示例。如果您正苦于以下问题:C++ IXMLDOMElementPtr::setAttribute方法的具体用法?C++ IXMLDOMElementPtr::setAttribute怎么用?C++ IXMLDOMElementPtr::setAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类msxml::IXMLDOMElementPtr
的用法示例。
在下文中一共展示了IXMLDOMElementPtr::setAttribute方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NewItem
bool CHelpDB::NewItem(CTSTRING& _sAlias, CTSTRING& sText, CTSTRING& sCreator)
{
MSXML::IXMLDOMElementPtr El;
bool r = false;
if(m_doc == 0) return false;
TSTRING sAlias;
{
TCHAR* tsz = _tcsdup(_sAlias.c_str());
_tcsupr(tsz);
sAlias = tsz;
SAFE_FREE(tsz);
}
// Just determine if it exists.
if(GetItemElement(sAlias, El, false))
{
// it already exists; fail.
sprintf(m_err, _T("%s already exists. If you want to change the existing entry, use !msgchange."), sAlias.c_str());
g_pLog->msg(_T("%s"), m_err.c_str());
}
else
{
// doesn't already exist... we're golden like the shower. This time
// just call GetItemElement() with bCreate set to true.
if(!GetItemElement(sAlias, El, true))
{
sprintf(m_err, _T("%s could not be added."), sAlias.c_str());
g_pLog->msg(_T("%s"), m_err.c_str());
}
else
{
El->setAttribute(TAG_ALIAS, sAlias.c_str());
El->setAttribute(TAG_CREATOR, sCreator.c_str());
El->setAttribute(TAG_TEXT, sText.c_str());
El->setAttribute(TAG_USAGE, _T("0"));
SYSTEMTIME st;
TSTRING sTime;
GetLocalTime(&st);
Bin2Str(sTime, (BYTE*)&st, sizeof(st));
El->setAttribute(TAG_TIME, sTime.c_str());
g_pLog->msg(_T("New db item: %s = %s"), _sAlias.c_str(), sText.c_str());
r = true;
}
}
return r;
}
示例2: ChangeItem
bool CHelpDB::ChangeItem(CTSTRING& sAlias, CTSTRING& sText)
{
MSXML::IXMLDOMElementPtr El;
HRESULT hr = 0;
bool r = false;
if(m_doc == 0) return false;
if(GetItemElement(sAlias, El, false))
{
if(SUCCEEDED(hr = El->setAttribute(TAG_TEXT, sText.c_str())))
{
g_pLog->msg(_T("Item changed: %s = %s"), sAlias.c_str(), sText.c_str());
r = true;
}
else
{
g_pLog->msg(_T("SetAttribute(%s=%s) failed, hr=0x%08x"), TAG_TEXT, sText.c_str(), hr);
}
}
else
{
sprintf(m_err, _T("%s was not found in the database."), sAlias.c_str());
g_pLog->msg(_T("CHelpDB::ChangeItem(%s) - Item wasn't found."), sAlias.c_str());
}
return r;
}
示例3: XMLSetAttribute
Result XMLSetAttribute(const _variant_t& val, MSXML::IXMLDOMElementPtr pEl, const string& sAttribute)
{
Result r;
try
{
pEl->setAttribute(sAttribute.c_str(), val);
r.Succeed();
}
catch(_com_error& e)
{
r.Fail(Format("Com error: % %").s(e.ErrorMessage()).s(e.Description()).Str());
}
return r;
}
示例4: Build
////////////////////////////////////////////////////////////////////////////
// Function: Create an XML DOM Document from Scratch in memory
////////////////////////////////////////////////////////////////////////////
HRESULT CXMLDocument::Build()
{
// Create a root node
MSXML::IXMLDOMNodePtr pRoot;
m_pDoc->createNode(CComVariant(MSXML::NODE_ELEMENT), CComBSTR("Root"), NULL, &pRoot);
// add child nodes
HRESULT hr = S_OK;
for (int i = 0; i < 10; i++)
{
MSXML::IXMLDOMNodePtr pNode;
m_pDoc->createNode(CComVariant(MSXML::NODE_ELEMENT), CComBSTR("Order"), NULL, &pNode);
MSXML::IXMLDOMElementPtr pElement = pNode;
if (pElement != NULL)
pElement->setAttribute(CComBSTR("id"), CComVariant(i));
MSXML::IXMLDOMNodePtr p0 = NULL;
CComVariant after;
hr = pRoot->insertBefore(pNode, after, &p0);
hr = CheckHR(hr, "inserting node");
// The XML Document should now own the node.
for (int j = 0; j < 10; j++)
{
MSXML::IXMLDOMNodePtr pNode2;
m_pDoc->createNode(CComVariant(MSXML::NODE_ELEMENT), CComBSTR("Item"), NULL, &pNode2);
MSXML::IXMLDOMElementPtr pElement2 = pNode2;
if (pElement2 != NULL)
pElement2->setAttribute(CComBSTR("id"), CComVariant((i*10) + j));
MSXML::IXMLDOMNodePtr p1 = NULL;
CComVariant after;
hr = p0->insertBefore(pNode2, after, &p1);
hr = CheckHR(hr, "inserting node");
// The XML Document should now own the node.
}
}
// Now attach this new subtree to the document.
m_pDoc->appendChild(pRoot, NULL);
return hr;
}
示例5: ElementToStruct
bool CHelpDB::ElementToStruct(CHelpMessage& info, MSXML::IXMLDOMElementPtr& El, bool bIncUsage)
{
bool r = false;
try
{
_variant_t vAlias = El->getAttribute(TAG_ALIAS);
_variant_t vCreator = El->getAttribute(TAG_CREATOR);
_variant_t vText = El->getAttribute(TAG_TEXT);
_variant_t vCreated = El->getAttribute(TAG_TIME);
_variant_t vUsage = El->getAttribute(TAG_USAGE);
HW2T(info.Alias, vAlias.bstrVal);
HW2T(info.Creator, vCreator.bstrVal);
HW2T(info.Text, vText.bstrVal);
TSTRING sTemp;
HW2T(sTemp, vCreated.bstrVal);
Str2Bin(sTemp, (PBYTE)&info.Created, sizeof(info.Created));
HW2T(sTemp, vUsage.bstrVal);
info.nUsage = _tcstoul(sTemp.c_str(), 0, 10);
if(bIncUsage)
{
TCHAR tsz[500];
info.nUsage++;
_ultot(info.nUsage, tsz, 10);
El->setAttribute(_bstr_t(TAG_USAGE), _variant_t(tsz));
}
r = true;
}
catch(_com_error& e)
{
sprintf(m_err, _T("COM Error: %08x"), e.Error(), (TCHAR*)e.Description());
g_pLog->msg(_T("CHelpDB::ElementToStruct ERROR"));
}
return r;
}
示例6: Save
void CArc::Save(MSXML::IXMLDOMElementPtr pRoot)
{
MSXML::IXMLDOMElementPtr pGO;
MSXML::IXMLDOMElementPtr pStatic;
MSXML::IXMLDOMElementPtr pDynamic;
MSXML::IXMLDOMElementPtr pAttr;
_variant_t val;
MSXML::IXMLDOMDocumentPtr pDoc=pRoot->ownerDocument;
//add a graphy object
pGO=pDoc->createElement(L"go");
val.vt=VT_BSTR;
val.bstrVal=::SysAllocString(L"arc");
pGO->setAttribute(L"type",val);
pRoot->appendChild(pGO);
//add a group static attribution
pStatic=pDoc->createElement(L"static");
pGO->appendChild(pStatic);
//position
pAttr=pDoc->createElement(L"position");
pStatic->appendChild(pAttr);
//x1
val.vt=VT_I4;
val.lVal=m_lx1;
pAttr->setAttribute(L"x1",val);
//y1
val.vt=VT_I4;
val.lVal=m_ly1;
pAttr->setAttribute(L"y1",val);
//x2
val.vt=VT_I4;
val.lVal=m_lx2;
pAttr->setAttribute(L"x2",val);
//y2
val.vt=VT_I4;
val.lVal=m_ly2;
pAttr->setAttribute(L"y2",val);
//x3
val.vt=VT_I4;
val.lVal=m_lx3;
pAttr->setAttribute(L"x3",val);
//y3
val.vt=VT_I4;
val.lVal=m_ly1;
pAttr->setAttribute(L"y3",val);
//x4
val.vt=VT_I4;
val.lVal=m_lx4;
pAttr->setAttribute(L"x4",val);
//y4
val.vt=VT_I4;
val.lVal=m_ly4;
pAttr->setAttribute(L"y4",val);
//pen
pAttr=pDoc->createElement("pen");
pStatic->appendChild(pAttr);
//style
val.vt=VT_UI4;
val.ulVal=m_pen.lopnStyle;
pAttr->setAttribute(L"s",val);
//width
val.vt=VT_I4;
val.lVal=m_pen.lopnWidth.x;
pAttr->setAttribute(L"w",val);
//color
val.vt=VT_UI4;
val.ulVal=m_pen.lopnColor;
pAttr->setAttribute(L"c",val);
//if linked then save dynamic attribution
pDynamic=pDoc->createElement("dynamic");
pGO->appendChild(pDynamic);
if(m_DnyAttr.m_Linked){
//linked
val.vt=VT_BOOL;
val.boolVal=-1;
pDynamic->setAttribute(L"linked",val);
//save dynamic attribution
m_DnyAttr.Save(pDoc,pDynamic);
}else{
//unlinked
val.vt=VT_BOOL;
val.boolVal=FALSE;
pDynamic->setAttribute(L"linked",val);
}
}
示例7: Save
void CText::Save(MSXML::IXMLDOMElementPtr pRoot)
{
MSXML::IXMLDOMElementPtr pGO;
MSXML::IXMLDOMElementPtr pStatic;
MSXML::IXMLDOMElementPtr pDynamic;
MSXML::IXMLDOMElementPtr pAttr;
_variant_t val;
MSXML::IXMLDOMDocumentPtr pDoc=pRoot->ownerDocument;
//add a graphy object
pGO=pDoc->createElement(L"go");
val.vt=VT_BSTR;
val.bstrVal=::SysAllocString(L"text");
pGO->setAttribute(L"type",val);
pRoot->appendChild(pGO);
//add a group static attribution
pStatic=pDoc->createElement(L"static");
pGO->appendChild(pStatic);
//position
pAttr=pDoc->createElement(L"position");
pStatic->appendChild(pAttr);
//x1
val.vt=VT_I4;
val.lVal=m_lx1;
pAttr->setAttribute(L"x1",val);
//y1
val.vt=VT_I4;
val.lVal=m_ly1;
pAttr->setAttribute(L"y1",val);
//x2
val.vt=VT_I4;
val.lVal=m_lx2;
pAttr->setAttribute(L"x2",val);
//y2
val.vt=VT_I4;
val.lVal=m_ly2;
pAttr->setAttribute(L"y2",val);
//face color
pAttr=pDoc->createElement("color");
pStatic->appendChild(pAttr);
//color
val.vt=VT_UI4;
val.ulVal=m_FaceColor;
pAttr->setAttribute(L"c",val);
//font
pAttr=pDoc->createElement("font");
pStatic->appendChild(pAttr);
//lfHeight
val.vt=VT_I4;
val.lVal=m_font.lfHeight;
pAttr->setAttribute(L"h",val);
//lfWidth
val.vt=VT_I4;
val.lVal=m_font.lfWidth;
pAttr->setAttribute(L"wd",val);
//lfEscapement
val.vt=VT_I4;
val.lVal=m_font.lfEscapement;
pAttr->setAttribute(L"e",val);
//lfOrientation
val.vt=VT_I4;
val.lVal=m_font.lfOrientation;
pAttr->setAttribute(L"o",val);
//lfWeight
val.vt=VT_I4;
val.lVal=m_font.lfWeight;
pAttr->setAttribute(L"wg",val);
//lfItalic
val.vt=VT_UI1;
val.bVal=m_font.lfItalic;
pAttr->setAttribute(L"i",val);
//lfUnderline
val.vt=VT_UI1;
val.bVal=m_font.lfUnderline;
pAttr->setAttribute(L"u",val);
//lfStrikeOut
val.vt=VT_UI1;
val.bVal=m_font.lfStrikeOut;
pAttr->setAttribute(L"so",val);
//lfCharSet
val.vt=VT_UI1;
val.bVal=m_font.lfCharSet;
pAttr->setAttribute(L"cs",val);
//lfOutPrecision
val.vt=VT_UI1;
val.bVal=m_font.lfOutPrecision;
pAttr->setAttribute(L"op",val);
//lfClipPrecision
val.vt=VT_UI1;
val.bVal=m_font.lfClipPrecision;
pAttr->setAttribute(L"cp",val);
//lfQuality
val.vt=VT_UI1;
val.bVal=m_font.lfQuality;
pAttr->setAttribute(L"q",val);
//.........这里部分代码省略.........
示例8: Save
void CMeta::Save(MSXML::IXMLDOMElementPtr pRoot)
{
MSXML::IXMLDOMElementPtr pGO;
MSXML::IXMLDOMElementPtr pStatic;
MSXML::IXMLDOMElementPtr pDynamic;
MSXML::IXMLDOMElementPtr pAttr;
_variant_t val;
MSXML::IXMLDOMDocumentPtr pDoc=pRoot->ownerDocument;
//add a graphy object
pGO=pDoc->createElement(L"go");
val.vt=VT_BSTR;
val.bstrVal=::SysAllocString(L"meta");
pGO->setAttribute(L"type",val);
pRoot->appendChild(pGO);
//add a group static attribution
pStatic=pDoc->createElement(L"static");
pGO->appendChild(pStatic);
//position
pAttr=pDoc->createElement(L"position");
pStatic->appendChild(pAttr);
//x1
val.vt=VT_I4;
val.lVal=m_lx1;
pAttr->setAttribute(L"x1",val);
//y1
val.vt=VT_I4;
val.lVal=m_ly1;
pAttr->setAttribute(L"y1",val);
//x2
val.vt=VT_I4;
val.lVal=m_lx2;
pAttr->setAttribute(L"x2",val);
//y2
val.vt=VT_I4;
val.lVal=m_ly2;
pAttr->setAttribute(L"y2",val);
//picture file
pAttr=pDoc->createElement("file");
pStatic->appendChild(pAttr);
val.vt=VT_BSTR;
val.bstrVal=m_sPicFile.AllocSysString();
pAttr->setAttribute(L"path",val);
//if linked then save dynamic attribution
pDynamic=pDoc->createElement("dynamic");
pGO->appendChild(pDynamic);
if(m_DnyAttr.m_Linked){
//linked
val.vt=VT_BOOL;
val.boolVal=-1;
pDynamic->setAttribute(L"linked",val);
//save dynamic attribution
m_DnyAttr.Save(pDoc,pDynamic);
}else{
//unlinked
val.vt=VT_BOOL;
val.boolVal=FALSE;
pDynamic->setAttribute(L"linked",val);
}
}
示例9: if
HRESULT touchmind::converter::NodeModelXMLEncoder::Encode(IN std::shared_ptr<touchmind::model::node::NodeModel> node,
IN MSXML::IXMLDOMDocumentPtr pXMLDoc,
OUT MSXML::IXMLDOMElementPtr &xmlNodeElement) {
HRESULT hr = S_OK;
try {
// id
std::wstring ws_idValue;
touchmind::NodeIdToString(node->GetId(), ws_idValue);
_variant_t v_idValue(ws_idValue.c_str());
xmlNodeElement->setAttribute(s_id, v_idValue);
// position
if (node->GetPosition() == NODE_SIDE_LEFT) {
xmlNodeElement->setAttribute(s_position, v_positionLeftValue);
} else if (node->GetPosition() == NODE_SIDE_RIGHT) {
xmlNodeElement->setAttribute(s_position, v_positionRightValue);
}
// created time
std::wstring ws_createdTime;
touchmind::SystemtimeToString(&node->GetCreatedTime(), ws_createdTime);
_variant_t v_createdTimeValue(ws_createdTime.c_str());
xmlNodeElement->setAttribute(s_createdTime, v_createdTimeValue);
// modified time
std::wstring ws_modifiedTime;
touchmind::SystemtimeToString(&node->GetModifiedTime(), ws_modifiedTime);
_variant_t v_modifiedTimeValue(ws_modifiedTime.c_str());
xmlNodeElement->setAttribute(s_modifiedTime, v_modifiedTimeValue);
// width
std::wstring ws_width;
touchmind::SizeToString(node->GetWidth(), ws_width);
_variant_t v_width(ws_width.c_str());
xmlNodeElement->setAttribute(s_width, v_width);
// height
std::wstring ws_height;
touchmind::SizeToString(node->GetHeight(), ws_height);
_variant_t v_height(ws_height.c_str());
xmlNodeElement->setAttribute(s_height, v_height);
// background color
if (!touchmind::util::ColorUtil::Equal(node->GetBackgroundColor(), D2D1::ColorF(D2D1::ColorF::White))) {
std::wstring ws_backgroundColorValue;
// touchmind::ColorrefToString(touchmind::util::ColorUtil::ToColorref(node->GetBackgroundColor()),
// ws_backgroundColorValue);
touchmind::ColorFToString(node->GetBackgroundColor(), ws_backgroundColorValue);
_variant_t v_backgroundColorValue(ws_backgroundColorValue.c_str());
xmlNodeElement->setAttribute(s_backgroundColor, v_backgroundColorValue);
}
// shape
if (node->GetNodeShape() != prop::NodeShape::GetDefaultNodeShape()) {
std::wstring ws_nodeShape = prop::NodeShape::ToString(node->GetNodeShape());
_variant_t v_nodeShape(ws_nodeShape.c_str());
xmlNodeElement->setAttribute(s_shape, v_nodeShape);
}
xmlNodeElement->setAttribute(s_height, v_height);
// text element
MSXML::IXMLDOMElementPtr xmlTextElement = pXMLDoc->createElement(s_text);
xmlNodeElement->appendChild(xmlTextElement);
// text
_bstr_t s_textValue(node->GetText().c_str());
MSXML::IXMLDOMTextPtr pText = pXMLDoc->createTextNode(s_textValue);
xmlTextElement->appendChild(pText);
if (node->GetFontAttributeCount() > 0) {
// fontAttriutes element
MSXML::IXMLDOMElementPtr xmlFontAttributesElement = pXMLDoc->createElement(s_fontAttributes);
xmlTextElement->appendChild(xmlFontAttributesElement);
for (size_t i = 0; i < node->GetFontAttributeCount(); ++i) {
// fontAttribute
MSXML::IXMLDOMElementPtr xmlFontAttributeElement = pXMLDoc->createElement(s_fontAttribute);
xmlFontAttributesElement->appendChild(xmlFontAttributeElement);
// start position
wchar_t buf[1024];
_ltow_s(node->GetFontAttribute(i).startPosition, buf, 1024, 10);
_variant_t v_startPositionValue(buf);
xmlFontAttributeElement->setAttribute(s_startPosition, v_startPositionValue);
// length
_ltow_s(node->GetFontAttribute(i).length, buf, 1024, 10);
_variant_t v_lengthValue(buf);
xmlFontAttributeElement->setAttribute(s_length, v_lengthValue);
// font family
if (node->GetFontAttribute(i).fontFamilyName.length() > 0) {
_variant_t v_fontFamilyValue(node->GetFontAttribute(i).fontFamilyName.c_str());
xmlFontAttributeElement->setAttribute(s_fontFamily, v_fontFamilyValue);
}
// font size
if (node->GetFontAttribute(i).fontSize > 0.0f) {
std::wstring ws_fontSizeValue;
touchmind::FontSizeToString(node->GetFontAttribute(i).fontSize, ws_fontSizeValue);
//.........这里部分代码省略.........