📄 saxparsertest.cpp
字号:
reader.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast<XML::LexicalHandler*>(&writer));
InputSource source(istr);
reader.parse(&source);
return ostr.str();
}
CppUnit::Test* SAXParserTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SAXParserTest");
CppUnit_addTest(pSuite, SAXParserTest, testSimple1);
CppUnit_addTest(pSuite, SAXParserTest, testSimple2);
CppUnit_addTest(pSuite, SAXParserTest, testAttributes);
CppUnit_addTest(pSuite, SAXParserTest, testCDATA);
CppUnit_addTest(pSuite, SAXParserTest, testComment);
CppUnit_addTest(pSuite, SAXParserTest, testPI);
CppUnit_addTest(pSuite, SAXParserTest, testDTD);
CppUnit_addTest(pSuite, SAXParserTest, testInternalEntity);
CppUnit_addTest(pSuite, SAXParserTest, testNotation);
CppUnit_addTest(pSuite, SAXParserTest, testExternalUnparsed);
CppUnit_addTest(pSuite, SAXParserTest, testExternalParsed);
CppUnit_addTest(pSuite, SAXParserTest, testDefaultNamespace);
CppUnit_addTest(pSuite, SAXParserTest, testNamespaces);
CppUnit_addTest(pSuite, SAXParserTest, testNamespacesNoPrefixes);
CppUnit_addTest(pSuite, SAXParserTest, testNoNamespaces);
CppUnit_addTest(pSuite, SAXParserTest, testUndeclaredNamespace);
CppUnit_addTest(pSuite, SAXParserTest, testUndeclaredNamespaceNoPrefixes);
CppUnit_addTest(pSuite, SAXParserTest, testUndeclaredNoNamespace);
CppUnit_addTest(pSuite, SAXParserTest, testRSS);
CppUnit_addTest(pSuite, SAXParserTest, testEncoding);
return pSuite;
}
const std::string SAXParserTest::SIMPLE1 =
"<foo/>\n";
const std::string SAXParserTest::SIMPLE2 =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<foo/>\n";
const std::string SAXParserTest::ATTRIBUTES =
"<root a1=\"v1\">\n"
"\t<elem a1=\"v1\" a2=\"v2\"/>\n"
"</root>";
const std::string SAXParserTest::CDATA =
"<data>\n"
"<![CDATA[\n"
"\tThe following <tag attr=\"value\">is inside a CDATA section</tag>.\n"
"]]>\n"
"</data>";
const std::string SAXParserTest::COMMENT =
"<!--this is a comment-->"
"<root>\n"
"\t<!--another comment-->\n"
"\t<elem/>\n"
"</root>";
const std::string SAXParserTest::PROCESSING_INSTRUCTION =
"<html>\n"
"\t<head>\n"
"\t\t<?xml-stylesheet href=\"style.css\" type=\"text/css\"?>\n"
"\t\t<title>test</title>\n"
"\t</head>\n"
"\t<body>\n"
"\t\t<p>this is a test</p>\n"
"\t</body>\n"
"</html>";
const std::string SAXParserTest::DTD =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<!DOCTYPE test SYSTEM \"test.dtd\">\n"
"<foo/>";
const std::string SAXParserTest::INTERNAL_ENTITY =
"<!DOCTYPE sample [\n"
"\t<!ENTITY appinf \"Applied Informatics\">\n"
"]>\n"
"<root>\n"
"\t<company>&appinf;</company>\n"
"</root>";
const std::string SAXParserTest::NOTATION =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<!DOCTYPE test [\n"
"\t<!NOTATION mov SYSTEM \"quicktime\">\n"
"\t<!NOTATION xml PUBLIC \"-//W3C//NOTATION XML 1.0//EN\">\n"
"]>\n"
"<foo/>";
const std::string SAXParserTest::EXTERNAL_UNPARSED =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<!DOCTYPE test [\n"
"\t<!NOTATION mov SYSTEM \"quicktime\">\n"
"\t<!ENTITY movie SYSTEM \"movie.mov\" NDATA mov>\n"
"]>\n"
"<sample/>";
const std::string SAXParserTest::EXTERNAL_PARSED =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<!DOCTYPE test [\n"
"\t<!ENTITY include SYSTEM \"include.xml\">\n"
"]>\n"
"<sample>\n"
"\t&include;\n"
"</sample>\n";
const std::string SAXParserTest::INCLUDE =
"<elem>\n"
"\tAn external entity.\n"
"</elem>\n";
const std::string SAXParserTest::DEFAULT_NAMESPACE =
"<root xmlns=\"urn:ns1\">\n"
"\t<elem>data</elem>\n"
"</root>";
const std::string SAXParserTest::NAMESPACES =
"<ns1:root xmlns:ns1=\"urn:ns1\" xmlns:ns2=\"urn:ns2\">\n"
"\t<ns2:elem>data</ns2:elem>\n"
"\t<ns3:elem a1=\"v1\" ns2:a2=\"v2\" xmlns:ns3=\"urn:ns3\">\n"
"\t\tmore data\n"
"\t</ns3:elem>\n"
"</ns1:root>";
const std::string SAXParserTest::UNDECLARED_NAMESPACE =
"<ns1:root xmlns:ns1=\"urn:ns1\" xmlns:ns2=\"urn:ns2\">\n"
"\t<ns2:elem>data</ns2:elem>\n"
"\t<ns3:elem a1=\"v1\" ns2:a2=\"v2\" xmlns:ns3=\"urn:ns3\">\n"
"\t\tmore data\n"
"\t</ns3:elem>\n"
"\t<ns4:elem/>\n"
"</ns1:root>";
const std::string SAXParserTest::XHTML_LATIN1_ENTITIES =
"<!-- Portions (C) International Organization for Standardization 1986\n"
" Permission to copy in any form is granted for use with\n"
" conforming SGML systems and applications as defined in\n"
" ISO 8879, provided this notice is included in all copies.\n"
"-->\n"
"<!-- Character entity set. Typical invocation:\n"
" <!ENTITY % HTMLlat1 PUBLIC\n"
" \"-//W3C//ENTITIES Latin 1 for XHTML//EN\"\n"
" \"http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent\">\n"
" %HTMLlat1;\n"
"-->\n"
"\n"
"<!ENTITY nbsp \" \"> <!-- no-break space = non-breaking space,\n"
" U+00A0 ISOnum -->\n"
"<!ENTITY iexcl \"¡\"> <!-- inverted exclamation mark, U+00A1 ISOnum -->\n"
"<!ENTITY cent \"¢\"> <!-- cent sign, U+00A2 ISOnum -->\n"
"<!ENTITY pound \"£\"> <!-- pound sign, U+00A3 ISOnum -->\n"
"<!ENTITY curren \"¤\"> <!-- currency sign, U+00A4 ISOnum -->\n"
"<!ENTITY yen \"¥\"> <!-- yen sign = yuan sign, U+00A5 ISOnum -->\n"
"<!ENTITY brvbar \"¦\"> <!-- broken bar = broken vertical bar,\n"
" U+00A6 ISOnum -->\n"
"<!ENTITY sect \"§\"> <!-- section sign, U+00A7 ISOnum -->\n"
"<!ENTITY uml \"¨\"> <!-- diaeresis = spacing diaeresis,\n"
" U+00A8 ISOdia -->\n"
"<!ENTITY copy \"©\"> <!-- copyright sign, U+00A9 ISOnum -->\n"
"<!ENTITY ordf \"ª\"> <!-- feminine ordinal indicator, U+00AA ISOnum -->\n"
"<!ENTITY laquo \"«\"> <!-- left-pointing double angle quotation mark\n"
" = left pointing guillemet, U+00AB ISOnum -->\n"
"<!ENTITY not \"¬\"> <!-- not sign = angled dash,\n"
" U+00AC ISOnum -->\n"
"<!ENTITY shy \"­\"> <!-- soft hyphen = discretionary hyphen,\n"
" U+00AD ISOnum -->\n"
"<!ENTITY reg \"®\"> <!-- registered sign = registered trade mark sign,\n"
" U+00AE ISOnum -->\n"
"<!ENTITY macr \"¯\"> <!-- macron = spacing macron = overline\n"
" = APL overbar, U+00AF ISOdia -->\n"
"<!ENTITY deg \"°\"> <!-- degree sign, U+00B0 ISOnum -->\n"
"<!ENTITY plusmn \"±\"> <!-- plus-minus sign = plus-or-minus sign,\n"
" U+00B1 ISOnum -->\n"
"<!ENTITY sup2 \"²\"> <!-- superscript two = superscript digit two\n"
" = squared, U+00B2 ISOnum -->\n"
"<!ENTITY sup3 \"³\"> <!-- superscript three = superscript digit three\n"
" = cubed, U+00B3 ISOnum -->\n"
"<!ENTITY acute \"´\"> <!-- acute accent = spacing acute,\n"
" U+00B4 ISOdia -->\n"
"<!ENTITY micro \"µ\"> <!-- micro sign, U+00B5 ISOnum -->\n"
"<!ENTITY para \"¶\"> <!-- pilcrow sign = paragraph sign,\n"
" U+00B6 ISOnum -->\n"
"<!ENTITY middot \"·\"> <!-- middle dot = Georgian comma\n"
" = Greek middle dot, U+00B7 ISOnum -->\n"
"<!ENTITY cedil \"¸\"> <!-- cedilla = spacing cedilla, U+00B8 ISOdia -->\n"
"<!ENTITY sup1 \"¹\"> <!-- superscript one = superscript digit one,\n"
" U+00B9 ISOnum -->\n"
"<!ENTITY ordm \"º\"> <!-- masculine ordinal indicator,\n"
" U+00BA ISOnum -->\n"
"<!ENTITY raquo \"»\"> <!-- right-pointing double angle quotation mark\n"
" = right pointing guillemet, U+00BB ISOnum -->\n"
"<!ENTITY frac14 \"¼\"> <!-- vulgar fraction one quarter\n"
" = fraction one quarter, U+00BC ISOnum -->\n"
"<!ENTITY frac12 \"½\"> <!-- vulgar fraction one half\n"
" = fraction one half, U+00BD ISOnum -->\n"
"<!ENTITY frac34 \"¾\"> <!-- vulgar fraction three quarters\n"
" = fraction three quarters, U+00BE ISOnum -->\n"
"<!ENTITY iquest \"¿\"> <!-- inverted question mark\n"
" = turned question mark, U+00BF ISOnum -->\n"
"<!ENTITY Agrave \"À\"> <!-- latin capital letter A with grave\n"
" = latin capital letter A grave,\n"
" U+00C0 ISOlat1 -->\n"
"<!ENTITY Aacute \"Á\"> <!-- latin capital letter A with acute,\n"
" U+00C1 ISOlat1 -->\n"
"<!ENTITY Acirc \"Â\"> <!-- latin capital letter A with circumflex,\n"
" U+00C2 ISOlat1 -->\n"
"<!ENTITY Atilde \"Ã\"> <!-- latin capital letter A with tilde,\n"
" U+00C3 ISOlat1 -->\n"
"<!ENTITY Auml \"Ä\"> <!-- latin capital letter A with diaeresis,\n"
" U+00C4 ISOlat1 -->\n"
"<!ENTITY Aring \"Å\"> <!-- latin capital letter A with ring above\n"
" = latin capital letter A ring,\n"
" U+00C5 ISOlat1 -->\n"
"<!ENTITY AElig \"Æ\"> <!-- latin capital letter AE\n"
" = latin capital ligature AE,\n"
" U+00C6 ISOlat1 -->\n"
"<!ENTITY Ccedil \"Ç\"> <!-- latin capital letter C with cedilla,\n"
" U+00C7 ISOlat1 -->\n"
"<!ENTITY Egrave \"È\"> <!-- latin capital letter E with grave,\n"
" U+00C8 ISOlat1 -->\n"
"<!ENTITY Eacute \"É\"> <!-- latin capital letter E with acute,\n"
" U+00C9 ISOlat1 -->\n"
"<!ENTITY Ecirc \"Ê\"> <!-- latin capital letter E with circumflex,\n"
" U+00CA ISOlat1 -->\n"
"<!ENTITY Euml \"Ë\"> <!-- latin capital letter E with diaeresis,\n"
" U+00CB ISOlat1 -->\n"
"<!ENTITY Igrave \"Ì\"> <!-- latin capital letter I with grave,\n"
" U+00CC ISOlat1 -->\n"
"<!ENTITY Iacute \"Í\"> <!-- latin capital letter I with acute,\n"
" U+00CD ISOlat1 -->\n"
"<!ENTITY Icirc \"Î\"> <!-- latin capital letter I with circumflex,\n"
" U+00CE ISOlat1 -->\n"
"<!ENTITY Iuml \"Ï\"> <!-- latin capital letter I with diaeresis,\n"
" U+00CF ISOlat1 -->\n"
"<!ENTITY ETH \"Ð\"> <!-- latin capital letter ETH, U+00D0 ISOlat1 -->\n"
"<!ENTITY Ntilde \"Ñ\"> <!-- latin capital letter N with tilde,\n"
" U+00D1 ISOlat1 -->\n"
"<!ENTITY Ograve \"Ò\"> <!-- latin capital letter O with grave,\n"
" U+00D2 ISOlat1 -->\n"
"<!ENTITY Oacute \"Ó\"> <!-- latin capital letter O with acute,\n"
" U+00D3 ISOlat1 -->\n"
"<!ENTITY Ocirc \"Ô\"> <!-- latin capital letter O with circumflex,\n"
" U+00D4 ISOlat1 -->\n"
"<!ENTITY Otilde \"Õ\"> <!-- latin capital letter O with tilde,\n"
" U+00D5 ISOlat1 -->\n"
"<!ENTITY Ouml \"Ö\"> <!-- latin capital letter O with diaeresis,\n"
" U+00D6 ISOlat1 -->\n"
"<!ENTITY times \"×\"> <!-- multiplication sign, U+00D7 ISOnum -->\n"
"<!ENTITY Oslash \"Ø\"> <!-- latin capital letter O with stroke\n"
" = latin capital letter O slash,\n"
" U+00D8 ISOlat1 -->\n"
"<!ENTITY Ugrave \"Ù\"> <!-- latin capital letter U with grave,\n"
" U+00D9 ISOlat1 -->\n"
"<!ENTITY Uacute \"Ú\"> <!-- latin capital letter U with acute,\n"
" U+00DA ISOlat1 -->\n"
"<!ENTITY Ucirc \"Û\"> <!-- latin capital letter U with circumflex,\n"
" U+00DB ISOlat1 -->\n"
"<!ENTITY Uuml \"Ü\"> <!-- latin capital letter U with diaeresis,\n"
" U+00DC ISOlat1 -->\n"
"<!ENTITY Yacute \"Ý\"> <!-- latin capital letter Y with acute,\n"
" U+00DD ISOlat1 -->\n"
"<!ENTITY THORN \"Þ\"> <!-- latin capital letter THORN,\n"
" U+00DE ISOlat1 -->\n"
"<!ENTITY szlig \"ß\"> <!-- latin small letter sharp s = ess-zed,\n"
" U+00DF ISOlat1 -->\n"
"<!ENTITY agrave \"à\"> <!-- latin small letter a with grave\n"
" = latin small letter a grave,\n"
" U+00E0 ISOlat1 -->\n"
"<!ENTITY aacute \"á\"> <!-- latin small letter a with acute,\n"
" U+00E1 ISOlat1 -->\n"
"<!ENTITY acirc \"â\"> <!-- latin small letter a with circumflex,\n"
" U+00E2 ISOlat1 -->\n"
"<!ENTITY atilde \"ã\"> <!-- latin small letter a with tilde,\n"
" U+00E3 ISOlat1 -->\n"
"<!ENTITY auml \"ä\"> <!-- latin small letter a with diaeresis,\n"
" U+00E4 ISOlat1 -->\n"
"<!ENTITY aring \"å\"> <!-- latin small letter a with ring above\n"
" = latin small letter a ring,\n"
" U+00E5 ISOlat1 -->\n"
"<!ENTITY aelig \"æ\"> <!-- latin small letter ae\n"
" = latin small ligature ae, U+00E6 ISOlat1 -->\n"
"<!ENTITY ccedil \"ç\"> <!-- latin small letter c with cedilla,\n"
" U+00E7 ISOlat1 -->\n"
"<!ENTITY egrave \"è\"> <!-- latin small letter e with grave,\n"
" U+00E8 ISOlat1 -->\n"
"<!ENTITY eacute \"é\"> <!-- latin small letter e with acute,\n"
" U+00E9 ISOlat1 -->\n"
"<!ENTITY ecirc \"ê\"> <!-- latin small letter e with circumflex,\n"
" U+00EA ISOlat1 -->\n"
"<!ENTITY euml \"ë\"> <!-- latin small letter e with diaeresis,\n"
" U+00EB ISOlat1 -->\n"
"<!ENTITY igrave \"ì\"> <!-- latin small letter i with grave,\n"
" U+00EC ISOlat1 -->\n"
"<!ENTITY iacute \"í\"> <!-- latin small letter i with acute,\n"
" U+00ED ISOlat1 -->\n"
"<!ENTITY icirc \"î\"> <!-- latin small letter i with circumflex,\n"
" U+00EE ISOlat1 -->\n"
"<!ENTITY iuml \"ï\"> <!-- latin small letter i with diaeresis,\n"
" U+00EF ISOlat1 -->\n"
"<!ENTITY eth \"ð\"> <!-- latin small letter eth, U+00F0 ISOlat1 -->\n"
"<!ENTITY ntilde \"ñ\"> <!-- latin small letter n with tilde,\n"
" U+00F1 ISOlat1 -->\n"
"<!ENTITY ograve \"ò\"> <!-- latin small letter o with grave,\n"
" U+00F2 ISOlat1 -->\n"
"<!ENTITY oacute \"ó\"> <!-- latin small letter o with acute,\n"
" U+00F3 ISOlat1 -->\n"
"<!ENTITY ocirc \"ô\"> <!-- latin small letter o with circumflex,\n"
" U+00F4 ISOlat1 -->\n"
"<!ENTITY otilde \"õ\"> <!-- latin small letter o with tilde,\n"
" U+00F5 ISOlat1 -->\n"
"<!ENTITY ouml \"ö\"> <!-- latin small letter o with diaeresis,\n"
" U+00F6 ISOlat1 -->\n"
"<!ENTITY divide \"÷\"> <!-- division sign, U+00F7 ISOnum -->\n"
"<!ENTITY oslash \"ø\"> <!-- latin small letter o with stroke,\n"
" = latin small letter o slash,\n"
" U+00F8 ISOlat1 -->\n"
"<!ENTITY ugrave \"ù\"> <!-- latin small letter u with grave,\n"
" U+00F9 ISOlat1 -->\n"
"<!ENTITY uacute \"ú\"> <!-- latin small letter u with acute,\n"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -