camcom 1.0.3
 
Loading...
Searching...
No Matches
xml_parser.cpp File Reference

GenICam XML parser implementation using Xerces-C. More...

#include "camcom/genicam/xml_parser.hpp"
#include "ifw/fnd/defs/base.hpp"
#include <xercesc/dom/DOM.hpp>
#include <xercesc/framework/MemBufInputSource.hpp>
#include <xercesc/framework/MemBufFormatTarget.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/sax/ErrorHandler.hpp>
#include <xercesc/sax/SAXParseException.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLString.hpp>
#include <fstream>
#include <sstream>
#include <memory>
#include <string>

Namespaces

namespace  camcom
 
namespace  camcom::genicam
 

Detailed Description

GenICam XML parser implementation using Xerces-C.

Note
History: this parser started on a vendored pugixml, moved to the system libxml2 (EICSSW-3395), and now uses Xerces-C. Xerces is the XML library already used elsewhere in the ELT CS (RAD, lsv/mirror-common); standardising on it avoids adding a third XML stack that the whole CS would have to carry. See EICSSW-3395.

Xerces-C notes:

  • Xerces is namespace-aware. The GenICam XML declares a default xmlns, so elements are matched by LOCAL name (getLocalName(), ignoring the namespace) to preserve the original pugixml behaviour. Note that getLocalName() is only populated when the parser is put in namespace-aware mode; otherwise it is null and getNodeName() must be used. localName() below handles both cases.
  • The DOM child list includes text/whitespace nodes; we iterate only ELEMENT_NODEs.
  • Xerces uses UTF-16 (XMLCh) throughout. Transcoding to/from local 8-bit strings goes through XMLString::transcode(), which returns heap buffers that must be released — the XStr/CStr RAII helpers below own that.
  • XMLPlatformUtils::Initialize()/Terminate() must bracket all Xerces use. A function-local static (see xercesPlatform()) does this once per process in a thread-safe way; we deliberately never call Terminate(), since other libraries in the process may still be using Xerces.
  • Parse errors: the default ErrorHandler prints to stderr and continues. SilentErrorHandler below swallows them so malformed input is reported via FNDERROR instead, matching the previous behaviour.