Exemplo n.º 1
0
int main(int argc, char** argv)
{
	// parse an XML document and print the generated SAX events

	if (argc < 2)
	{
		std::cout << "usage: " << argv[0] << ": <xmlfile>" << std::endl;
		return 1;
	}
	
	MyHandler handler;

	SAXParser parser;
	parser.setFeature(XMLReader::FEATURE_NAMESPACES, true);
	parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, true);
	parser.setContentHandler(&handler);
	parser.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast<LexicalHandler*>(&handler));
	
	try
	{
		parser.parse(argv[1]);
	}
	catch (Poco::Exception& e)
	{
		std::cerr << e.displayText() << std::endl;
		return 2;
	}
	
	return 0;
}
Exemplo n.º 2
0
void SAXParserTest::testNamespacesNoPrefixes()
{
	SAXParser parser;
	parser.setFeature(XMLReader::FEATURE_NAMESPACES, true);
	parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, false);
	std::string xml = parse(parser, XMLWriter::CANONICAL, NAMESPACES);
	assert (xml == NAMESPACES);
}
Exemplo n.º 3
0
void SAXParserTest::testUndeclaredNamespaceNoPrefixes()
{
	SAXParser parser;
	parser.setFeature(XMLReader::FEATURE_NAMESPACES, true);
	parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, false);
	try
	{
		std::string xml = parse(parser, XMLWriter::CANONICAL, UNDECLARED_NAMESPACE);
		fail("undeclared namespace - must throw exception");
	}
	catch (SAXParseException&)
	{
	}
}
Exemplo n.º 4
0
			void PSAPAddrTest::setUp() {
#if 0
//
// Macros are defined for now by the Macro constructor
//
				AEISAXHandler handler;
				SAXParser parser;

				parser.setFeature(XMLReader::FEATURE_NAMESPACES, true);
				parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, true);
				parser.setContentHandler(&handler);
				parser.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER,	static_cast<LexicalHandler*>(&handler));

				parser.parse("../../../../../../test/iso/itu/osi/als/base/addr/Macros.xml");
#endif
			}
Exemplo n.º 5
0
void SAXParserTest::testUndeclaredNoNamespace()
{
	SAXParser parser;
	parser.setFeature(XMLReader::FEATURE_NAMESPACES, false);
	std::string xml = parse(parser, XMLWriter::CANONICAL, UNDECLARED_NAMESPACE);
	assert (xml == UNDECLARED_NAMESPACE);
}
Exemplo n.º 6
0
int main (int argc, char** argv) {
	if (false) {
		RFC_1006 rfc1006;
		NSAPAddr nsap;
		const char* n = rfc1006.parse(nsap, "+03+10.0.0.6:8080");
		const char*p;
		Selector selector;
		p = selector.parse("////NS+a433bb93c1");
		p = selector.parse("#124/NS");
		p = selector.parse("\"abc\"/NS");
		p = selector.parse("'3a'H/NS");

		string sel = "#124";
		TSAPService		service("echo", "#124", "pippo",  "bar");
		TSAPServices	services;
		services.add("echo", "#12", "pippo", "bar");
		const OSIService* os = services.getServiceBySelector(selector);
		if (os != NULL) {
			os->entity();
		}
	}
	{
		AEISAXHandler handler;
		SAXParser parser;

		parser.setFeature(XMLReader::FEATURE_NAMESPACES, true);
		parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, true);
		parser.setContentHandler(&handler);
		parser.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER,	static_cast<LexicalHandler*>(&handler));

		try	{
			parser.parse("AEI.xml");
			ServiceFunctor functor(cout);
			//TSAP_SERVICES.print(functor);
			//SSAP_SERVICES.print(functor);
			//PSAP_SERVICES.print(functor);

			const OSIService* service = TSAP_SERVICES.getServiceByEntity("ssap");
			cout << service->mangled() << endl;

		} catch (Poco::Exception& e)	{
			std::cerr << e.displayText() << std::endl;
		}
	}

#if 0
	<config>
Exemplo n.º 7
0
void SAXParserTest::testCharacters()
{
	static const XMLString xml("<textnode> TEXT &amp; AMPERSAND </textnode>");
	SAXParser parser;
	parser.setFeature(XMLReader::FEATURE_NAMESPACES, false);
	std::string result = parse(parser, XMLWriter::CANONICAL, xml);
	assert (result == xml);
}
Exemplo n.º 8
0
void SAXParserTest::testRSS()
{
	SAXParser parser;
	WhitespaceFilter filter(&parser);
	TestEntityResolver resolver;
	filter.setEntityResolver(&resolver);
	parser.setFeature(XMLReader::FEATURE_EXTERNAL_GENERAL_ENTITIES, true);
	parser.setFeature(XMLReader::FEATURE_EXTERNAL_PARAMETER_ENTITIES, true);
	
	std::istringstream istr(RSS);
	Poco::FileOutputStream ostr("rss.xml");
	XMLWriter writer(ostr, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT);
	filter.setContentHandler(&writer);
	filter.setDTDHandler(&writer);
	filter.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast<Poco::XML::LexicalHandler*>(&writer));
	InputSource source(istr);
	filter.parse(&source);
}
Exemplo n.º 9
0
void SAXParserTest::testExternalParsed()
{
	SAXParser parser;
	TestEntityResolver resolver;
	parser.setEntityResolver(&resolver);
	parser.setFeature(XMLReader::FEATURE_EXTERNAL_GENERAL_ENTITIES, true);
	std::string xml = parse(parser, XMLWriter::CANONICAL, EXTERNAL_PARSED);
	assert (xml == "<!DOCTYPE test><sample>\n\t<elem>\n\tAn external entity.\n</elem>\n\n</sample>");
}
Exemplo n.º 10
0
void AreFriends::handleResponse(istream & inputstream) const
{
	SAXParser parser;
	parser.setFeature(XMLReader::FEATURE_NAMESPACES, true);
	parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, true);
	parser.setContentHandler(const_cast<AreFriends*>(this));
	
	try
	{
		SharedPtr<InputSource> inputSource(new InputSource(inputstream));
		parser.parse(inputSource);
		mSuccessCallback.call(mFriendInfoList);
	}
	catch (Exception& e)
	{
		cerr << e.displayText() << endl;
		mErrorCallback.call(ErrorResponse(0,e.message(), KeyValue()));
	}
}