From 5cb1ea4c26a99957adeb9d8213f4842ddea271fb Mon Sep 17 00:00:00 2001 From: Ko van der Sloot Date: Tue, 29 Oct 2024 15:48:41 +0100 Subject: [PATCH] improve debugging --- include/libfolia/folia_utils.h | 2 +- src/folia_document.cxx | 2 +- src/folia_utils.cxx | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/libfolia/folia_utils.h b/include/libfolia/folia_utils.h index c28a50e..399a6eb 100644 --- a/include/libfolia/folia_utils.h +++ b/include/libfolia/folia_utils.h @@ -193,7 +193,7 @@ namespace folia { KWargs getArgs( const std::string& ); std::string toString( const KWargs& ); - void addAttributes( const xmlNode *, const KWargs& ); + void addAttributes( const xmlNode *, const KWargs&, bool=false ); KWargs getAttributes( const xmlNode * ); std::string parseDate( const std::string& ); diff --git a/src/folia_document.cxx b/src/folia_document.cxx index 3a0576e..e1c5b32 100644 --- a/src/folia_document.cxx +++ b/src/folia_document.cxx @@ -3235,7 +3235,7 @@ namespace folia { if ( debug == SERIALIZE ){ cerr << "to_xmlDoc: add attributes to root: " << attribs << endl; } - addAttributes( root, attribs ); + addAttributes( root, attribs, debug == SERIALIZE ); xmlNode *md = xmlAddChild( root, TiCC::XmlNewNode( foliaNs(), "metadata" ) ); add_annotations( md ); add_provenance( md ); diff --git a/src/folia_utils.cxx b/src/folia_utils.cxx index b7958cf..7b49529 100644 --- a/src/folia_utils.cxx +++ b/src/folia_utils.cxx @@ -416,17 +416,23 @@ namespace folia { return atts; } - void addAttributes( const xmlNode *_node, const KWargs& atts ){ + void addAttributes( const xmlNode *_node, + const KWargs& atts, + bool debug ){ /// add all attributes from 'atts' as attribute nodes to 'node` /*! \param _node The xmlNode to add to \param atts The list of attribute/value pairs + \param debug do we want to debug? (default false) some special care is taken for attributes 'xml:id', 'id' and 'lang' */ xmlNode *node = const_cast(_node); // strange libxml2 interface KWargs attribs = atts; auto it = attribs.find("xml:id"); if ( it != attribs.end() ){ // xml:id is special + if ( debug ){ + cerr << "set xml:id " << it->second << endl; + } xmlSetProp( node, XML_XML_ID, to_xmlChar(it->second) ); @@ -434,12 +440,18 @@ namespace folia { } it = attribs.find("lang"); if ( it != attribs.end() ){ // lang is special too + if ( debug ){ + cerr << "set lang " << it->second << endl; + } xmlNodeSetLang( node, to_xmlChar(it->second) ); attribs.erase(it); } it = attribs.find("id"); if ( it != attribs.end() ){ + if ( debug ){ + cerr << "set id " << it->second << endl; + } xmlSetProp( node, to_xmlChar("id"), to_xmlChar(it->second) ); @@ -447,6 +459,9 @@ namespace folia { } // and now the rest for ( const auto& [at,val] : attribs ){ + if ( debug ){ + cerr << "add attribute: [" << at << "," << val << "]" << endl; + } xmlSetProp( node, to_xmlChar(at), to_xmlChar(val) );