Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions libs/openFrameworks/utils/ofXml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ using std::string;
ofXml::ofXml()
:doc(new pugi::xml_document){
xml = doc->root();
parsing_options = OF_PARSE_DEFAULT;
}

ofXml::ofXml(std::shared_ptr<pugi::xml_document> doc, const pugi::xml_node & xml)
Expand All @@ -15,9 +16,13 @@ ofXml::ofXml(std::shared_ptr<pugi::xml_document> doc, const pugi::xml_node & xml

}

void ofXml::setParsingOptions(unsigned int l_parsing_options) {
parsing_options = l_parsing_options;
}

bool ofXml::load(const of::filesystem::path & file){
auto auxDoc = std::make_shared<pugi::xml_document>();
auto res = auxDoc->load_file(ofToDataPath(file).c_str());
auto res = auxDoc->load_file(ofToDataPath(file).c_str(), parsing_options);
if( res ){
doc = auxDoc;
xml = doc->root();
Expand All @@ -35,9 +40,9 @@ bool ofXml::load(const ofBuffer & buffer){
bool ofXml::parse(const std::string & xmlStr){
auto auxDoc { std::make_shared<pugi::xml_document>() };
#if ( defined(PUGIXML_VERSION) && PUGIXML_VERSION >= 150 )
if(auxDoc->load_string(xmlStr.c_str())){
if(auxDoc->load_string(xmlStr.c_str(), parsing_options)){
#else
if(auxDoc->load(xmlStr.c_str())){
if(auxDoc->load(xmlStr.c_str(), parsing_options)){
#endif
doc = auxDoc;
xml = doc->root();
Expand Down
24 changes: 24 additions & 0 deletions libs/openFrameworks/utils/ofXml.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@
#include "ofParameter.h"
#include <pugixml.hpp>

enum ofXmlParsingOption: const unsigned int {
OF_PARSE_MINIMAL = pugi::parse_minimal,
OF_PARSE_DEFAULT = pugi::parse_default,
OF_PARSE_FULL = pugi::parse_full,

OF_PARSE_DECLARATION = pugi::parse_declaration,
OF_PARSE_DOCTYPE = pugi::parse_doctype,
OF_PARSE_PI = pugi::parse_pi,
OF_PARSE_COMMENTS = pugi::parse_comments,
OF_PARSE_CDATA = pugi::parse_cdata,
OF_PARSE_TRIM_PCDATA = pugi::parse_trim_pcdata,
OF_PARSE_WS_PCDATA = pugi::parse_ws_pcdata,
OF_PARSE_WS_PCDATA_SINGLE = pugi::parse_ws_pcdata_single,
OF_PARSE_EMBED_PCDATA = pugi::parse_embed_pcdata,
OF_PARSE_FRAGMENT = pugi::parse_fragment,
OF_PARSE_ESCAPES = pugi::parse_escapes,
OF_PARSE_EOL = pugi::parse_eol,
OF_PARSE_WCONV_ATTRIBUTE = pugi::parse_wconv_attribute,
OF_PARSE_WNORM_ATTRIBUTE = pugi::parse_wnorm_attribute
};

template<typename It>
class ofXmlIterator;
class ofXmlAttributeIterator;
Expand Down Expand Up @@ -101,6 +122,7 @@ class ofXml{

bool load(const of::filesystem::path & file);
bool load(const ofBuffer & buffer);
void setParsingOptions(unsigned int l_parsing_options);
bool parse(const std::string & xmlStr);
bool save(const of::filesystem::path & file) const;
void clear();
Expand All @@ -114,6 +136,8 @@ class ofXml{
ofXml prependChild(const ofXml & xml);
bool removeChild(const ofXml & node);

unsigned int parsing_options;

#if PUGIXML_VERSION>=170
ofXml appendChild(ofXml && xml);
ofXml prependChild(ofXml && xml);
Expand Down