Beispiel #1
0
void Executive::executeCommands(ConfigParseToConsole configure)
{
	//demonstrating each requirment one by one
	Display dp;
	XmlProcessing::XmlDocument doc(configure.getRepository()->getRoot());
	std::cout << "\n""\n""\n" << std::string(150, '=');
	std::cout << "\n" << "Demonstarting Requirement 3 and 10 by parsing and thereby writing an XML File/String to corresponding Tree representation";
	std::cout << "\n" << std::string(150, '=');
	dp.displayToConsole(configure.getRepository()->getRoot(), true);
	dp.writeToOutputXML(configure.getRepository()->getRoot(), true);
	//Execute Functions:If TA supplies any new XML then he can make neccesary changes 
	demonstrateAddRoot(dp, doc, "NewRoot");
	demonstrateFindByTag(dp, doc, "title");
	demonstrateFindByTag(dp, doc, "HelloWorld");
	demonstrateFindByNameValue(dp, doc, "tagName", "Tester");
	demonstrateFindByNameValue(dp, doc, "InvalidName", "InvalidValue");
	demonstrateShowAttribute(dp, doc, "LectureNote");
	demonstrateShowChildren(dp, doc, "LectureNote");
	demonstrateAddAttribute(dp, doc, "title", "name", "ojas");
	demonstrateAddChild(dp, doc, "LectureNote", "comment");
	demonstrateAddChild(dp, doc, "LectureNote", "tag");
	demonstrateAddChild(dp, doc, "LectureNote", "text");
	demonstrateRemoveAttribute(dp, doc, "GreatChildTestTag", "tagName", "Tester");
	demonstrateRemoveChild(dp, doc, "author", "TestTag");
	doc.findById("").removeChild("LectureNote"); //removing the root from the docElement so that addRoot Functionality can be tested
	demonstrateAddRoot(dp, doc, "NewRoot");
	demonstrateMoveOperation(dp, doc);

}
Beispiel #2
0
void executeForString()
{
	//build parser
	ConfigParseToConsole configure;
	Parser* pParser = configure.Build();
	std::string string = makeString();
	if (pParser)
	{
		bool flag = configure.Attach(string, false);
		if (!flag)
		{
			std::cout << "\n  could not open file " << string << std::endl;
			return;
		}
	}

	else
	{
		std::cout << "\n\n  Parser not built\n\n";
		return;
	}
	// now that parser is built, use it
	Executive exec(configure.getRepository()->getRoot());
	while (pParser->next())
		pParser->parse();
	exec.executeCommands(configure);
}
Beispiel #3
0
int main(int argc, char* argv[])
{
	std::cout << "\n  Testing Parser class\n "
		<< std::string(22, '=') << std::endl;

	if (argc < 2)
	{
		std::cout
			<< "\n  please enter name of file to process on command line\n\n";
		return 1;
	}

	for (int i = 1; i<argc; ++i)
	{
		std::cout << "\n  Processing file " << argv[i];
		std::cout << "\n  " << std::string(16 + strlen(argv[i]), '-');
		// build parser
		ConfigParseToConsole configure;
		Parser* pParser = configure.Build();
		try
		{
			if (pParser)
			{
				if (!configure.Attach(argv[i]))
				{
					std::cout << "\n  could not open file " << argv[i] << std::endl;
					continue;
				}
			}
			else
			{
				std::cout << "\n\n  Parser not built\n\n";
				return 1;
			}
			// now that parser is built, use it

			while (pParser->next())
				pParser->parse();
			std::cout << "\n\n" << configure.getRepository()->getRoot()->toString();
		}
		catch (std::exception& ex)
		{
			std::cout << "\n\n    " << ex.what() << "\n\n";
		}
		std::cout << "\n\n";
	}
}
int main(int argc, char *argv[])
{
	title("Testing XmlDocument class");
	std::vector<std::pair<std::string, std::string>> vectorAttributePair;
	std::vector<std::shared_ptr<AbstractXmlElement>> vectorSharedPtr;
	// build parser first
	ConfigParseToConsole configure;
	Parser* pParser = configure.Build();
	configure.Attach(argv[1]);
	// now that parser is built, use it
	while (pParser->next())
		pParser->parse();
	std::shared_ptr < AbstractXmlElement > pDocElement;
	XmlProcessing::XmlDocument doc(configure.getRepository()->getRoot());
	pDocElement = doc.getRoot();
	//test and then display each method one by one 
	vectorSharedPtr = doc.findByNameAndValue("course","CSE681").select();
	std::cout << "\n\n" << "Displaying Functionality of Method:'findByNameAndValue' and Method:'select'" << "\n";
	std::cout << "\n\n" << "Query is:Find Collection of Elements with Name-Value Pair: 'course = CSE681'" << "\n" << "XML Portion found with specified ID is:";
	for (auto elem : vectorSharedPtr)
	{
		std::cout << "\n" << elem->toString() << "\n" << std::string(60, '-');
	}
	//On using the function select found Vector is moved
	vectorSharedPtr = doc.findById("LectureNote").select();
	std::cout << "\n\n" << "Displaying Functionality of Method:'findById' and Method: 'select'" << "\n";
	std::cout << "\n\n" << "Query is:Find Collection of Elements with tag: LectureNote"<<"\n"<<"XML Portion found with specified ID is:";
	for (auto elem : vectorSharedPtr)
	{
		std::cout << "\n" << elem->toString() << "\n" << std::string(60, '-');
	}

	std::cout << "\n\n" << "Displaying Functionality of Method:'addAttribute'" << "\n";
	std::cout << "\n\n" << "Query is: Add attribute with Name-Value: 'name = ojas' in tag: author" << "\n" << "Modified XML is:";
	doc.findById("author").addAttribute("name","ojas");
	std::cout << "\n\n" << pDocElement->toString() << "\n"<<std::string(60, '-');

	std::cout << "\n\n" << "Displaying Functionality of Method:'removeAttribute'" << "\n";
	std::cout << "\n\n" << "Query is: remove attribute with Name-Value: 'name = ojas' in tag: author" << "\n" << "Modified XML is:";
	doc.findById("author").removeAttribute("name", "ojas");
	std::cout << "\n\n" << pDocElement->toString() << "\n" << std::string(60, '-');

	std::cout << "\n\n" << "Displaying Functionality of Method:'addChild'" << "\n";
	std::cout << "\n\n" << "Query is: Add child with tag: 'children' in parent tag: author" << "\n" << "Modified XML is:";
	std::shared_ptr < AbstractXmlElement > sharedPtr = makeTaggedElement("children");
	doc.findById("author").addChild(sharedPtr);
	std::cout << "\n\n" << pDocElement->toString() << "\n" << std::string(60, '-');

	std::cout << "\n\n" << "Displaying Functionality of Method:'removeChild'" << "\n";
	std::cout << "\n\n" << "Query is: Remove child with tag: 'children' in parent tag: author" << "\n" << "Modified XML is:";
	doc.findById("author").removeChild("children");
	std::cout << "\n\n" << pDocElement->toString() <<"\n"<< std::string(60, '-');

	std::cout << "\n\n" << "Displaying Functionality of Method:'getAttributePairVector'" << "\n";
	std::cout << "\n\n" << "Query is: get attributePair by giving pointer to the element of Tag: LectureNote";
	vectorAttributePair = doc.getAttributePairVector(vectorSharedPtr[0]);
	std::cout << "\n""\n" << "Following Name-Value Attribute Pair Found:"<< "\n";
	for (auto elem : vectorAttributePair)
	{
		std::cout << elem.first.c_str() << " = " << elem.second.c_str() << "\n";
	}
	std::cout << std::string(60, '-');


	std::cout << "\n\n" << "Displaying Functionality of Method:'getChildrenVector'" << "\n";
	std::cout << "\n\n" << "Query is: get childrens by giving pointer to the element of Tag: LectureNote";
	for (auto elem : doc.getChildrenVector(vectorSharedPtr[0]))
	{
		std::cout << elem->value()  << "\n";
	}
	std::cout<<std::string(60, '-');

	std::cout << "\n\n" << "Displaying Functionality of Method:'addRoot'" << "\n";
	std::cout << "\n\n" << "Query is: adding root after deleting all the childs"<<"\n"<<"New Root Formed with Tagged element: 'newchild' is:";
	doc.findById("").removeChild("LectureNote");
	doc.findById("").removeChild("xml declaration");
	doc.findById("").removeChild("xml declaration");
	doc.findById("").removeChild("XML test case");
	doc.addRoot("newchild");
	std::cout << "\n\n" << doc.getRoot()->toString() <<"\n"<< std::string(60, '-');

	return 0;
	
}