1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "jingle/notifier/listener/xml_element_util.h" 6 7 #include <sstream> 8 #include <string> 9 10 #include "base/strings/string_number_conversions.h" 11 #include "talk/xmllite/qname.h" 12 #include "talk/xmllite/xmlconstants.h" 13 #include "talk/xmllite/xmlelement.h" 14 #include "talk/xmllite/xmlprinter.h" 15 16 namespace notifier { 17 18 std::string XmlElementToString(const buzz::XmlElement& xml_element) { 19 std::ostringstream xml_stream; 20 buzz::XmlPrinter::PrintXml(&xml_stream, &xml_element); 21 return xml_stream.str(); 22 } 23 24 buzz::XmlElement* MakeBoolXmlElement(const char* name, bool value) { 25 const buzz::QName elementQName(buzz::STR_EMPTY, name); 26 const buzz::QName boolAttrQName(buzz::STR_EMPTY, "bool"); 27 buzz::XmlElement* bool_xml_element = 28 new buzz::XmlElement(elementQName, true); 29 bool_xml_element->AddAttr(boolAttrQName, value ? "true" : "false"); 30 return bool_xml_element; 31 } 32 33 buzz::XmlElement* MakeIntXmlElement(const char* name, int value) { 34 const buzz::QName elementQName(buzz::STR_EMPTY, name); 35 const buzz::QName intAttrQName(buzz::STR_EMPTY, "int"); 36 buzz::XmlElement* int_xml_element = 37 new buzz::XmlElement(elementQName, true); 38 int_xml_element->AddAttr(intAttrQName, base::IntToString(value)); 39 return int_xml_element; 40 } 41 42 buzz::XmlElement* MakeStringXmlElement(const char* name, const char* value) { 43 const buzz::QName elementQName(buzz::STR_EMPTY, name); 44 const buzz::QName dataAttrQName(buzz::STR_EMPTY, "data"); 45 buzz::XmlElement* data_xml_element = 46 new buzz::XmlElement(elementQName, true); 47 data_xml_element->AddAttr(dataAttrQName, value); 48 return data_xml_element; 49 } 50 51 } // namespace notifier 52