FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
libxml_wrapper.cpp File Reference

Wrapper for managing XML documents and elements using libxml2. More...

#include "libxml_wrapper.h"
#include <cctype>
#include <cstdarg>
#include <format>
#include <string>
#include "libxml/encoding.h"
#include "libxml/parser.h"
#include "libxml/valid.h"
#include "libxml/xmlIO.h"
#include "libxml/xmlerror.h"
#include "libxml/xmlschemas.h"
+ Include dependency graph for libxml_wrapper.cpp:

Go to the source code of this file.

Functions

void mergeXmlDocuments (const XmlDocument &mainDoc, const XmlDocument &includedDoc)
 Merge two XML documents.
 
void removeIncludeElements (const XmlDocument &doc)
 Remove "include" elements from the XML document.
 

Detailed Description

Wrapper for managing XML documents and elements using libxml2.

Definition in file libxml_wrapper.cpp.

Function Documentation

◆ mergeXmlDocuments()

void mergeXmlDocuments ( const XmlDocument mainDoc,
const XmlDocument includedDoc 
)

Merge two XML documents.

Parameters
mainDocThe main XML document.
includedDocThe XML document to include.

Definition at line 185 of file libxml_wrapper.cpp.

186{
187 const XmlElement main_root = mainDoc.getRootElement();
188 const XmlElement included_root = includedDoc.getRootElement();
189
190 for (xmlNodePtr child = included_root.getNode()->children; child != nullptr; child = child->next)
191 {
192 if (child->type == XML_ELEMENT_NODE)
193 {
194 xmlNodePtr new_node = xmlCopyNode(child, 1);
195 xmlAddChild(main_root.getNode(), new_node);
196 }
197 }
198}
XmlElement getRootElement() const
Get the root element of the document.
Class representing a node in an XML document.
xmlNodePtr getNode() const noexcept
Get the underlying XML node pointer.

References XmlElement::getNode(), and XmlDocument::getRootElement().

Referenced by serial::xml_parser_utils::addIncludeFilesToMainDocument().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeIncludeElements()

void removeIncludeElements ( const XmlDocument doc)

Remove "include" elements from the XML document.

Parameters
docThe XML document from which to remove the "include" elements.

Definition at line 200 of file libxml_wrapper.cpp.

201{
202 const XmlElement root = doc.getRootElement();
203
204 while (true)
205 {
206 if (XmlElement include_element = root.childElement("include", 0); include_element.isValid())
207 {
208 xmlUnlinkNode(include_element.getNode());
209 xmlFreeNode(include_element.getNode());
210 }
211 else
212 {
213 break;
214 }
215 }
216}
XmlElement childElement(const std::string_view name="", const unsigned index=0) const noexcept
Retrieve a child element by name and index.

References XmlElement::childElement(), and XmlDocument::getRootElement().

Referenced by serial::xml_parser_utils::addIncludeFilesToMainDocument().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: