src/libtsduck/base/xml/tsxmlJSONConverter.cpp
//----------------------------------------------------------------------------
// Convert an XML document into a JSON object.
//----------------------------------------------------------------------------
Convert an XML document into a JSON object.
Convert an XML document into a JSON object .
ts::json::ValuePtr ts::xml::JSONConverter::convert(const Document& source, bool force_root) const
{
    const xml::Element* docRoot = source.rootElement();
    if (docRoot == nullptr) {
        report().error(u"invalid XML document, no root element");
        return json::ValuePtr();
    }
    else {
        const Element* modelRoot = rootElement();
        if (modelRoot != nullptr && !modelRoot->name().similar(docRoot->name())) {
            modelRoot = nullptr;
        }
        if (_args.include_root || force_root) {
            return convertElement(modelRoot, docRoot);
        }
        else {
            return convertChildren(modelRoot, docRoot);
        }
    }
}
ts :: json :: ValuePtr ts :: xml :: JSONConverter :: convert ( const Document & source , bool force_root ) const { const xml :: Element * docRoot = source . rootElement ( ) ; if ( docRoot == nullptr ) { report ( ) . error ( u" " ) ; return json :: ValuePtr ( ) ; } else { const Element * modelRoot = rootElement ( ) ; if ( modelRoot != nullptr && ! modelRoot -> name ( ) . similar ( docRoot -> name ( ) ) ) { modelRoot = nullptr ; } if ( _args . include_root || force_root ) { return convertElement ( modelRoot , docRoot ) ; } else { return convertChildren ( modelRoot , docRoot ) ; } } }
Convert an XML document into a JSON object.
Convert an XML document into a JSON object .
// Ignore the model if the model root has a different name from the source root. // Convert the source. Use no model if not the same as source. // Return a JSON object containing the root. // Return a JSON array of all top-level elements in the root.