コード例 #1
0
// searches for the proc instruction elements in the document
std::vector<XmlDocument::sPtr> XmlDocument::Proc_Search(sPtr pnode, std::string tag_)
{
    DocElement* docptr = dynamic_cast<DocElement*>(pnode.get());
    TaggedElement* taggedptr = dynamic_cast<TaggedElement*>(pnode.get());
    if (docptr != nullptr)
    {
        for (auto docchild : docptr->children())
        {
            ProcInstrElement* procptr = check_proc_type(docchild);
            XmlDeclarElement *declarptr = check_declaration_type(docchild);
            TaggedElement* taggedptr = check_Tagged_type(docchild);
            CommentElement *commptr = check_comment_type(docchild);
            if (commptr != nullptr)
                continue;
            else if (procptr != nullptr)
            {
                if (tag_.compare(procptr->toString()))
                    found_.push_back(docchild);
            }
            else if (declarptr != nullptr)
                continue;
            else if (taggedptr != nullptr)
                Proc_Search(root, tag_);
            else
                return found_;
        }
    }

    if (taggedptr != nullptr)
    {
        for (auto pchild : taggedptr->children())
        {
            ProcInstrElement* procptr = check_proc_type(pchild);
            TaggedElement* taggedptr = check_Tagged_type(pchild);
            CommentElement *commptr = check_comment_type(pchild);
            TextElement *textptr = check_text_type(pchild);
            if (procptr != nullptr)
            {
                if(tag_== procptr->toString())
                    found_.push_back(pchild);
                continue;
            }
            if (commptr != nullptr)
                continue;
            if (textptr != nullptr)
                continue;
            if (taggedptr != nullptr)
                Proc_Search(pchild, tag_);
        }
    }
    return found_;
}
コード例 #2
0
//searches for the name and value pair from the root element and returns the corresponding elements
XmlDocument::sPtr XmlDocument::Attribute_search(sPtr pNode, std::string attribute_id, std::string value)
{
    TaggedElement* taggedptr = dynamic_cast<TaggedElement*>(pNode.get());
    ProcInstrElement* procptr = dynamic_cast<ProcInstrElement*>(pNode.get());
    if ((taggedptr != nullptr))
    {
        if (taggedptr->children().size() == 0)
        {
            std::vector<std::pair<std::string, std::string>>& attri_ = taggedptr->attributes();
            for (int i = 0; i < attri_.size(); i++)
            {
                if ((attri_[i].first == attribute_id) && (attri_[i].second == value))
                    return pNode;
            }
            return nullptr;
        }
        for (auto pChild : taggedptr->children())
        {
            std::vector<std::pair<std::string, std::string>>& attri_ = taggedptr->attributes();
            for (int i = 0; i < attri_.size(); i++)
            {
                if ((attri_[i].first == attribute_id) && (attri_[i].second == value))
                {
                    found_.push_back(pNode);
                    return pNode;
                }
            }
            TextElement* checkchildtextPtr = check_text_type(pChild);
            CommentElement* checkcommenttextPtr = check_comment_type(pChild);
            if (checkchildtextPtr != nullptr)
                continue;
            if (checkcommenttextPtr != nullptr)
                continue;
            sPtr temp = Attribute_search(pChild, attribute_id, value);
            if (temp != nullptr)
                found_.push_back(temp);
        }
        return nullptr;
    }
    if (procptr != nullptr)
    {
        std::vector<std::pair<std::string, std::string>>& attri_ = procptr->attributes();
        for (int i = 0; i < attri_.size(); i++)
        {
            if ((attri_[i].first == attribute_id) && (attri_[i].second == value))
                return pNode;
        }
        return nullptr;
    }
    return nullptr;
}
コード例 #3
0
// Performs tag serach from the doc element and returns all the elements with the matching tag.
std::vector<XmlDocument::sPtr> XmlDocument::Tag_Search(sPtr pnode, std::string tag_)
{
    DocElement* docptr = dynamic_cast<DocElement*>(pnode.get());
    TaggedElement* taggedptr = dynamic_cast<TaggedElement*>(pnode.get());
    if (docptr != nullptr)
    {
        for (auto docchild : docptr->children())
        {
            ProcInstrElement* procptr = check_proc_type(docchild);
            XmlDeclarElement *declarptr = check_declaration_type(docchild);
            TaggedElement* taggedptr = check_Tagged_type(docchild);
            CommentElement *commptr = check_comment_type(docchild);
            if (commptr != nullptr)
            {
                continue;
            }
            else if (procptr != nullptr)
            {
                continue;
            }
            else if (declarptr != nullptr)
            {
                continue;
            }
            else if (taggedptr!=nullptr)
            {

                Tag_Search(root, tag_);

            }
            else
            {
                return found_;
            }
        }
    }

    if (taggedptr != nullptr)
    {
        if (taggedptr->value() == tag_)
            found_.push_back(pnode);
        for (auto pchild : taggedptr->children())
        {
            Tag_Search(pchild, tag_);
        }
    }
    return found_;
}
コード例 #4
0
//given an attribute name and value, it searches for the corresponding element from the doc element.
//this calls the arribute_search function which searches the name and value pair from the root
XmlDocument::sPtr XmlDocument::doc_Attribute_search(sPtr pNode, std::string attribute_id, std::string value)
{
    DocElement *docptr = dynamic_cast<DocElement*>(pNode.get());
    for (auto docchild : docptr->children())
    {
        ProcInstrElement* procptr = check_proc_type(docchild);
        XmlDeclarElement *declarptr = check_declaration_type(docchild);
        TaggedElement* taggedptr = check_Tagged_type(docchild);
        CommentElement *commptr = check_comment_type(docchild);
        if (commptr!=nullptr)
        {
            continue;
        }
        if (procptr!=nullptr)
        {
            std::vector<std::pair<std::string, std::string>>& attri_ = procptr->attributes();
            for (int i = 0; i < attri_.size(); i++)
            {
                if ((attri_[i].first == attribute_id) && (attri_[i].second == value))
                {
                    found_.push_back(docchild);
                    return pNode;
                }
            }
        }
        if (declarptr!=nullptr)
        {
            std::vector<std::pair<std::string, std::string>>& attri_ = declarptr->attributes();
            for (int i = 0; i < attri_.size(); i++)
            {
                if ((attri_[i].first == attribute_id) && (attri_[i].second == value))
                {
                    found_.push_back(docchild);
                    return pNode;
                }
            }
        }
        if (taggedptr!=nullptr)
        {
            sPtr tagged = Attribute_search( docchild, attribute_id, value);
            return tagged;
        }
    }
}