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

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

#include <iostream>
#include <libxml/parser.h>
#include <memory>
#include <span>
#include <stdexcept>
#include <string>
#include <string_view>
#include "core/logging.h"
#include "libxml/globals.h"
#include "libxml/xmlstring.h"
+ Include dependency graph for libxml_wrapper.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  XmlException
 Exception class for handling XML-related errors. More...
 
class  XmlElement
 Class representing a node in an XML document. More...
 
class  XmlDocument
 Class for managing XML documents. More...
 

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.

This header file provides classes and functions to simplify handling XML documents and elements using the libxml2 library. It includes basic functionality for manipulating XML nodes, attributes, content, and validation using DTD and XSD schemas.

Definition in file libxml_wrapper.h.

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 83 of file libxml_wrapper.cpp.

84{
85 const XmlElement main_root = mainDoc.getRootElement();
86 const XmlElement included_root = includedDoc.getRootElement();
87
88 for (xmlNodePtr child = included_root.getNode()->children; child; child = child->next)
89 {
90 if (child->type == XML_ELEMENT_NODE)
91 {
92 xmlNodePtr new_node = xmlCopyNode(child, 1);
93 xmlAddChild(main_root.getNode(), new_node);
94 }
95 }
96}
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().

+ Here is the call 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 98 of file libxml_wrapper.cpp.

99{
100 const XmlElement root = doc.getRootElement();
101
102 while (true)
103 {
104 if (XmlElement include_element = root.childElement("include", 0); include_element.isValid())
105 {
106 xmlUnlinkNode(include_element.getNode());
107 xmlFreeNode(include_element.getNode());
108 }
109 else
110 {
111 break;
112 }
113 }
114}
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().

+ Here is the call graph for this function: