00001
00002
00003
00004
00005
00006
00007
00008
00012 #include <zypp/parser/LibXMLHelper.h>
00013 #include <libxml/tree.h>
00014 #include <libxml/xmlstring.h>
00015 #include "zypp/parser/xml_parser_assert.h"
00016 #include <sstream>
00017
00018 namespace zypp {
00019
00020 namespace parser {
00021
00022 using namespace std;
00023
00024 LibXMLHelper::LibXMLHelper()
00025 { }
00026
00027 LibXMLHelper::~LibXMLHelper()
00028 { }
00029
00030 std::string LibXMLHelper::attribute(xmlNode * nodePtr,
00031 const string &name,
00032 const string &defaultValue) const
00033 {
00034 xml_assert(nodePtr);
00035 xmlChar *xmlRes = xmlGetProp(nodePtr, BAD_CAST(name.c_str()));
00036 if (xmlRes == 0)
00037 return defaultValue;
00038 else {
00039 string res((const char *)xmlRes);
00040 xmlFree(xmlRes);
00041 return res;
00042 }
00043 }
00044
00045
00046 std::string LibXMLHelper::content(xmlNode * nodePtr) const
00047 {
00048 xml_assert(nodePtr);
00049 xmlChar *xmlRes = xmlNodeGetContent(nodePtr);
00050 if (xmlRes == 0)
00051 return string();
00052 else {
00053 string res((const char*) xmlRes);
00054 xmlFree(xmlRes);
00055 return res;
00056 }
00057 }
00058
00059 std::string LibXMLHelper::name(const xmlNode * nodePtr) const
00060 {
00061 xml_assert(nodePtr);
00062 return string((const char*) nodePtr->name);
00063 }
00064
00065
00066 bool LibXMLHelper::isElement(const xmlNode * nodePtr) const
00067 {
00068 return nodePtr->type == XML_ELEMENT_NODE;
00069 }
00070
00071 std::string LibXMLHelper::positionInfo(const xmlNode * nodePtr) const
00072 {
00073 stringstream strm;
00074 strm << nodePtr->line;
00075 return string("at line ") + strm.str();
00076 }
00077 }
00078 }