コード例 #1
0
bool XmlDocument::R7eChildElements(sPtr parent, std::string newChildName, std::string newChildText, std::vector<std::string> newChildAttributes)
{
	bool result = false;
	if ((parent != NULL) && (!parent->isSelfClose()))
	{
		sPtr newChild = makeTaggedElement(newChildName);
		if (!newChildText.empty())
			newChild->addChild(makeTextElement(newChildText));
		if (!newChildAttributes.empty())
		{
			for (size_t i = 0; i < newChildAttributes.size(); i += 2)
			{
				newChild->addAttrib(newChildAttributes[i], newChildAttributes[i + 1]);
			}
		}
		cout << "\n child for root element" << newChild->toString() << endl;
		cout << "parent's number of children before adding new child... " << parent->children().size() << endl;

		parent->addChild(newChild);
		cout << "after adding new child...\n " << parent->toString() << endl;
		cout << "parent's number of children before adding new child... " << parent->children().size() << endl;
		result = true;
	}
	return result;
}
コード例 #2
0
/*
 *  if tag == "" returns pElem and all decendents
 */
bool XmlDocument::find(const std::string& tag, sPtr pElem, bool findall)
{
  if (pElem->tag() == tag || tag == "")
  {
    found_.push_back(pElem);
    if (!findall)
      return true;
  }
  for (auto pChild : pElem->children())
    find(tag, pChild);
  return (found_.size() > 0);
}
コード例 #3
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_;
}
コード例 #4
0
//Convert pointer to package information
PackageDetails Repository::convertsPtrToPackageDetails(sPtr result, string packageName) {
	PackageDetails package;
	if (result != nullptr) {
		if (result->tag() == "Version") {
			package.package() = packageName;
			package.version() = result->getAttrib("Name");
			package.path() = result->getAttrib("Directory");
			package.status() = result->getAttrib("Status");
			return package;
		}
	}
	return package;
}
コード例 #5
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;
}
コード例 #6
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_;
}
コード例 #7
0
void Display::disElemIDInfo(sPtr tempPtr)
{	
	if (tempPtr != nullptr)
		std::cout << "\n" << "The given id is present in the " << tempPtr->value() << " tag" << "\n";
	else
		printStatement("The given id is not present the XML Tree");
}
コード例 #8
0
std::vector<sPtr> XmlDocument::R8b(sPtr element)
{
	std::vector<sPtr> children;
	children.empty();
	if (element != NULL)
	{
		children = element->children();
	}
	return children;
}
コード例 #9
0
std::vector<std::pair<std::string, std::string>> XmlDocument::R8a(sPtr element)
{
	std::vector<std::pair<std::string, std::string>> attributes;
	attributes.empty();
	if (element != NULL)
	{
		attributes = element->attributes();
	}
	return attributes;
}
コード例 #10
0
// ---------------< create xml element for file and its dependencies >-------------
sPtr ClientHandler::makeFileElement(sPtr pRoot, std::string package, std::string filename, std::vector<std::string> deps) {
	sPtr file = makeTaggedElement("file");
	file->addChild(makeTextElement(filename));
	sPtr depNames = makeTaggedElement("deps");
	for (auto depName : deps) {
		sPtr dep = makeTaggedElement("dep");
		dep->addChild(makeTextElement(depName));
		depNames->addChild(dep);
	}
	file->addChild(depNames);
	pRoot->addChild(file);
	return pRoot;
}
コード例 #11
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;
        }
    }
}