| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "libxml_utils.h" | 5 #include "libxml_utils.h" |
| 6 | 6 |
| 7 #include "libxml/xmlreader.h" | 7 #include "libxml/xmlreader.h" |
| 8 | 8 |
| 9 std::string XmlStringToStdString(const xmlChar* xmlstring) { | 9 std::string XmlStringToStdString(const xmlChar* xmlstring) { |
| 10 // xmlChar*s are UTF-8, so this cast is safe. | 10 // xmlChar*s are UTF-8, so this cast is safe. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 bool XmlReader::NodeAttribute(const char* name, std::string* out) { | 42 bool XmlReader::NodeAttribute(const char* name, std::string* out) { |
| 43 xmlChar* value = xmlTextReaderGetAttribute(reader_, BAD_CAST name); | 43 xmlChar* value = xmlTextReaderGetAttribute(reader_, BAD_CAST name); |
| 44 if (!value) | 44 if (!value) |
| 45 return false; | 45 return false; |
| 46 *out = XmlStringToStdString(value); | 46 *out = XmlStringToStdString(value); |
| 47 xmlFree(value); | 47 xmlFree(value); |
| 48 return true; | 48 return true; |
| 49 } | 49 } |
| 50 | 50 |
| 51 bool XmlReader::IsClosingElement() { |
| 52 return NodeType() == XML_READER_TYPE_END_ELEMENT; |
| 53 } |
| 54 |
| 51 bool XmlReader::ReadElementContent(std::string* content) { | 55 bool XmlReader::ReadElementContent(std::string* content) { |
| 52 const int start_depth = Depth(); | 56 const int start_depth = Depth(); |
| 53 | 57 |
| 54 if (xmlTextReaderIsEmptyElement(reader_)) { | 58 if (xmlTextReaderIsEmptyElement(reader_)) { |
| 55 // Empty tag. We succesfully read the content, but it's | 59 // Empty tag. We succesfully read the content, but it's |
| 56 // empty. | 60 // empty. |
| 57 *content = ""; | 61 *content = ""; |
| 58 // Advance past this empty tag. | 62 // Advance past this empty tag. |
| 59 if (!Read()) | 63 if (!Read()) |
| 60 return false; | 64 return false; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 writer_ = xmlNewTextWriterMemory(buffer_, 0); | 118 writer_ = xmlNewTextWriterMemory(buffer_, 0); |
| 115 xmlTextWriterSetIndent(writer_, 1); | 119 xmlTextWriterSetIndent(writer_, 1); |
| 116 xmlTextWriterStartDocument(writer_, NULL, NULL, NULL); | 120 xmlTextWriterStartDocument(writer_, NULL, NULL, NULL); |
| 117 } | 121 } |
| 118 | 122 |
| 119 void XmlWriter::StopWriting() { | 123 void XmlWriter::StopWriting() { |
| 120 xmlTextWriterEndDocument(writer_); | 124 xmlTextWriterEndDocument(writer_); |
| 121 xmlFreeTextWriter(writer_); | 125 xmlFreeTextWriter(writer_); |
| 122 writer_ = NULL; | 126 writer_ = NULL; |
| 123 } | 127 } |
| OLD | NEW |