void read_xml_node( pugi::xml_node node, Ptree &pt, int flags) { typedef typename Ptree::key_type::value_type Ch; switch ( node.type() ) { case pugi::node_element: { Ptree &tmp = pt.push_back(std::make_pair( node.name(), Ptree()))->second; for ( pugi::xml_attribute attr = node.first_attribute(); attr; attr = attr.next_attribute() ) tmp.put( xmlattr<Ch>() + "." + attr.name(), attr.value()); for ( pugi::xml_node child = node.first_child(); child; child = child.next_sibling()) read_xml_node(child, tmp, flags); } break; case pugi::node_pcdata: { if (flags & no_concat_text) pt.push_back(std::make_pair(xmltext<Ch>(), Ptree( node.value() ))); else pt.data() += node.value(); } break; case pugi::node_comment: { if (!(flags & no_comments)) pt.push_back(std::make_pair(xmlcomment<Ch>(), Ptree( node.value() ))); } break; default: // skip other types break; } }
bool XMLFile::CombineText(const pugi::xml_node& patch, const pugi::xml_node& original, bool prepend) const { if (!patch || !original) return false; if ((patch.type() == pugi::node_pcdata && original.type() == pugi::node_pcdata) || (patch.type() == pugi::node_cdata && original.type() == pugi::node_cdata)) { if (prepend) const_cast<pugi::xml_node&>(original).set_value(Urho3D::ToString("%s%s", patch.value(), original.value()).CString()); else const_cast<pugi::xml_node&>(original).set_value(Urho3D::ToString("%s%s", original.value(), patch.value()).CString()); return true; } return false; }
void xmlManager::print_node(pugi::xml_node source_node, string prefix) { cout << prefix << source_node.name() << ": " << source_node.value() << endl; for (pugi::xml_attribute_iterator it = source_node.attributes_begin(); it != source_node.attributes_end(); it++) cout << prefix + "\t" << it->name() << " : " << it->value() << endl; for (pugi::xml_node_iterator it = source_node.begin(); it != source_node.end(); it++) print_node(*it, prefix + "\t"); }
int SChatEdit::_InsertFormatText(int iCaret,CHARFORMATW cf,pugi::xml_node xmlText,BOOL bCanUndo) { SStringW strText = xmlText.value(); if(xmlText.name() == KLabelSmiley) {//insert smiley SComPtr<ISoSmileyCtrl> pSmiley; HRESULT hr=::CoCreateInstance(CLSID_CSoSmileyCtrl,NULL,CLSCTX_INPROC,__uuidof(ISoSmileyCtrl),(LPVOID*)&pSmiley); if(FAILED(hr)) return 0; SComPtr<IRichEditOle> ole; if(SSendMessage(EM_GETOLEINTERFACE,0,(LPARAM)(void**)&ole) && ole) { SComPtr<IRichEditOleCallback> pCallback; hr=ole->QueryInterface(IID_IRichEditOleCallback,(void**)&pCallback); if(FAILED(hr)) return 0; SComPtr<ISmileyHost> host; hr = pCallback->QueryInterface(__uuidof(ISmileyHost),(void**)&host); if(FAILED(hr)) return 0; SComPtr<ISmileySource> pSource; hr = host->CreateSource(&pSource); if(FAILED(hr)) return 0; { UINT uID = xmlText.attribute(L"id").as_uint(-1); SStringW strPath = xmlText.attribute(L"path").value(); if(uID != -1) hr = pSource->LoadFromID(uID); else hr = pSource->LoadFromFile(strPath); if(SUCCEEDED(hr)) { pSmiley->SetSource(pSource); SSendMessage(EM_SETSEL,iCaret,iCaret); pSmiley->Insert2Richedit((DWORD_PTR)(void*)ole); } } } return SUCCEEDED(hr)?1:0; } CHARFORMATW cfNew = cf; cfNew.dwMask = 0; if(xmlText.name() == KLabelColor) { cfNew.crTextColor = StringToColor(xmlText.attribute(L"value").value()) & 0x00ffffff; cfNew.dwMask |= CFM_COLOR; }else if(xmlText.name()== KLabelFont) { wcscpy(cf.szFaceName,cfNew.szFaceName); wcscpy_s(cfNew.szFaceName,LF_FACESIZE-1,xmlText.attribute(L"value").value()); cfNew.dwMask |= CFM_FACE; }else if(xmlText.name()==KLabelUnderline) { cfNew.dwMask |=CFM_UNDERLINE; cfNew.dwEffects |= CFE_UNDERLINE; }else if(xmlText.name() == KLabelItalic) { cfNew.dwMask |=CFM_ITALIC; cfNew.dwEffects |= CFE_ITALIC; }else if(xmlText.name() == KLabelBold) { cfNew.dwMask |=CFM_BOLD; cfNew.dwEffects |= CFE_BOLD; }else if(xmlText.name() == KLabelStrike) { cfNew.dwMask |= CFM_STRIKEOUT; cfNew.dwEffects |= CFE_STRIKEOUT; }else if(xmlText.name() == KLabelLink) { cfNew.dwMask |= CFM_LINK; cfNew.dwEffects |= CFE_LINK; COLORREF cr = StringToColor(xmlText.attribute(L"color").value()); if(cr!=0) { cfNew.dwMask |= CFM_COLOR; cfNew.crTextColor = cr & 0x00ffffff; } }else if(xmlText.name() == KLabelSize) { cfNew.dwMask |= CFM_SIZE; HDC hdc=GetDC(NULL); LONG yPixPerInch = GetDeviceCaps(hdc, LOGPIXELSY); ReleaseDC(NULL,hdc); cfNew.yHeight = abs(MulDiv(xmlText.attribute(L"value").as_uint(12), LY_PER_INCH, yPixPerInch)); } int nRet = strText.GetLength(); SSendMessage(EM_REPLACESEL,bCanUndo,(LPARAM)(LPCWSTR)strText); int iEnd = iCaret + nRet; SSendMessage(EM_SETSEL,iCaret,iEnd); SSendMessage(EM_SETCHARFORMAT,SCF_SELECTION,(LPARAM)&cfNew); iCaret = iEnd; SSendMessage(EM_SETSEL,iCaret,iCaret); pugi::xml_node xmlChild = xmlText.first_child(); while(xmlChild) { int nSubLen = _InsertFormatText(iCaret,cfNew,xmlChild,bCanUndo); iCaret += nSubLen; nRet += nSubLen; xmlChild = xmlChild.next_sibling(); } if(cfNew.dwMask) { cf.dwMask = CFM_ALL; SSendMessage(EM_SETCHARFORMAT,SCF_SELECTION,(LPARAM)&cf); } return nRet; }
virtual bool for_each(pugi::xml_node& node) { Log::log(logModule, level, "XML node type = [%s], name = [%s], value = [%s]", node_types[node.type()], node.name(), node.type() == pugi::node_cdata || node.type() == pugi::node_pcdata ? node.text().get() : node.value()); for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { Log::log(logModule, level, " attribute name = [%s], value = [%s]", ait->name(), ait->value()); } return true; }
virtual bool for_each(pugi::xml_node& node) { for (int i = 0; i < depth(); ++i) std::cout << " "; // indentation std::cout << /* node_types[node.type()] << */ ": name='" << node.name() << "', value='" << node.value() << "'\n"; return true; // continue traversal }