1 /* 2 * Copyright (c) 2024-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef HISTREAMER_XML_PARSER_H 17 #define HISTREAMER_XML_PARSER_H 18 19 #include "xml_element.h" 20 #include <string> 21 #include <libxml/parser.h> 22 #include <libxml/tree.h> 23 24 namespace OHOS { 25 namespace Media { 26 namespace Plugins { 27 namespace HttpPlugin { 28 class XmlParser { 29 public: 30 XmlParser() = default; 31 ~XmlParser() = default; 32 33 int32_t ParseFromBuffer(const char *buf, int32_t length); 34 int32_t ParseFromString(const std::string &xmlStr); 35 int32_t ParseFromFile(const std::string &filePath); 36 std::shared_ptr<XmlElement> GetRootElement(); 37 int32_t GetAttribute(std::shared_ptr<XmlElement> element, const std::string attrName, std::string &value); 38 void SkipElementNameSpace(std::string &elementName) const; 39 void DestroyDoc(); 40 41 private: 42 static constexpr const char *const TAG = "XmlParser"; 43 xmlDocPtr xmlDocPtr_; 44 }; 45 } // namespace HttpPluginLite 46 } // namespace Plugin 47 } // namespace Media 48 } // namespace OHOS 49 #endif // HISTREAMER_XML_PARSER_H 50