src/libtsduck/base/xml/tsxmlJSONConverter.cpp
//----------------------------------------------------------------------------
// Convert all children of an element as a JSON array.
//----------------------------------------------------------------------------
Convert all children of an element as a JSON array.
Convert all children of an element as a JSON array .
ts::json::ValuePtr ts::xml::JSONConverter::convertChildren(const Element* model, const Element* parent) const
{
    json::ValuePtr jchildren(new json::Array());
    CheckNonNull(jchildren.pointer());
    UString textModel;
    bool getTextModel = model != nullptr;
    bool hexaModel = false;
    bool lastNode = false;
    for (const Node* child = parent->firstChild(); child != nullptr && !lastNode; child = child->nextSibling()) {
        lastNode = child == parent->lastChild();
        const Element* elem = dynamic_cast<const Element*>(child);
        const Text* text = dynamic_cast<const Text*>(child);
        if (elem != nullptr) {
            jchildren->set(convertElement(findModelElement(model, elem->name()), elem));
        }
        else if (text != nullptr) {
            UString content(text->value());
            if (getTextModel) {
                getTextModel = false;
                model->getText(textModel, true);
                hexaModel = textModel.startWith(u"hexa", CASE_INSENSITIVE);
            }
            content.trim(hexaModel || _args.trim_text, hexaModel || _args.trim_text, hexaModel || _args.collapse_text);
            jchildren->set(content);
        }
    }
    return jchildren;
}
ts :: json :: ValuePtr ts :: xml :: JSONConverter :: convertChildren ( const Element * model , const Element * parent ) const { json :: ValuePtr jchildren ( new json :: Array ( ) ) ; CheckNonNull ( jchildren . pointer ( ) ) ; UString textModel ; bool getTextModel = model != nullptr ; bool hexaModel = false ; bool lastNode = false ; for ( const Node * child = parent -> firstChild ( ) ; child != nullptr && ! lastNode ; child = child -> nextSibling ( ) ) { lastNode = child == parent -> lastChild ( ) ; const Element * elem = dynamic_cast < const Element * > ( child ) ; const Text * text = dynamic_cast < const Text * > ( child ) ; if ( elem != nullptr ) { jchildren -> set ( convertElement ( findModelElement ( model , elem -> name ( ) ) , elem ) ) ; } else if ( text != nullptr ) { UString content ( text -> value ( ) ) ; if ( getTextModel ) { getTextModel = false ; model -> getText ( textModel , true ) ; hexaModel = textModel . startWith ( u" " , CASE_INSENSITIVE ) ; } content . trim ( hexaModel || _args . trim_text , hexaModel || _args . trim_text , hexaModel || _args . collapse_text ) ; jchildren -> set ( content ) ; } } return jchildren ; }
Convert all children of an element as a JSON array.
Convert all children of an element as a JSON array .
// All JSON children are placed in an array. // Content of the text children in the model. // Loop on all children nodes. // Interpret the child either as an Element or a Text node. // Other types of nodes are ignored. // Convert an element. Add a JSON child object in the array of JSON children. // Convert a text. // Get the model description once only. // Trim the text content according to model and command line options. // Add a JSON string for the text node in the array of JSON children.