| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_COMMON_LIBXML_UTILS_H__ | 5 #ifndef CHROME_COMMON_LIBXML_UTILS_H__ |
| 6 #define CHROME_COMMON_LIBXML_UTILS_H__ | 6 #define CHROME_COMMON_LIBXML_UTILS_H__ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "libxml/xmlreader.h" | 10 #include "libxml/xmlreader.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 // Adds a new element with name |element_name| and content |content| | 156 // Adds a new element with name |element_name| and content |content| |
| 157 // to the buffer. Example: <|element_name|>|content|</|element_name|> | 157 // to the buffer. Example: <|element_name|>|content|</|element_name|> |
| 158 // Returns false on errors. | 158 // Returns false on errors. |
| 159 bool WriteElement(const std::string& element_name, | 159 bool WriteElement(const std::string& element_name, |
| 160 const std::string& content) { | 160 const std::string& content) { |
| 161 return xmlTextWriterWriteElement(writer_, | 161 return xmlTextWriterWriteElement(writer_, |
| 162 BAD_CAST element_name.c_str(), | 162 BAD_CAST element_name.c_str(), |
| 163 BAD_CAST content.c_str()) >= 0; | 163 BAD_CAST content.c_str()) >= 0; |
| 164 } | 164 } |
| 165 | 165 |
| 166 // Helper functions not provided by xmlTextWriter ----------------------------
------ | 166 // Helper functions not provided by xmlTextWriter --------------------------- |
| 167 | 167 |
| 168 // Returns the string that has been written to the buffer. | 168 // Returns the string that has been written to the buffer. |
| 169 std::string GetWrittenString() { | 169 std::string GetWrittenString() { |
| 170 if (buffer_ == NULL) | 170 if (buffer_ == NULL) |
| 171 return ""; | 171 return ""; |
| 172 return XmlStringToStdString(buffer_->content); | 172 return XmlStringToStdString(buffer_->content); |
| 173 } | 173 } |
| 174 | 174 |
| 175 private: | 175 private: |
| 176 // The underlying libxml xmlTextWriter. | 176 // The underlying libxml xmlTextWriter. |
| 177 xmlTextWriterPtr writer_; | 177 xmlTextWriterPtr writer_; |
| 178 | 178 |
| 179 // Stores the output. | 179 // Stores the output. |
| 180 xmlBufferPtr buffer_; | 180 xmlBufferPtr buffer_; |
| 181 }; | 181 }; |
| 182 | 182 |
| 183 #endif // CHROME_COMMON_LIBXML_UTILS_H__ | 183 #endif // CHROME_COMMON_LIBXML_UTILS_H__ |
| 184 | 184 |
| OLD | NEW |