diff --git a/ChangeLog b/ChangeLog index 6e500e45..0882aa9a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Tue Aug 10 20:28:09 CEST 1999 Daniel Veillard + + * configure.in: upgraded to version 1.4.0 + * valid.[ch], SAX.c, parser.[ch] parserInternals.h ... + Big update, added a large part of the validation process, + it should be usable, but some parts are missing + * xpath.c: improved the implementation w.r.t. root. + * Makefile.am: added more tests + * test and result trees: added a lot of tests + * libxml.spec.in: export libxml.so.0 and libxml.so.1 + Tue Aug 10 11:33:41 CEST 1999 Daniel Veillard * Added an HACKING file diff --git a/HTMLparser.c b/HTMLparser.c index 6b08a224..9b41542b 100644 --- a/HTMLparser.c +++ b/HTMLparser.c @@ -515,13 +515,11 @@ htmlEntityDesc html40EntitiesTable[] = { { 180, "acute","acute accent = spacing acute, U+00B4 ISOdia" }, { 181, "micro","micro sign, U+00B5 ISOnum" }, { 182, "para", "pilcrow sign = paragraph sign, U+00B6 ISOnum" }, -{ 183, "middot","middle dot = Georgian comma - = Greek middle dot, U+00B7 ISOnum" }, +{ 183, "middot","middle dot = Georgian comma Greek middle dot, U+00B7 ISOnum" }, { 184, "cedil","cedilla = spacing cedilla, U+00B8 ISOdia" }, { 185, "sup1", "superscript one = superscript digit one, U+00B9 ISOnum" }, { 186, "ordm", "masculine ordinal indicator, U+00BA ISOnum" }, -{ 187, "raquo","right-pointing double angle quotation mark - = right pointing guillemet, U+00BB ISOnum" }, +{ 187, "raquo","right-pointing double angle quotation mark right pointing guillemet, U+00BB ISOnum" }, { 188, "frac14","vulgar fraction one quarter = fraction one quarter, U+00BC ISOnum" }, { 189, "frac12","vulgar fraction one half = fraction one half, U+00BD ISOnum" }, { 190, "frac34","vulgar fraction three quarters = fraction three quarters, U+00BE ISOnum" }, @@ -550,7 +548,7 @@ htmlEntityDesc html40EntitiesTable[] = { { 213, "Otilde","latin capital letter O with tilde, U+00D5 ISOlat1" }, { 214, "Ouml", "latin capital letter O with diaeresis, U+00D6 ISOlat1" }, { 215, "times","multiplication sign, U+00D7 ISOnum" }, -{ 216, "Oslash","latin capital letter O with stroke = latin capital letter O slash, U+00D8 ISOlat1" }, +{ 216, "Oslash","latin capital letter O with stroke latin capital letter O slash, U+00D8 ISOlat1" }, { 217, "Ugrave","latin capital letter U with grave, U+00D9 ISOlat1" }, { 218, "Uacute","latin capital letter U with acute, U+00DA ISOlat1" }, { 219, "Ucirc","latin capital letter U with circumflex, U+00DB ISOlat1" }, @@ -657,8 +655,7 @@ htmlEntityDesc html40EntitiesTable[] = { { 8254, "oline","overline = spacing overscore, U+203E NEW" }, { 8260, "frasl","fraction slash, U+2044 NEW" }, -{ 8472, "weierp","script capital P = power set - = Weierstrass p, U+2118 ISOamso" }, +{ 8472, "weierp","script capital P = power set = Weierstrass p, U+2118 ISOamso" }, { 8465, "image","blackletter capital I = imaginary part, U+2111 ISOamso" }, { 8476, "real", "blackletter capital R = real part symbol, U+211C ISOamso" }, { 8482, "trade","trade mark sign, U+2122 ISOnum" }, @@ -754,8 +751,7 @@ htmlEntityDesc html40EntitiesTable[] = { { 8225, "Dagger","double dagger, U+2021 ISOpub" }, { 8240, "permil","per mille sign, U+2030 ISOtech" }, { 8249, "lsaquo","single left-pointing angle quotation mark, U+2039 ISO proposed" }, -{ 8250, "rsaquo","single right-pointing angle quotation mark, - U+203A ISO proposed" }, +{ 8250, "rsaquo","single right-pointing angle quotation mark, U+203A ISO proposed" }, { 8364, "euro", "euro sign, U+20AC NEW" } }; diff --git a/Makefile.am b/Makefile.am index 08247e22..2b56ddd6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -44,7 +44,7 @@ xmlinc_HEADERS = \ valid.h DEPS = $(top_builddir)/libxml.la -LDADDS = $(top_builddir)/libxml.la @Z_LIBS@ +LDADDS = $(top_builddir)/libxml.la @Z_LIBS@ @M_LIBS@ tester_SOURCES=tester.c tester_LDFLAGS = @@ -68,108 +68,167 @@ testXPath_LDADD= $(LDADDS) check-local: tests -testall : tests SVGtests SAXtests XPathtests +testall : tests SVGtests SAXtests XPathtests XMLenttests + +tests: XMLtests HTMLtests Validtests -tests: HTMLtests XMLtests HTMLtests : testHTML - @(DIR=`pwd`; cd $(srcdir) ; \ - for i in test/HTML/* ; do \ + @echo "##" + @echo "## HTML regression tests" + @echo "##" + @(for i in $(srcdir)/test/HTML/* ; do \ + name=`basename $$i`; \ if [ ! -d $$i ] ; then \ - if [ ! -f result/HTML/`basename $$i` ] ; then \ - echo New test file `basename $$i` ; \ - $$DIR/testHTML $$i > result/HTML/`basename $$i` ; \ + if [ ! -f $(srcdir)/result/HTML/$$name ] ; then \ + echo New test file $$name ; \ + testHTML $$i > $(srcdir)/result/HTML/$$name ; \ else \ - echo Testing `basename $$i` ; \ - $$DIR/testHTML $$i > result.`basename $$i` ; \ - diff result/HTML/`basename $$i` result.`basename $$i` ; \ - $$DIR/testHTML result.`basename $$i` > result2.`basename $$i` ; \ - diff result.`basename $$i` result2.`basename $$i` ; \ - rm result.`basename $$i` result2.`basename $$i` ; \ + echo Testing $$name ; \ + testHTML $$i > result.$$name ; \ + diff $(srcdir)/result/HTML/$$name result.$$name ; \ + testHTML result.$$name > result2.$$name ; \ + diff result.$$name result2.$$name ; \ + rm result.$$name result2.$$name ; \ fi ; fi ; done) XMLtests : tester - @(DIR=`pwd`; cd $(srcdir) ; \ - for i in test/* ; do \ + @echo "##" + @echo "## XML regression tests" + @echo "##" + @(for i in $(srcdir)/test/* ; do \ + name=`basename $$i`; \ if [ ! -d $$i ] ; then \ - if [ ! -f result/`basename $$i` ] ; then \ - echo New test file `basename $$i` ; \ - $$DIR/tester $$i > result/`basename $$i` ; \ + if [ ! -f $(srcdir)/result/$$name ] ; then \ + echo New test file $$name ; \ + tester $$i > $(srcdir)/result/$$name ; \ else \ - echo Testing `basename $$i` ; \ - $$DIR/tester $$i > result.`basename $$i` ; \ - diff result/`basename $$i` result.`basename $$i` ; \ - $$DIR/tester result.`basename $$i` > result2.`basename $$i` ; \ - diff result.`basename $$i` result2.`basename $$i` ; \ - rm result.`basename $$i` result2.`basename $$i` ; \ + echo Testing $$name ; \ + tester $$i > result.$$name ; \ + diff $(srcdir)/result/$$name result.$$name ; \ + tester result.$$name > result2.$$name ; \ + diff result.$$name result2.$$name ; \ + rm result.$$name result2.$$name ; \ fi ; fi ; done) -SVGtests : tester - @(DIR=`pwd`; cd $(srcdir) ; \ - for i in test/SVG/* ; do \ +XMLenttests : tester + @echo "##" + @echo "## XML entity subst regression tests" + @echo "##" + @(for i in $(srcdir)/test/* ; do \ + name=`basename $$i`; \ if [ ! -d $$i ] ; then \ - if [ ! -f result/SVG/`basename $$i` ] ; then \ - echo New test file `basename $$i` ; \ - $$DIR/tester $$i > result/SVG/`basename $$i` ; \ + if [ ! -f $(srcdir)/result/noent/$$name ] ; then \ + echo New test file $$name ; \ + tester --noent $$i > $(srcdir)/result/noent/$$name ; \ else \ - echo Testing `basename $$i` ; \ - $$DIR/tester $$i > result.`basename $$i` ; \ - diff result/SVG/`basename $$i` result.`basename $$i` ; \ - $$DIR/tester result.`basename $$i` > result2.`basename $$i` ; \ - diff result.`basename $$i` result2.`basename $$i` ; \ - rm result.`basename $$i` result2.`basename $$i` ; \ + echo Testing $$name ; \ + tester --noent $$i > result.$$name ; \ + diff $(srcdir)/result/noent/$$name result.$$name ; \ + tester --noent result.$$name > result2.$$name ; \ + diff result.$$name result2.$$name ; \ + rm result.$$name result2.$$name ; \ fi ; fi ; done) XPathtests : testXPath - @(DIR=`pwd`; cd $(srcdir) ; \ - for i in test/XPath/expr/* ; do \ - if [ ! -d $$i ] ; then \ - if [ ! -f result/XPath/expr/`basename $$i` ] ; then \ - echo New test file `basename $$i` ; \ - $$DIR/testXPath -f --expr $$i > result/XPath/expr/`basename $$i` ; \ - else \ - echo Testing `basename $$i` ; \ - $$DIR/testXPath -f --expr $$i > result.`basename $$i` ; \ - diff result/XPath/expr/`basename $$i` result.`basename $$i` ; \ - rm result.`basename $$i` ; \ - fi ; fi ; done) - @(DIR=`pwd`; cd $(srcdir) ; \ - for i in test/XPath/docs/* ; do \ - if [ ! -d $$i ] ; then \ + @echo "##" + @echo "## XPath regression tests" + @echo "##" + @(for i in $(srcdir)/test/XPath/expr/* ; do \ name=`basename $$i`; \ - for j in test/XPath/tests/$$name* ; do \ - if [ ! -d $$j ] ; then \ - if [ ! -f result/XPath/tests/`basename $$j` ] ; then \ - echo New test file `basename $$i` ; \ - $$DIR/testXPath -f -i $$i $$j > result/XPath/tests/`basename $$j` ; \ + if [ ! -d $$i ] ; then \ + if [ ! -f $(srcdir)/result/XPath/expr/$$name ] ; then \ + echo New test file $$name ; \ + testXPath -f --expr $$i > $(srcdir)/result/XPath/expr/$$name ; \ else \ - echo Testing `basename $$j` ; \ - $$DIR/testXPath -f -i $$i $$j > result.`basename $$j` ; \ - diff result/XPath/tests/`basename $$j` result.`basename $$j` ; \ - rm result.`basename $$j` ; \ + echo Testing $$name ; \ + testXPath -f --expr $$i > result.$$name ; \ + diff $(srcdir)/result/XPath/expr/$$name result.$$name ; \ + rm result.$$name ; \ + fi ; fi ; done) + @(for i in $(srcdir)/test/XPath/docs/* ; do \ + if [ ! -d $$i ] ; then \ + doc=`basename $$i`; \ + for j in $(srcdir)/test/XPath/tests/$$doc* ; do \ + name=`basename $$j`; \ + if [ ! -d $$j ] ; then \ + if [ ! -f $(srcdir)/result/XPath/tests/$$name ] ; then \ + echo New test file $$name ; \ + testXPath -f -i $$i $$j > $(srcdir)/result/XPath/tests/$$name ; \ + else \ + echo Testing $$name ; \ + testXPath -f -i $$i $$j > result.$$name ; \ + diff $(srcdir)/result/XPath/tests/$$name result.$$name ; \ + rm result.$$name ; \ fi ; fi ; done ; fi ; done) -SAXtests : testSAX - @(DIR=`pwd`; cd $(srcdir) ; \ - for i in test/* ; do \ +SVGtests : tester + @echo "##" + @echo "## SVG parsing regression tests" + @echo "##" + @(for i in $(srcdir)/test/SVG/* ; do \ + name=`basename $$i`; \ if [ ! -d $$i ] ; then \ - if [ ! -f SAXresult/`basename $$i` ] ; then \ - echo New test file `basename $$i` ; \ - $$DIR/testSAX $$i > SAXresult/`basename $$i` ; \ + if [ ! -f $(srcdir)/result/SVG/$$name ] ; then \ + echo New test file $$name ; \ + tester $$i > $(srcdir)/result/SVG/$$name ; \ else \ - echo Testing `basename $$i` ; \ - $$DIR/testSAX $$i > result.`basename $$i` ; \ - diff SAXresult/`basename $$i` result.`basename $$i` ; \ - rm result.`basename $$i` ; \ + echo Testing $$name ; \ + tester $$i > result.$$name ; \ + diff $(srcdir)/result/SVG/$$name result.$$name ; \ + tester result.$$name > result2.$$name ; \ + diff result.$$name result2.$$name ; \ + rm result.$$name result2.$$name ; \ fi ; fi ; done) -## Put `exec' in the name because this should be installed by -## `install-exec', not `install-data'. +SAXtests : testSAX + @echo "##" + @echo "## SAX callbacks regression tests" + @echo "##" + @(for i in $(srcdir)/test/* ; do \ + name=`basename $$i`; \ + if [ ! -d $$i ] ; then \ + if [ ! -f $(srcdir)/SAXresult/$$name ] ; then \ + echo New test file $$name ; \ + testSAX $$i > $(srcdir)/SAXresult/$$name ; \ + else \ + echo Testing $$name ; \ + testSAX $$i > result.$$name ; \ + diff $(srcdir)/SAXresult/$$name result.$$name ; \ + rm result.$$name ; \ + fi ; fi ; done) -confexecdir=$(libdir) -confexec_DATA = xmlConf.sh -EXTRA_DIST = xmlConf.sh.in libxml.spec.in test result SAXresult example/Makefile.am \ - example/gjobread.c example/gjobs.xml +Validtests : tester + @echo "##" + @echo "## Validity checking regression tests" + @echo "##" + @(for i in $(srcdir)/test/VC/* ; do \ + name=`basename $$i`; \ + if [ ! -d $$i ] ; then \ + if [ ! -f $(srcdir)/result/VC/$$name ] ; then \ + echo New test file $$name ; \ + tester --noout --valid $$i 2> $(srcdir)/result/VC/$$name ; \ + else \ + echo Testing $$name ; \ + tester --noout --valid $$i 2> result.$$name ; \ + diff $(srcdir)/result/VC/$$name result.$$name ; \ + rm result.$$name ; \ + fi ; fi ; done) + @echo "##" + @echo "## Valid documents regression tests" + @echo "##" + @(for i in $(srcdir)/test/valid/* ; do \ + name=`basename $$i`; \ + if [ ! -d $$i ] ; then \ + if [ ! -f $(srcdir)/result/valid/$$name ] ; then \ + echo New test file $$name ; \ + tester --valid $$i > $(srcdir)/result/valid/$$name ; \ + else \ + echo Testing $$name ; \ + tester --valid $$i > result.$$name ; \ + diff $(srcdir)/result/valid/$$name result.$$name ; \ + rm result.$$name ; \ + fi ; fi ; done) dist-hook: cp libxml.spec $(distdir) diff --git a/SAX.c b/SAX.c index 968021ad..28bf0c2f 100644 --- a/SAX.c +++ b/SAX.c @@ -132,7 +132,7 @@ hasExternalSubset(void *ctx) } /** - * hasInternalSubset: + * internalSubset: * @ctx: the user data (XML parser context) * * Does this document has an internal subset @@ -141,15 +141,72 @@ void internalSubset(void *ctx, const CHAR *name, const CHAR *ExternalID, const CHAR *SystemID) { - xmlDtdPtr externalSubset; xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; #ifdef DEBUG_SAX fprintf(stderr, "SAX.internalSubset(%s, %s, %s)\n", name, ExternalID, SystemID); #endif xmlCreateIntSubset(ctxt->myDoc, name, ExternalID, SystemID); - if ((ExternalID != NULL) || (SystemID != NULL)) { - externalSubset = xmlParseDTD(ExternalID, SystemID); + if (((ExternalID != NULL) || (SystemID != NULL)) && + (ctxt->validate && ctxt->wellFormed && ctxt->myDoc)) { + /* + * Try to fetch and parse the external subset. + */ + xmlDtdPtr ret = NULL; + xmlParserCtxtPtr dtdCtxt; + xmlParserInputPtr input = NULL; + xmlCharEncoding enc; + + dtdCtxt = xmlNewParserCtxt(); + if (dtdCtxt == NULL) return; + + /* + * Ask the Entity resolver to load the damn thing + */ + if ((ctxt->directory != NULL) && (dtdCtxt->directory == NULL)) + dtdCtxt->directory = xmlStrdup(ctxt->directory); + + if ((dtdCtxt->sax != NULL) && (dtdCtxt->sax->resolveEntity != NULL)) + input = dtdCtxt->sax->resolveEntity(dtdCtxt->userData, ExternalID, + SystemID); + if (input == NULL) { + xmlFreeParserCtxt(dtdCtxt); + return; + } + + /* + * plug some encoding conversion routines here. !!! + */ + xmlPushInput(dtdCtxt, input); + enc = xmlDetectCharEncoding(dtdCtxt->input->cur); + xmlSwitchEncoding(dtdCtxt, enc); + + if (input->filename == NULL) + input->filename = xmlStrdup(SystemID); + input->line = 1; + input->col = 1; + input->base = dtdCtxt->input->cur; + input->cur = dtdCtxt->input->cur; + input->free = NULL; + + /* + * let's parse that entity knowing it's an external subset. + */ + xmlParseExternalSubset(dtdCtxt, ExternalID, SystemID); + + if (dtdCtxt->myDoc != NULL) { + if (dtdCtxt->wellFormed) { + ret = dtdCtxt->myDoc->intSubset; + dtdCtxt->myDoc->intSubset = NULL; + } else { + ret = NULL; + } + xmlFreeDoc(dtdCtxt->myDoc); + dtdCtxt->myDoc = NULL; + } + xmlFreeParserCtxt(dtdCtxt); + + ctxt->myDoc->extSubset = ret; } } @@ -214,6 +271,29 @@ getEntity(void *ctx, const CHAR *name) return(ret); } +/** + * getParameterEntity: + * @ctx: the user data (XML parser context) + * @name: The entity name + * + * Get a parameter entity by name + * + * Returns the xmlEntityPtr if found. + */ +xmlEntityPtr +getParameterEntity(void *ctx, const CHAR *name) +{ + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; + xmlEntityPtr ret; + +#ifdef DEBUG_SAX + fprintf(stderr, "SAX.getParameterEntity(%s)\n", name); +#endif + + ret = xmlGetParameterEntity(ctxt->myDoc, name); + return(ret); +} + /** * entityDecl: @@ -256,13 +336,19 @@ attributeDecl(void *ctx, const CHAR *elem, const CHAR *name, xmlEnumerationPtr tree) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; + xmlAttributePtr attr; #ifdef DEBUG_SAX fprintf(stderr, "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n", elem, name, type, def, defaultValue); #endif - xmlAddAttributeDecl(ctxt->myDoc->intSubset, elem, name, type, def, - defaultValue, tree); + attr = xmlAddAttributeDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, elem, + name, type, def, defaultValue, tree); + if (attr == 0) ctxt->valid = 0; + if (ctxt->validate && ctxt->wellFormed && + ctxt->myDoc && ctxt->myDoc->intSubset) + ctxt->valid &= xmlValidateAttributeDecl(&ctxt->vctxt, ctxt->myDoc, + attr); } /** @@ -281,12 +367,19 @@ elementDecl(void *ctx, const CHAR *name, int type, xmlElementContentPtr content) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; + xmlElementPtr elem; #ifdef DEBUG_SAX fprintf(stderr, "SAX.elementDecl(%s, %d, ...)\n", name, type); #endif - xmlAddElementDecl(ctxt->myDoc->intSubset, name, type, content); + + elem = xmlAddElementDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, + name, type, content); + if (elem == 0) ctxt->valid = 0; + if (ctxt->validate && ctxt->wellFormed && + ctxt->myDoc && ctxt->myDoc->intSubset) + ctxt->valid &= xmlValidateElementDecl(&ctxt->vctxt, ctxt->myDoc, elem); } /** @@ -304,10 +397,19 @@ notationDecl(void *ctx, const CHAR *name, const CHAR *publicId, const CHAR *systemId) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; + xmlNotationPtr nota; + #ifdef DEBUG_SAX fprintf(stderr, "SAX.notationDecl(%s, %s, %s)\n", name, publicId, systemId); #endif - xmlAddNotationDecl(ctxt->myDoc->intSubset, name, publicId, systemId); + + nota = xmlAddNotationDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, name, + publicId, systemId); + if (nota == 0) ctxt->valid = 0; + if (ctxt->validate && ctxt->wellFormed && + ctxt->myDoc && ctxt->myDoc->intSubset) + ctxt->valid &= xmlValidateNotationDecl(&ctxt->vctxt, ctxt->myDoc, + nota); } /** @@ -442,8 +544,15 @@ attribute(void *ctx, const CHAR *fullname, const CHAR *value) } ret = xmlNewProp(ctxt->node, name, NULL); + if ((ret != NULL) && (ctxt->replaceEntities == 0)) ret->val = xmlStringGetNodeList(ctxt->myDoc, value); + + if (ctxt->validate && ctxt->wellFormed && + ctxt->myDoc && ctxt->myDoc->intSubset) + ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, ctxt->myDoc, + ctxt->node, ret, value); + if (name != NULL) free(name); if (ns != NULL) @@ -569,6 +678,12 @@ endElement(void *ctx, const CHAR *name) xmlParserAddNodeInfo(ctxt, &node_info); } + if (ctxt->validate && ctxt->wellFormed && + ctxt->myDoc && ctxt->myDoc->intSubset) + ctxt->valid &= xmlValidateOneElement(&ctxt->vctxt, ctxt->myDoc, + cur); + + /* * end of parsing of this node. */ @@ -821,6 +936,29 @@ comment(void *ctx, const CHAR *value) #endif ret = xmlNewDocComment(ctxt->myDoc, value); xmlAddChild(ctxt->node, ret); + /* !!!!! merges */ +} + +/** + * cdataBlock: + * @ctx: the user data (XML parser context) + * @value: The pcdata content + * @len: the block length + * + * called when a pcdata block has been parsed + */ +void +cdataBlock(void *ctx, const CHAR *value, int len) +{ + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; + xmlNodePtr ret; + +#ifdef DEBUG_SAX + fprintf(stderr, "SAX.pcdata(%s, %d)\n", name, len); +#endif + ret = xmlNewCDataBlock(ctxt->myDoc, value, len); + xmlAddChild(ctxt->node, ret); + /* !!!!! merges */ } /* @@ -851,6 +989,8 @@ xmlSAXHandler xmlDefaultSAXHandler = { xmlParserWarning, xmlParserError, xmlParserError, + getParameterEntity, + cdataBlock, }; /** @@ -867,6 +1007,7 @@ xmlDefaultSAXHandlerInit(void) xmlDefaultSAXHandler.hasExternalSubset = hasExternalSubset; xmlDefaultSAXHandler.resolveEntity = resolveEntity; xmlDefaultSAXHandler.getEntity = getEntity; + xmlDefaultSAXHandler.getParameterEntity = getParameterEntity; xmlDefaultSAXHandler.entityDecl = entityDecl; xmlDefaultSAXHandler.attributeDecl = attributeDecl; xmlDefaultSAXHandler.elementDecl = elementDecl; @@ -879,6 +1020,7 @@ xmlDefaultSAXHandlerInit(void) xmlDefaultSAXHandler.endElement = endElement; xmlDefaultSAXHandler.reference = reference; xmlDefaultSAXHandler.characters = characters; + xmlDefaultSAXHandler.cdataBlock = cdataBlock; xmlDefaultSAXHandler.ignorableWhitespace = ignorableWhitespace; xmlDefaultSAXHandler.processingInstruction = processingInstruction; xmlDefaultSAXHandler.comment = comment; @@ -915,6 +1057,8 @@ xmlSAXHandler htmlDefaultSAXHandler = { xmlParserWarning, xmlParserError, xmlParserError, + getParameterEntity, + NULL, }; /** @@ -931,6 +1075,7 @@ htmlDefaultSAXHandlerInit(void) htmlDefaultSAXHandler.hasExternalSubset = NULL; htmlDefaultSAXHandler.resolveEntity = NULL; htmlDefaultSAXHandler.getEntity = getEntity; + htmlDefaultSAXHandler.getParameterEntity = NULL; htmlDefaultSAXHandler.entityDecl = NULL; htmlDefaultSAXHandler.attributeDecl = NULL; htmlDefaultSAXHandler.elementDecl = NULL; @@ -943,6 +1088,7 @@ htmlDefaultSAXHandlerInit(void) htmlDefaultSAXHandler.endElement = endElement; htmlDefaultSAXHandler.reference = NULL; htmlDefaultSAXHandler.characters = characters; + htmlDefaultSAXHandler.cdataBlock = NULL; htmlDefaultSAXHandler.ignorableWhitespace = ignorableWhitespace; htmlDefaultSAXHandler.processingInstruction = NULL; htmlDefaultSAXHandler.comment = comment; diff --git a/TODO b/TODO index 84167631..f3ab844d 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,8 @@ TODO for the XML parser: +- use libunicode ! +- finish XPath, then XPointer, Xlink - Support for UTF-8 and UTF-16 encoding (Urgent !!!). - progressive parsing. The entity support is a first step toward asbtraction of an input stream. A large part of the context is still diff --git a/acconfig.h b/acconfig.h index e89b2af3..6d79490b 100644 --- a/acconfig.h +++ b/acconfig.h @@ -1,3 +1,6 @@ #undef PACKAGE #undef VERSION #undef HAVE_LIBZ +#undef HAVE_LIBM +#undef HAVE_ISINF +#undef HAVE_ISNAN diff --git a/config.h.in b/config.h.in index 6778ed02..97a7bd12 100644 --- a/config.h.in +++ b/config.h.in @@ -9,6 +9,30 @@ #undef PACKAGE #undef VERSION #undef HAVE_LIBZ +#undef HAVE_LIBM +#undef HAVE_ISINF +#undef HAVE_ISNAN + +/* Define if you have the class function. */ +#undef HAVE_CLASS + +/* Define if you have the finite function. */ +#undef HAVE_FINITE + +/* Define if you have the fp_class function. */ +#undef HAVE_FP_CLASS + +/* Define if you have the fpclass function. */ +#undef HAVE_FPCLASS + +/* Define if you have the isinf function. */ +#undef HAVE_ISINF + +/* Define if you have the isnan function. */ +#undef HAVE_ISNAN + +/* Define if you have the isnand function. */ +#undef HAVE_ISNAND /* Define if you have the snprintf function. */ #undef HAVE_SNPRINTF @@ -34,9 +58,24 @@ /* Define if you have the header file. */ #undef HAVE_FCNTL_H +/* Define if you have the header file. */ +#undef HAVE_FLOAT_H + +/* Define if you have the header file. */ +#undef HAVE_FP_CLASS_H + +/* Define if you have the header file. */ +#undef HAVE_IEEEFP_H + /* Define if you have the header file. */ #undef HAVE_MALLOC_H +/* Define if you have the header file. */ +#undef HAVE_MATH_H + +/* Define if you have the header file. */ +#undef HAVE_NAN_H + /* Define if you have the header file. */ #undef HAVE_NDIR_H diff --git a/configure.in b/configure.in index 93328050..35294a6c 100644 --- a/configure.in +++ b/configure.in @@ -4,7 +4,7 @@ AC_INIT(entities.h) AM_CONFIG_HEADER(config.h) LIBXML_MAJOR_VERSION=1 -LIBXML_MINOR_VERSION=4 +LIBXML_MINOR_VERSION=5 LIBXML_MICRO_VERSION=0 LIBXML_VERSION=$LIBXML_MAJOR_VERSION.$LIBXML_MINOR_VERSION.$LIBXML_MICRO_VERSION LIBXML_VERSION_INFO=`expr $LIBXML_MAJOR_VERSION + $LIBXML_MINOR_VERSION`:$LIBXML_MICRO_VERSION:$LIBXML_MINOR_VERSION @@ -39,11 +39,13 @@ AC_CHECK_LIB(z, inflate, AC_CHECK_HEADER(zlib.h, Z_LIBS="-lz"; AC_DEFINE(HAVE_LIBZ))) + dnl Checks for header files. AC_HEADER_DIRENT AC_HEADER_STDC AC_CHECK_HEADERS(fcntl.h unistd.h ctype.h dirent.h errno.h malloc.h) AC_CHECK_HEADERS(stdarg.h sys/stat.h sys/types.h time.h zlib.h) +AC_CHECK_HEADERS(ieeefp.h nan.h math.h fp_class.h float.h) dnl Specific dir for HTML output ? if test "x$with_html_dir" = "x" ; then @@ -54,15 +56,6 @@ fi AC_SUBST(HTML_DIR) -XML_LIBDIR='-L${libdir}' -XML_INCLUDEDIR='-I${includedir}/gnome-xml' -XML_LIBS="-lxml $Z_LIBS" - -AC_SUBST(XML_LIBDIR) -AC_SUBST(XML_LIBS) -AC_SUBST(XML_INCLUDEDIR) -AC_SUBST(HTML_DIR) - AC_ARG_ENABLE(corba, [ --enable-corba Add Corba support (default)]) dnl @@ -75,7 +68,41 @@ AC_SUBST(CORBA_CFLAGS) dnl Checks for library functions. AC_FUNC_STRFTIME -AC_CHECK_FUNCS(strdup strndup strerror snprintf ) +AC_CHECK_FUNCS(strdup strndup strerror snprintf) +AC_CHECK_FUNCS(finite isinf isnan isnand fp_class class fpclass finite) + +dnl Checks for isnan in libm if not in libc +M_LIBS= +if test "$ac_cv_func_isnan" != "yes" +then +AC_CHECK_LIB(m, isnan, + M_LIBS="-lm"; AC_DEFINE(HAVE_ISNAN)) +fi + +dnl Checks for isinf in libm if not in libc +if test "$ac_cv_func_isinf" != "yes" +then +M2_LIBS="" +AC_CHECK_LIB(m, isinf, + M2_LIBS="-lm"; AC_DEFINE(HAVE_ISINF)) +if test "$M2_LIBS" != "" +then + M_LIBS="$M2_LIBS" +fi +fi + +XML_LIBDIR='-L${libdir}' +XML_INCLUDEDIR='-I${includedir}/gnome-xml' +XML_LIBS="-lxml $Z_LIBS $M_LIBS" + +AC_SUBST(XML_LIBDIR) +AC_SUBST(XML_LIBS) +AC_SUBST(XML_INCLUDEDIR) +AC_SUBST(HTML_DIR) +AC_SUBST(HAVE_ISNAN) +AC_SUBST(HAVE_ISINF) + AC_SUBST(Z_LIBS) +AC_SUBST(M_LIBS) AC_OUTPUT(libxml.spec Makefile doc/Makefile example/Makefile xml-config) diff --git a/doc/html/gnome-xml-entities.html b/doc/html/gnome-xml-entities.html index 0a27454b..2ebcc419 100644 --- a/doc/html/gnome-xml-entities.html +++ b/doc/html/gnome-xml-entities.html @@ -115,7 +115,7 @@ SIZE="3" >

Name

Synopsis

CHAR *name); +xmlEntityPtr xmlGetParameterEntity (xmlDocPtr doc, + const CHAR *name); const CHAR

Description

Details

#define XML_INTERNAL_GENERAL_ENTITY		1
#define XML_INTERNAL_GENERAL_ENTITY

#define XML_EXTERNAL_GENERAL_PARSED_ENTITY	2
#define XML_EXTERNAL_GENERAL_PARSED_ENTITY

#define XML_EXTERNAL_GENERAL_UNPARSED_ENTITY	3
#define XML_EXTERNAL_GENERAL_UNPARSED_ENTITY

#define XML_INTERNAL_PARAMETER_ENTITY		4
#define XML_INTERNAL_PARAMETER_ENTITY

#define XML_EXTERNAL_PARAMETER_ENTITY		5
#define XML_EXTERNAL_PARAMETER_ENTITY

#define XML_INTERNAL_PREDEFINED_ENTITY		6
#define XML_INTERNAL_PREDEFINED_ENTITY

xmlEntityPtr

typedef xmlEntity *xmlEntityPtr;


#define XML_MIN_ENTITIES_TABLE	32
#define XML_MIN_ENTITIES_TABLE

xmlEntitiesTablePtr

typedef xmlEntitiesTable *xmlEntitiesTablePtr;


the document  the entity name  the entity type XML_xxx_yyy_ENTITY  the entity external ID if available  the entity system ID if available  the entity content 


the document  the entity name  the entity type XML_xxx_yyy_ENTITY  the entity external ID if available  the entity system ID if available  the entity content 


the entity name NULL if not, othervise the entity 


the document referencing the entity  the entity name A pointer to the entity structure or NULL if not found. 


the document referencing the entity  the entity name A pointer to the entity structure or NULL if not found. 


xmlGetParameterEntity ()

xmlEntityPtr xmlGetParameterEntity          (xmlDocPtr doc,
+                                             const CHAR *name);

Do an entity lookup in the internal and external subsets and +returns the corresponding parameter entity, if found.

doc : 
name : 
Returns : 


Do a global encoding of a string, replacing the predefined entities and non ASCII values with their entities and CharRef counterparts.

TODO !!!! Once moved to UTF-8 internal encoding, the encoding of non-ascii -get erroneous.

TODO: remove this, once we are not afraid of breaking binary compatibility

TODO This routine is not reentrant, the interface -should not be modified though.

People must migrate their code to xmlEncodeEntitiesReentrant !

People must migrate their code to xmlEncodeEntitiesReentrant ! +This routine will issue a warning when encountered.

the document containing the string  A string to convert to XML. A newly allocated string with the substitution done. 


the document containing the string  A string to convert to XML. A newly allocated string with the substitution done. 


the xmlEntitiesTablePtr just created or NULL in case of error. 


An entity table the new xmlEntitiesTablePtr or NULL in case of error. 


An entity table 


An XML buffer.  An entity table 

Name

Synopsis

Description

Details

htmlParserCtxt

typedef xmlParserCtxt htmlParserCtxt;


htmlParserCtxtPtr

typedef xmlParserCtxtPtr htmlParserCtxtPtr;


htmlParserNodeInfo

typedef xmlParserNodeInfo htmlParserNodeInfo;


htmlSAXHandler

typedef xmlSAXHandler htmlSAXHandler;


htmlSAXHandlerPtr

typedef xmlSAXHandlerPtr htmlSAXHandlerPtr;


htmlParserInput

typedef xmlParserInput htmlParserInput;


htmlParserInputPtr

typedef xmlParserInputPtr htmlParserInputPtr;


htmlDocPtr

typedef xmlDocPtr htmlDocPtr;


htmlNodePtr

typedef xmlNodePtr htmlNodePtr;


The tag name the related htmlElemDescPtr or NULL if not found. 


the entity name the associated htmlEntityDescPtr if found, NULL otherwise. 


an HTML parser context  location to store the entity name the associated htmlEntityDescPtr if found, or NULL otherwise, -if non-NULL *str will have to be freed by the caller. 


an HTML parser context the value parsed (as an int) 


an HTML parser context 


a pointer to an array of CHAR  a free form C string describing the HTML document encoding, or NULL  the SAX handler block  if using SAX, this pointer will be provided on callbacks.  the resulting document tree 


a pointer to an array of CHAR  a free form C string describing the HTML document encoding, or NULL the resulting document tree 


the filename  a free form C string describing the HTML document encoding, or NULL  the SAX handler block  if using SAX, this pointer will be provided on callbacks.  the resulting document tree 


the filename  a free form C string describing the HTML document encoding, or NULL the resulting document tree 

Name

Synopsis

Description

Details

#define HTML_TEXT_NODE		XML_TEXT_NODE
#define HTML_TEXT_NODE

#define HTML_ENTITY_REF_NODE	XML_ENTITY_REF_NODE
#define HTML_ENTITY_REF_NODE

#define HTML_COMMENT_NODE	XML_COMMENT_NODE
#define HTML_COMMENT_NODE

the document  OUT: the memory pointer  OUT: the memory lenght 


the FILE*  the document 


the filename  the document  the number of byte written or -1 in case of failure. 

xmlParserNodeInfoSeqPtr; +enum xmlParserInputState; typedef xmlParserCtxtCHAR *name); +xmlEntityPtr (*getParameterEntitySAXFunc) (void *ctx, + const CHAR *name); void (*entityDeclSAXFuncCHAR *value); void (*cdataBlockSAXFunc) (void *ctx, + const CHAR *value, + int len); +void (*warningSAXFunc) (void *ctx, @@ -823,7 +847,7 @@ HREF="gnome-xml-parser.html#HTMLDEFAULTSAXHANDLERINIT" >

Description

Details

#define XML_DEFAULT_VERSION	"1.0"
#define XML_DEFAULT_VERSION


xmlParserInputPtr

typedef xmlParserInput *xmlParserInputPtr;


xmlParserNodeInfo

typedef _xmlParserNodeInfo xmlParserNodeInfo;

xmlParserNodeInfoSeq

typedef _xmlParserNodeInfoSeq xmlParserNodeInfoSeq;
xmlParserNodeInfo


xmlParserNodeInfoSeq


xmlParserNodeInfoSeqPtr


enum xmlParserInputState

typedef xmlParserNodeInfoSeq *xmlParserNodeInfoSeqPtr;
typedef enum xmlParserInputState { + XML_PARSER_EOF = 0, + XML_PARSER_PROLOG, + XML_PARSER_CONTENT, + XML_PARSER_ENTITY_DECL, + XML_PARSER_ENTITY_VALUE, + XML_PARSER_ATTRIBUTE_VALUE, + XML_PARSER_DTD, + XML_PARSER_EPILOG, + XML_PARSER_COMMENT, + XML_PARSER_CDATA_SECTION, +} xmlParserInputState;

xmlParserCtxt

typedef _xmlParserCtxt xmlParserCtxt;


xmlParserCtxtPtr

typedef xmlParserCtxt *xmlParserCtxtPtr;


xmlSAXLocator

typedef _xmlSAXLocator xmlSAXLocator;

xmlSAXLocatorPtr

typedef xmlSAXLocator *xmlSAXLocatorPtr;
xmlSAXLocator


xmlSAXLocatorPtr





getParameterEntitySAXFunc ()

xmlEntityPtr (*getParameterEntitySAXFunc)   (void *ctx,
+                                             const CHAR *name);

ctx : 
name : 
Returns : 


















cdataBlockSAXFunc ()

void        (*cdataBlockSAXFunc)            (void *ctx,
+                                             const CHAR *value,
+                                             int len);

ctx : 
value : 
len : 








xmlSAXHandlerPtr

typedef xmlSAXHandler *xmlSAXHandlerPtr;






an XML parser input  an indicative size for the lookahead the number of CHARs read, or -1 in case of error, 0 indicate the -end of this entity 


an XML parser input  an indicative size for the lookahead the number of CHARs read, or -1 in case of error, 0 indicate the -end of this entity 


the input CHAR * a new CHAR * or NULL 


the input CHAR *  the len of cur a new CHAR * or NULL 


the CHAR * array (haystack)  the index of the first char (zero based)  the length of the substring the CHAR * for the first occurence or NULL. 


the CHAR * array  the CHAR to search the CHAR * for the first occurence or NULL. 


the CHAR * array (haystack)  the CHAR to search (needle) the CHAR * for the first occurence or NULL. 


the first CHAR *  the second CHAR * the integer result of the comparison 


the first CHAR *  the second CHAR *  the max comparison length the integer result of the comparison 


the CHAR * array the number of CHAR contained in the ARRAY. 


the original CHAR * array  the CHAR * array added a new CHAR * containing the concatenated string. 


the original CHAR * array  the CHAR * array added  the length of add a new CHAR * containing the concatenated string. 


a pointer to an array of CHAR the resulting document tree 


an pointer to a char array  the size of the array the resulting document tree 


the filename the resulting document tree 


int 0 or 1  the last value for 0 for no substitution, 1 for substitution. 


a pointer to an array of CHAR the resulting document tree 


an pointer to a char array  the size of the array the resulting document tree 


the filename the resulting document tree 


an XML parser context 0, -1 in case of error. the parser context is augmented -as a result of the parsing. 


the SAX handler block  a pointer to an array of CHAR  work in recovery mode, i.e. tries to read no Well Formed -documents the resulting document tree 


the SAX handler block  an pointer to a char array  the siwe of the array  work in recovery mode, i.e. tries to read no Well Formed -documents the resulting document tree 


the SAX handler block  the filename  work in recovery mode, i.e. tries to read no Well Formed -documents the resulting document tree 


a NAME* containing the External ID of the DTD  a NAME* containing the URL to the DTD the resulting xmlDtdPtr or NULL in case of error. 


the SAX handler block  a NAME* containing the External ID of the DTD  a NAME* containing the URL to the DTD the resulting xmlDtdPtr or NULL in case of error. 


an HTML parser context 


an XML parser context 


an XML parser context  a CHAR * buffer  a file name 


an XML parser context  an XML node within the tree an xmlParserNodeInfo block pointer or NULL 


a node info sequence pointer 


a node info sequence pointer 


a node info sequence pointer  an XML node pointer a long indicating the position of the record 


an XML parser context  a node info sequence pointer 



Name

Synopsis

+typedef CHARVAL; +#define NEXTCHARVAL (p) +#define SKIPCHARVAL (p) #define IS_CHARxmlParserCtxtPtr ctxt); +xmlParserCtxtPtr xmlNewParserCtxt (); +void xmlSwitchEncoding (xmlParserCtxtPtr ctxt, + xmlCharEncoding enc); void xmlHandleEntityCHAR* xmlScanName (xmlParserCtxtPtr ctxt); +CHAR* xmlParseName (xmlParserCtxtPtr ctxt); +void xmlParseExternalSubset (xmlParserCtxtPtr ctxt, + const CHAR *ExternalID, + const CHAR *SystemID); #define XML_SUBSTITUTE_NONE

Description

Details

CHARVAL


NEXTCHARVAL()

#define     NEXTCHARVAL(p)

p : 


SKIPCHARVAL()

#define     SKIPCHARVAL(p)

p : 














a pointer to an array of CHAR the new parser context or NULL 


the filename the new parser context or NULL 


an pointer to a char array  the siwe of the array the new parser context or NULL 


an XML parser context 


xmlHandleEntity ()

xmlNewParserCtxt ()

void        xmlHandleEntity                 (xmlParserCtxtPtr ctxt,
-                                             xmlEntityPtr entity);
xmlNewParserCtxt ();

Default handling of defined entities, when should we define a new input -stream ? When do we just handle that as a set of chars ? -TODO: we should call the SAX handler here and have it resolve the issue

Allocate and initialize a new parser context.

Returns : 


xmlSwitchEncoding ()

void        xmlSwitchEncoding               (xmlParserCtxtPtr ctxt,
+                                             xmlCharEncoding enc);

change the input functions when discovering the character encoding +of a given entity.

an XML parser context enc : 


xmlHandleEntity ()

void        xmlHandleEntity                 (xmlParserCtxtPtr ctxt,
+                                             xmlEntityPtr entity);

Default handling of defined entities, when should we define a new input +stream ? When do we just handle that as a set of chars ?

OBSOLETE: to be removed at some point.

 
ctxt : 
an XML entity pointer.


an XML parser context  an Entity pointer the new input stream 


an XML parser context  an XML parser input fragment (entity, XML fragment ...). 


xmlPopInput: the current input pointed by ctxt->input came to an end pop it and return the next char.

TODO A deallocation of the popped Input structure is needed

an XML parser context the current CHAR in the parser context 


an xmlParserInputPtr 


an XML parser context  the filename to use as entity the new input stream or NULL in case of error 


an XML parser context  a CHAR **  the function returns the local part, and prefix is updated -to get the Prefix if any. 


an XML parser context the namespace name or NULL 


an XML parser context  a CHAR **  the function returns the local part, and prefix is updated -to get the Prefix if any. 


an XML parser context the namespace name 


[OLD] Parse and return a string between quotes or doublequotes

[OLD] Parse and return a string between quotes or doublequotes +To be removed at next drop of binary compatibility

an XML parser context the string parser or NULL. 


To be removed at next drop of binary compatibility

an XML parser context 


xmlScanName ()

CHAR*       xmlScanName                     (xmlParserCtxtPtr ctxt);

Trickery: parse an XML name but without consuming the input flow +Needed for rollback cases.

[4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | +CombiningChar | Extender

[5] Name ::= (Letter | '_' | ':') (NameChar)*

[6] Names ::= Name (S Name)*

ctxt : 
Returns : 


an XML parser context the Name parsed or NULL 


an XML parser context the Nmtoken parsed or NULL 


an XML parser context  if non-NULL store a copy of the original entity value the EntityValue parsed with reference substitued or NULL 


an XML parser context the AttValue parsed or NULL. 


an XML parser context the SystemLiteral parsed or NULL 


an XML parser context the PubidLiteral parsed or NULL. 


an XML parser context  int indicating whether we are within a CDATA section 


an XML parser context  a CHAR** receiving PubidLiteral  indicate whether we should restrict parsing to only -production [75], see NOTE below the function returns SystemLiteral and in the second -case publicID receives PubidLiteral, is strict is off -it is possible to return NULL and have publicID set. 


an XML parser context  should we create a node, or just skip the content 


an XML parser context the PITarget name or NULL 


an XML parser context 


an XML parser context 


[76] NDataDecl ::= S 'NDATA' S Name

[ VC: Notation Declared ] +TODO The Name must match the declared name of a notation.

an XML parser context 


FIXED' S)? AttValue)

[ VC: Required Attribute ] +TODO if the default declaration is the keyword REQUIRED, then the +attribute must be specified for all elements of the type in the +attribute-list declaration.

[ VC: Attribute Default Legal ] +The declared default value must meet the lexical constraints of +the declared attribute type c.f. xmlValidateAttributeDecl()

[ VC: Fixed Attribute Default ] +TODO if an attribute has a default value declared with the FIXED +keyword, instances of that attribute must match the default value.

[ WFC: No < in Attribute Values ] +handled in xmlParseAttValue()

an XML parser context  Receive a possible fixed default value for the attribute  XML_ATTRIBUTE_NONE, XML_ATTRIBUTE_REQUIRED, XML_ATTRIBUTE_IMPLIED -or XML_ATTRIBUTE_FIXED.  


parse an Notation attribute type.

Note: the leading 'NOTATION' S part has already being parsed...

[58] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')'

Note: the leading 'NOTATION' S part has already being parsed...

[ VC: Notation Attributes ] +TODO Values of this type must match one of the notation names included +in the declaration; all notation names in the declaration must be declared.

an XML parser context  the notation attribute tree built while parsing 


[59] Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')'

[ VC: Enumeration ] +TODO Values of this type must match one of the Nmtoken tokens in +the declaration

an XML parser context  the enumeration attribute tree built while parsing 


an XML parser context  the enumeration tree built while parsing  XML_ATTRIBUTE_ENUMERATION or XML_ATTRIBUTE_NOTATION 


[56] TokenizedType ::= 'ID' | 'IDREF' | 'IDREFS' | 'ENTITY' | 'ENTITIES' | 'NMTOKEN' | 'NMTOKENS'

Validity constraints for attribute values syntax are checked in +xmlValidateAttributeValue()

[ VC: ID ] +Values of type ID must match the Name production. TODO A name must not +appear more than once in an XML document as a value of this type; +i.e., ID values must uniquely identify the elements which bear them.

[ VC: One ID per Element Type ] +TODO No element type may have more than one ID attribute specified.

[ VC: ID Attribute Default ] +TODO An ID attribute must have a declared default of IMPLIED or REQUIRED.

[ VC: IDREF ] +Values of type IDREF must match the Name production, and values +of type IDREFS must match Names; TODO each Name must match the value of +an ID attribute on some element in the XML document; i.e. IDREF +values must match the value of some ID attribute.

[ VC: Entity Name ] +Values of type ENTITY must match the Name production, values +of type ENTITIES must match Names; TODO each Name must match the name of +an unparsed entity declared in the DTD.

[ VC: Name Token ] +Values of type NMTOKEN must match the Nmtoken production; values +of type NMTOKENS must match Nmtokens.

an XML parser context  the enumeration tree built while parsing the attribute type 


an XML parser context 


PCDATA' S? ')'

[ VC: Proper Group/PE Nesting ] applies to [51] too (see [49])

[ VC: No Duplicate Types ] +TODO The same name must not appear more than once in a single +mixed-content declaration.

an XML parser context  the list of the xmlElementContentPtr describing the element choices 


[50] seq ::= '(' S? cp ( S? ',' S? cp )* S? ')'

[ VC: Proper Group/PE Nesting ] applies to [49] and [50] +TODO Parameter-entity replacement text must be properly nested +with parenthetized groups. That is to say, if either of the +opening or closing parentheses in a choice, seq, or Mixed +construct is contained in the replacement text for a parameter +entity, both must be contained in the same replacement text. For +interoperability, if a parameter-entity reference appears in a +choice, seq, or Mixed construct, its replacement text should not +be empty, and neither the first nor last non-blank character of +the replacement text should be a connector (| or ,).

an XML parser context  the tree of xmlElementContentPtr describing the element -hierarchy. 


an XML parser context  the name of the element being defined.  the Element Content pointer will be stored here if any  the type of element content XML_ELEMENT_TYPE_xxx 


[45] elementdecl ::= '<!ELEMENT' S Name S contentspec S? '>'

TODO There is a check [ VC: Unique Element Type Declaration ]

[ VC: Unique Element Type Declaration ] +TODO No element type may be declared more than once

an XML parser context the type of the element, or -1 in case of error 


[29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl | NotationDecl | PI | Comment

TODO There is a check [ VC: Proper Declaration/PE Nesting ]

[ VC: Proper Declaration/PE Nesting ] +TODO Parameter-entity replacement text must be properly nested with +markup declarations. That is to say, if either the first character +or the last character of a markup declaration (markupdecl above) is +contained in the replacement text for a parameter-entity reference, +both must be contained in the same replacement text.

[ WFC: PEs in Internal Subset ] +In the internal DTD subset, parameter-entity references can occur +only where markup declarations can occur, not within markup declarations. +(This does not apply to references that occur in external parameter +entities or to the external subset.)

an XML parser context 


x' [0-9a-fA-F]+ ';'

[ WFC: Legal Character ] +Characters referred to using character references must match the +production for Char.

an XML parser context the value parsed (as an int) 


[68] EntityRef ::= '&' Name ';'

[ WFC: Entity Declared ] +In a document without any DTD, a document with only an internal DTD +subset which contains no parameter entity references, or a document +with "standalone='yes'", the Name given in the entity reference +must match that in an entity declaration, except that well-formed +documents need not declare any of the following entities: amp, lt, +gt, apos, quot. The declaration of a parameter entity must precede +any reference to it. Similarly, the declaration of a general entity +must precede any reference to it which appears in a default value in an +attribute-list declaration. Note that if entities are declared in the +external subset or in external parameter entities, a non-validating +processor is not obligated to read and process their declarations; +for such documents, the rule that an entity must be declared is a +well-formedness constraint only if standalone='yes'.

[ WFC: Parsed Entity ] +An entity reference must not contain the name of an unparsed entity

an XML parser context the xmlEntityPtr if found, or NULL otherwise. 


an XML parser context 


[69] PEReference ::= '%' Name ';'

[ WFC: No Recursion ] +TODO A parsed entity must not contain a recursive +reference to itself, either directly or indirectly.

[ WFC: Entity Declared ] +In a document without any DTD, a document with only an internal DTD +subset which contains no parameter entity references, or a document +with "standalone='yes'", ... ... The declaration of a parameter +entity must precede any reference to it...

[ VC: Entity Declared ] +In a document with an external subset or external parameter entities +with "standalone='no'", ... ... The declaration of a parameter entity +must precede any reference to it...

[ WFC: In DTD ] +Parameter-entity references may only appear in the DTD. +NOTE: misleading but this is handled.

an XML parser context 


[28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? ('[' (markupdecl | PEReference | S)* ']' S?)? '>'

[ VC: Root Element Type ] +The Name in the document type declaration must match the element +type of the root element.

an XML parser context 


[41] Attribute ::= Name Eq AttValue

[ WFC: No External Entity References ] +Attribute values cannot contain direct or indirect entity references +to external entities.

[ WFC: No < in Attribute Values ] +The replacement text of any entity referred to directly or indirectly in +an attribute value (other than "&lt;") must not contain a <.

[ VC: Attribute Value Type ] +TODO The attribute must have been declared; the value must be of the type +declared for it.

[25] Eq ::= S? '=' S?

With namespace:

an XML parser context  a CHAR ** used to store the value of the attribute the attribute name, and the value in *value. 


[40] STag ::= '<' Name (S Attribute)* S? '>'

[ WFC: Unique Att Spec ] +No attribute name may appear more than once in the same start-tag or +empty-element tag.

[44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'

[ WFC: Unique Att Spec ] +No attribute name may appear more than once in the same start-tag or +empty-element tag.

With namespace:

[NS 8] STag ::= '<' QName (S Attribute)* S? '>'

an XML parser context the element name parsed 


an XML parser context  the tag name as parsed in the opening tag. 


an XML parser context 


an XML parser context 


[39] element ::= EmptyElemTag | STag content ETag

[41] Attribute ::= Name Eq AttValue

[ WFC: Element Type Match ] +The Name in an element's end-tag must match the element type in the +start-tag.

[ VC: Element Valid ] +TODO An element is valid if there is a declaration matching elementdecl +where the Name matches the element type and one of the following holds: +- The declaration matches EMPTY and the element has no content. +- The declaration matches children and the sequence of child elements +belongs to the language generated by the regular expression in the +content model, with optional white space (characters matching the +nonterminal S) between each pair of child elements. +- The declaration matches Mixed and the content consists of character +data and child elements whose types match names in the content model. +- The declaration matches ANY, and the types of any child elements have +been declared.

an XML parser context 


an XML parser context the string giving the XML version number, or NULL 


an XML parser context the version string, e.g. "1.0" 


an XML parser context the encoding name value or NULL 


an XML parser context the encoding value or NULL 


parse the XML standalone declaration

[32] SDDecl ::= S 'standalone' Eq -(("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no')'"'))

[ VC: Standalone Document Declaration ] +TODO The standalone document declaration must have the value "no" +if any external markup declarations contain declarations of: +- attributes with default values, if elements to which these +attributes apply appear in the document without specifications +of values for these attributes, or +- entities (other than amp, lt, gt, apos, quot), if references +to those entities appear in the document, or +- attributes with values subject to normalization, where the +attribute appears in the document with a value which will change +as a result of normalization, or +- element types with element content, if white space occurs directly +within any instance of those types.

an XML parser context 1 if standalone, 0 otherwise 


an XML parser context 


an XML parser context 


xmlParseExternalSubset ()

void        xmlParseExternalSubset          (xmlParserCtxtPtr ctxt,
+                                             const CHAR *ExternalID,
+                                             const CHAR *SystemID);

parse Markup declarations from an external subset

[30] extSubset ::= textDecl? extSubsetDecl

[31] extSubsetDecl ::= (markupdecl | conditionalSect | PEReference | S) *

TODO There is a check [ VC: Proper Declaration/PE Nesting ]

ctxt : 
ExternalID : 
SystemID : 


#define XML_SUBSTITUTE_NONE	0
#define XML_SUBSTITUTE_NONE

#define XML_SUBSTITUTE_REF	1
#define XML_SUBSTITUTE_REF

#define XML_SUBSTITUTE_PEREF	2
#define XML_SUBSTITUTE_PEREF

#define XML_SUBSTITUTE_BOTH 	3
#define XML_SUBSTITUTE_BOTH

the parser context  the len to decode (in bytes !), -1 for no size limit  combination of XML_SUBSTITUTE_REF and XML_SUBSTITUTE_PEREF  an end marker CHAR, 0 if none  an end marker CHAR, 0 if none  an end marker CHAR, 0 if none A newly allocated string with the substitution done. The caller -must deallocate it ! 





Name

Synopsis

xmlNodePtr xmlNewCDataBlock (xmlDocPtr doc, + const CHAR *content, + int len); +xmlNodePtr xmlNewReference (

Description

Details



xmlNotationPtr

typedef xmlNotation *xmlNotationPtr;




xmlEnumerationPtr

typedef xmlEnumeration *xmlEnumerationPtr;


xmlAttributePtr

typedef xmlAttribute *xmlAttributePtr;




xmlElementContentPtr

typedef xmlElementContent *xmlElementContentPtr;



xmlElementPtr

typedef xmlElement *xmlElementPtr;



xmlNsPtr

typedef xmlNs *xmlNsPtr;


xmlDtdPtr

typedef xmlDtd *xmlDtdPtr;


xmlAttrPtr

typedef xmlAttr *xmlAttrPtr;


xmlNode

typedef _xmlNode xmlNode;


xmlNodePtr

typedef _xmlNode *xmlNodePtr;


xmlDoc

typedef _xmlDoc xmlDoc;


xmlDocPtr

typedef xmlDoc *xmlDocPtr;


xmlBuffer

typedef _xmlBuffer xmlBuffer;


xmlBufferPtr

typedef xmlBuffer *xmlBufferPtr;





the new structure. 


the buffer to free 


the file output  the buffer to dump the number of CHAR written 


the buffer to dump  the CHAR string  the number of CHAR to add 


the buffer to dump  the CHAR string 


the buffer to dump  the C char string 


the buffer to dump  the number of CHAR to remove the number of CHAR removed, or -1 in case of failure. 


the buffer 


the document pointer  the DTD name  the external ID  the system ID a pointer to the new DTD structure 


the document pointer  the DTD name  the external ID  the system ID a pointer to the new DTD structure 


the DTD structure to free up 


the document carrying the namespace  the URI associated  the prefix for the namespace returns a new namespace pointer 


the element carrying the namespace  the URI associated  the prefix for the namespace returns a new namespace pointer 


the namespace pointer 


CHAR string giving the version of XML "1.0" a new document 


pointer to the document -@:  


the document  the name of the attribute  the value of the attribute a pointer to the attribute 


the holding node  the name of the attribute  the value of the attribute a pointer to the attribute 


the first property in the list 


the first property in the list 


the attribute  a new xmlAttrPtr, or NULL in case of error. 


the first attribute  a new xmlAttrPtr, or NULL in case of error. 


the dtd  a new xmlDtdPtr, or NULL in case of error. 


the document  if 1 do a recursive copy.  a new xmlDocPtr, or NULL in case of error. 


the document  namespace if any  the node name  the text content if any a pointer to the new node object. 


namespace if any  the node name a pointer to the new node object. 


the parent node  a namespace if any  the name of the child  the content of the child if any. a pointer to the new node object. 


the document  the text content a pointer to the new node object. 


the text content a pointer to the new node object. 


the document  the text content  the text len. a pointer to the new node object. 


the text content  the text len. a pointer to the new node object. 


the document  the comment content a pointer to the new node object. 


the comment content a pointer to the new node object. 


xmlNewCDataBlock ()

xmlNodePtr  xmlNewCDataBlock                (xmlDocPtr doc,
+                                             const CHAR *content,
+                                             int len);

Creation of a new node containing a CData block.

doc : 
content : 
len : 
Returns : 


the document  the reference name, or the reference string with & and ; a pointer to the new node object. 


the node  if 1 do a recursive copy.  a new xmlNodePtr, or NULL in case of error. 


the first node in the list.  a new xmlNodePtr, or NULL in case of error. 


the parent node the last child or NULL if none. 


the node 1 yes, 0 no 


the parent node  the child node the child or NULL in case of error. 


the node 


the first text node  the second text node being merged the first text node augmented 


the node  the content  content lenght 


the first node in the list 


the node 


the document  the current node  the namespace string the namespace pointer or NULL. 


the document  the current node  the namespace value the namespace pointer or NULL. 


a node in the document  a namespace pointer 


the namespace  a new xmlNsPtr, or NULL in case of error. 


the first namespace  a new xmlNsPtr, or NULL in case of error. 


the node  the attribute name  the attribute value the attribute pointer. 


the node  the attribute name the attribute value or NULL if not found. 


the document  the value of the attribute a pointer to the first child 


the document  the value of the text  the length of the string value a pointer to the first child 


the document  a Node list  should we replace entity contents or show their external form a pointer to the string copy, the calller must free it. 


the node being modified  the new value of the content 


the node being modified  the new value of the content  the size of content 


the node being modified  extra content 


the node being modified  extra content  the size of content 


the node being read a new CHAR * or NULL if no content is available. -It's up to the caller to free the memory. 


the XML buffer  the string to add 


the XML buffer output  the string to add 


the XML buffer output  the string to add 


the document  OUT: the memory pointer  OUT: the memory lenght 


the FILE*  the document 


the filename  the document  the number of file written or -1 in case of failure. 


the document 0 (uncompressed) to 9 (max compression) 


the document  the compression ratio 


0 (uncompressed) to 9 (max compression) 


the compression ratio 

Name

Synopsis

+void (*xmlValidityErrorFunc) (void *ctx, + const char *msg, + ...); +void (*xmlValidityWarningFunc) (void *ctx, + const char *msg, + ...); +void xmlParserValidityError (void *ctx, + const char *msg, + ...); +void xmlParserValidityWarning (void *ctx, + const char *msg, + ...); #define XML_MIN_NOTATION_TABLE xmlAddNotationDecl ( (xmlValidCtxtPtr ctxt, + xmlDtdPtr dtd, @@ -246,7 +274,11 @@ HREF="gnome-xml-tree.html#XMLELEMENTPTR" > xmlAddElementDecl ( (xmlValidCtxtPtr ctxt, + xmlDtdPtr dtd, @@ -320,7 +352,11 @@ HREF="gnome-xml-tree.html#XMLATTRIBUTEPTR" > xmlAddAttributeDecl ( (xmlValidCtxtPtr ctxt, + xmlDtdPtr dtd, @@ -369,7 +405,153 @@ HREF="gnome-xml-tree.html#XMLBUFFERPTR" xmlAttributeTablePtr table); table); +int xmlValidateRoot (xmlValidCtxtPtr ctxt, + xmlDocPtr doc); +int xmlValidateElementDecl (xmlValidCtxtPtr ctxt, + xmlDocPtr doc, + xmlElementPtr elem); +int xmlValidateAttributeDecl (xmlValidCtxtPtr ctxt, + xmlDocPtr doc, + xmlAttributePtr attr); +int xmlValidateNotationDecl (xmlValidCtxtPtr ctxt, + xmlDocPtr doc, + xmlNotationPtr nota); +int xmlValidateDtd (xmlValidCtxtPtr ctxt, + xmlDocPtr doc, + xmlDtdPtr dtd); +int xmlValidateDocument (xmlValidCtxtPtr ctxt, + xmlDocPtr doc); +int xmlValidateElement (xmlValidCtxtPtr ctxt, + xmlDocPtr doc, + xmlNodePtr elem); +int xmlValidateOneElement (xmlValidCtxtPtr ctxt, + xmlDocPtr doc, + xmlNodePtr elem); +int xmlValidateOneAttribute (xmlValidCtxtPtr ctxt, + xmlDocPtr doc, + xmlNodePtr elem, + xmlAttrPtr attr, + const CHAR *value); +int xmlIsMixedElement (xmlDocPtr doc, + const CHAR *name);

Description

Details

xmlValidityErrorFunc ()

void        (*xmlValidityErrorFunc)         (void *ctx,
+                                             const char *msg,
+                                             ...);

ctx : 
msg : 
... : 


xmlValidityWarningFunc ()

void        (*xmlValidityWarningFunc)       (void *ctx,
+                                             const char *msg,
+                                             ...);

ctx : 
msg : 
... : 


xmlParserValidityError ()

void        xmlParserValidityError          (void *ctx,
+                                             const char *msg,
+                                             ...);

Display and format an validity error messages, gives file, +line, position and extra parameters.

ctx : 
msg : 
... : 


xmlParserValidityWarning ()

void        xmlParserValidityWarning        (void *ctx,
+                                             const char *msg,
+                                             ...);

Display and format a validity warning messages, gives file, line, +position and extra parameters.

ctx : 
msg : 
... : 


#define XML_MIN_NOTATION_TABLE	32
#define XML_MIN_NOTATION_TABLE

xmlNotationTablePtr

typedef xmlNotationTable *xmlNotationTablePtr;


#define XML_MIN_ELEMENT_TABLE	32
#define XML_MIN_ELEMENT_TABLE

xmlElementTablePtr

typedef xmlElementTable *xmlElementTablePtr;


#define XML_MIN_ATTRIBUTE_TABLE	32
#define XML_MIN_ATTRIBUTE_TABLE

xmlAttributeTablePtr

typedef xmlAttributeTable *xmlAttributeTablePtr;


xmlNotationPtr xmlAddNotationDecl ( xmlAddNotationDecl (xmlValidCtxtPtr ctxt, + xmlDtdPtr dtd, @@ -611,6 +1140,23 @@ VALIGN="TOP" >ctxt : dtd : pointer to the DTD  the entity name  the public identifier or NULL  the system identifier or NULL NULL if not, othervise the entity 


A notation table the new xmlNotationTablePtr or NULL in case of error. 


An notation table 


the XML buffer output  A notation table 


the subelement name or NULL  the type of element content decl NULL if not, othervise the new element content structure 


An element content pointer. the new xmlElementContentPtr or NULL in case of error. 


the element content tree to free 


xmlElementPtr xmlAddElementDecl ( xmlAddElementDecl (xmlValidCtxtPtr ctxt, + xmlDtdPtr dtd, @@ -1223,6 +1773,23 @@ VALIGN="TOP" >ctxt : dtd : pointer to the DTD  the entity name  the element type  the element content tree or NULL NULL if not, othervise the entity 


An element table the new xmlElementTablePtr or NULL in case of error. 


An element table 


the XML buffer output  An element table 


the enumeration name or NULL the xmlEnumerationPtr just created or NULL in case -of error. 


the tree to free. 


the tree to copy. the xmlEnumerationPtr just created or NULL in case -of error. 


xmlAttributePtr xmlAddAttributeDecl ( xmlAddAttributeDecl (xmlValidCtxtPtr ctxt, + xmlDtdPtr dtd, @@ -1828,6 +2397,23 @@ VALIGN="TOP" >ctxt : dtd : pointer to the DTD  the element name  the attribute name  the attribute type  the attribute default type  the attribute default value  if it's an enumeration, the associated list NULL if not, othervise the entity 


An attribute table the new xmlAttributeTablePtr or NULL in case of error. 



xmlValidateRoot ()

int         xmlValidateRoot                 (xmlValidCtxtPtr ctxt,
+                                             xmlDocPtr doc);

Try to validate a the root element +basically it does the following check as described by the +XML-1.0 recommendation: +- [ VC: Root Element Type ] +it doesn't try to recurse or apply other check to the element

ctxt : 
doc : 
Returns : 


xmlValidateElementDecl ()

int         xmlValidateElementDecl          (xmlValidCtxtPtr ctxt,
+                                             xmlDocPtr doc,
+                                             xmlElementPtr elem);

Try to validate a single element definition +basically it does the following checks as described by the +XML-1.0 recommendation: +- [ VC: One ID per Element Type ] +- [ VC: No Duplicate Types ] +- [ VC: Unique Element Type Declaration ]

ctxt : 
doc : 
elem : 
Returns : 


xmlValidateAttributeDecl ()

int         xmlValidateAttributeDecl        (xmlValidCtxtPtr ctxt,
+                                             xmlDocPtr doc,
+                                             xmlAttributePtr attr);

Try to validate a single attribute definition +basically it does the following checks as described by the +XML-1.0 recommendation: +- [ VC: Attribute Default Legal ] +- [ VC: Enumeration ] +- [ VC: ID Attribute Default ]

The ID/IDREF uniqueness and matching are done separately

ctxt : 
doc : 
attr : 
Returns : 


xmlValidateNotationDecl ()

int         xmlValidateNotationDecl         (xmlValidCtxtPtr ctxt,
+                                             xmlDocPtr doc,
+                                             xmlNotationPtr nota);

Try to validate a single notation definition +basically it does the following checks as described by the +XML-1.0 recommendation: +- it seems that no validity constraing exist on notation declarations +But this function get called anyway ...

ctxt : 
doc : 
nota : 
Returns : 


xmlValidateDtd ()

int         xmlValidateDtd                  (xmlValidCtxtPtr ctxt,
+                                             xmlDocPtr doc,
+                                             xmlDtdPtr dtd);

Try to validate the dtd instance

basically it does check all the definitions in the DtD.

ctxt : 
doc : 
dtd : 
Returns : 


xmlValidateDocument ()

int         xmlValidateDocument             (xmlValidCtxtPtr ctxt,
+                                             xmlDocPtr doc);

Try to validate the document instance

basically it does the all the checks described by the +i.e. validates the internal and external subset (if present) +and validate the document tree.

ctxt : 
doc : 
Returns : 


xmlValidateElement ()

int         xmlValidateElement              (xmlValidCtxtPtr ctxt,
+                                             xmlDocPtr doc,
+                                             xmlNodePtr elem);

Try to validate the subtree under an element

ctxt : 
doc : 
elem : 
Returns : 


xmlValidateOneElement ()

int         xmlValidateOneElement           (xmlValidCtxtPtr ctxt,
+                                             xmlDocPtr doc,
+                                             xmlNodePtr elem);

Try to validate a single element and it's attributes, +basically it does the following checks as described by the +XML-1.0 recommendation: +- [ VC: Element Valid ] +- [ VC: Required Attribute ] +Then call xmlValidateOneAttribute() for each attribute present.

The ID/IDREF checkings are done separately

ctxt : 
doc : 
elem : 
Returns : 


xmlValidateOneAttribute ()

int         xmlValidateOneAttribute         (xmlValidCtxtPtr ctxt,
+                                             xmlDocPtr doc,
+                                             xmlNodePtr elem,
+                                             xmlAttrPtr attr,
+                                             const CHAR *value);

Try to validate a single attribute for an element +basically it * does the following checks as described by the +XML-1.0 recommendation: +- [ VC: Attribute Value Type ] +- [ VC: Fixed Attribute Default ] +- [ VC: Entity Name ] +- [ VC: Name Token ] +- [ VC: ID ] +- [ VC: IDREF ] +- [ VC: Entity Name ] +- [ VC: Notation Attributes ]

The ID/IDREF uniqueness and matching are done separately

ctxt : 
doc : 
elem : 
attr : 
value : 
Returns : 


xmlIsMixedElement ()

int         xmlIsMixedElement               (xmlDocPtr doc,
+                                             const CHAR *name);

Search in the DtDs whether an element accept Mixed content (or ANY) +basically if it is supposed to accept text childs

doc : 
name : 
Returns : 

Name

Synopsis

Description

Details

an XML parser context  the message to display/transmit  extra parameters for the message display 


an XML parser context  the message to display/transmit  extra parameters for the message display 

Name

Synopsis

Description

Details

#define XPATH_UNDEFINED	0
#define XPATH_UNDEFINED

#define XPATH_NODESET	1
#define XPATH_NODESET

#define XPATH_BOOLEAN	2
#define XPATH_BOOLEAN

#define XPATH_NUMBER	3
#define XPATH_NUMBER

#define XPATH_STRING	4
#define XPATH_STRING


the XML document  the variable list  the function list  the namespace list the xmlXPathContext just allocated. 


the context to free 


the XPath expression  the XPath context the xmlXPathObjectPtr resulting from the eveluation or NULL. -the caller has to free the object. 


the object to free 


the XPath expression  the XPath context the xmlXPathObjectPtr resulting from the eveluation or NULL. -the caller has to free the object. 

+ @@ -12,6 +13,7 @@ + @@ -28,6 +30,7 @@ + @@ -133,6 +136,7 @@ + @@ -184,6 +188,7 @@ + @@ -191,6 +196,10 @@ + + + + @@ -215,10 +224,23 @@ + + + + + + + + + + + + + @@ -235,6 +257,8 @@ + + @@ -247,6 +271,7 @@ + @@ -289,6 +314,7 @@ + diff --git a/doc/xml.html b/doc/xml.html index 03abc155..edeb391e 100644 --- a/doc/xml.html +++ b/doc/xml.html @@ -1,23 +1,54 @@ + "http://www.w3.org/TR/REC-html40/loose.dtd"> -The XML library for Gnome - + The XML library for Gnome + - +

The XML library for Gnome

-

-This document describes the XML library -provideed in the Gnome framework. XML is a -standard to build tag based structured documents. The internal document -repesentation is as close as possible to the DOM interfaces.

+ +

This document describes the XML +library provideed in the Gnome framework. +XML is a standard to build tag based structured documents/data.

+ +

The internal document repesentation is as close as possible to the DOM interfaces.

+ +

Libxml also has a SAX +interface, James Henstridge made a nice +documentation expaining how to use it. The interface is as compatible as +possible with Expat +one.

+ +

The code is commented in a way which allow extensive documentation +to be automatically extracted.

+ +

There is also a mailing-list xml@rufus.w3.org for libxml, with an on-line archive. To +subscribe to this majordomo based list, send a mail to majordomo@rufus.w3.org with "subscribe xml" +in the content of the message.

+ +

This library is released both under the W3C Copyright and the GNU LGP, +basically everybody should be happy, if not, drop me a mail.

+ +

People are invited to use the gdome Gnome module to get a +full DOM interface, thanks to Raph +Levien, check his DOMination paper. He +uses it for his implementation of SVG called gill.

xml

-

-XML is a standard for markup based structured documents, here is XML is a standard for markup based structured documents, here is an example:

<?xml version="1.0"?>
 <EXAMPLE prop1="gnome is great" prop2="&amp; linux too">
@@ -31,17 +62,17 @@ name="example">an example:

<p>...</p> </chapter> </EXAMPLE>
-

-The first line specify that it's an XML document and gives useful informations -about it's encoding. Then the document is a text format whose structure is -specified by tags between brackets. Each tag opened have to be -closed XML is pedantic about this, not that for example the image -tag has no content (just an attribute) and is closed by ending up the tag -with />.

+ +

The first line specify that it's an XML document and gives useful +informations about it's encoding. Then the document is a text format whose +structure is specified by tags between brackets. Each tag opened have +to be closed XML is pedantic about this, not that for example the +image tag has no content (just an attribute) and is closed by ending up the +tag with />.

The tree output

-

-The parser returns a tree built during the document analysis. The value + +

The parser returns a tree built during the document analysis. The value returned is an xmlDocPtr (i.e. a pointer to an xmlDoc structure). This structure contains informations like the file name, the document type, and a root pointer which @@ -50,13 +81,13 @@ which is the document). The tree is made of xmlNodes, chained in double linked lists of siblings and with childs<->parent relationship. An xmlNode can also carry properties (a chain of xmlAttr structures). An attribute may have a value which is a list of TEXT or ENTITY_REF nodes.

-

-Here is an example (erroneous w.r.t. the XML spec since there should be only -one ELEMENT under the root):

-

- structure.gif

-

-In the source package there is a small program (not installed by default) + +

Here is an example (erroneous w.r.t. the XML spec since there should be +only one ELEMENT under the root):

+ +

 structure.gif

+ +

In the source package there is a small program (not installed by default) called tester which parses XML files given as argument and prints them back as parsed, this is useful to detect errors both in XML code and in the XML parser itself. It has an option --debug which @@ -91,12 +122,12 @@ standalone=true ELEMENT p TEXT content=... -

-This should be useful to learn the internal representation model.

+ +

This should be useful to learn the internal representation model.

The XML library interfaces

-

-This section is directly intended to help programmers getting bootstrapped + +

This section is directly intended to help programmers getting bootstrapped using the XML library from the C language. It doesn't intent to be extensive, I hope the automatically generated docs will provide the completeness required, but as a separated set of documents. The interfaces of the XML @@ -105,35 +136,33 @@ interested in a higher level API should look at DOM (unfortunately not completed).

Invoking the parser

-

-Usually, the first thing to do is to read an XML input, the parser accepts to -parse both memory mapped documents or direct files. The functions are defined -in "parser.h":

+ +

Usually, the first thing to do is to read an XML input, the parser accepts +to parse both memory mapped documents or direct files. The functions are +defined in "parser.h":

-
xmlDocPtr xmlParseMemory(char *buffer, int size);
-

-parse a zero terminated string containing the document

-
+
xmlDocPtr xmlParseMemory(char *buffer, int size);
+

parse a zero terminated string containing the document

+
-
xmlDocPtr xmlParseFile(const char *filename);
-

-parse an XML document contained in a file (possibly compressed)

-
+
xmlDocPtr xmlParseFile(const char *filename);
+

parse an XML document contained in a file (possibly compressed)

+
-

-This returns a pointer to the document structure (or NULL in case of + +

This returns a pointer to the document structure (or NULL in case of failure).

-

-A couple of comments can be made, first this mean that the parser is + +

A couple of comments can be made, first this mean that the parser is memory-hungry, first to load the document in memory, second to build the tree. Reading a document without building the tree will be possible in the future by pluggin the code to the SAX interface (see SAX.c).

Building a tree from scratch

-

-The other way to get an XML tree in memory is by building it. Basically there -is a set of functions dedicated to building new elements, those are also + +

The other way to get an XML tree in memory is by building it. Basically +there is a set of functions dedicated to building new elements, those are also described in "tree.h", here is for example the piece of code producing the example used before:

    xmlDocPtr doc;
@@ -150,129 +179,120 @@ example used before:

subtree = xmlNewChild(tree, NULL, "p", "bla bla bla ..."); subtree = xmlNewChild(tree, NULL, "image", NULL); xmlSetProp(subtree, "href", "linus.gif");
-

-Not really rocket science ...

+ +

Not really rocket science ...

Traversing the tree

-

-Basically by including "tree.h" your code has access to the internal structure -of all the element of the tree. The names should be somewhat simple like -parent, childs, next, + +

Basically by including "tree.h" your code has access to the internal +structure of all the element of the tree. The names should be somewhat simple +like parent, childs, next, prev, properties, etc... For example still with the previous example:

doc->root->childs->childs
-

-points to the title element,

+ +

points to the title element,

doc->root->childs->next->child->child
-

-points to the text node containing the chapter titlle "The Linux adventure" + +

points to the text node containing the chapter titlle "The Linux adventure" and

doc->root->properties->next->val
-

-points to the entity reference containing the value of "&linux" at the + +

points to the entity reference containing the value of "&linux" at the beginning of the second attribute of the root element "EXAMPLE".

Modifying the tree

-

-functions are provided to read and write the document content:

+ +

functions are provided to read and write the document content:

-
xmlAttrPtr xmlSetProp(xmlNodePtr node, const CHAR *name, const CHAR -*value);
-

-This set (or change) an attribute carried by an ELEMENT node the value can be -NULL

-
+
xmlAttrPtr xmlSetProp(xmlNodePtr node, const CHAR *name, const + CHAR *value);
+

This set (or change) an attribute carried by an ELEMENT node the + value can be NULL

+
-
const CHAR *xmlGetProp(xmlNodePtr node, const CHAR -*name);
-

-This function returns a pointer to the property content, note that no extra -copy is made

-
+
const CHAR *xmlGetProp(xmlNodePtr node, const CHAR + *name);
+

This function returns a pointer to the property content, note that + no extra copy is made

+
-

-Two functions must be used to read an write the text associated to + +

Two functions must be used to read an write the text associated to elements:

-
xmlNodePtr xmlStringGetNodeList(xmlDocPtr doc, const CHAR -*value);
-

-This function takes an "external" string and convert it to one text node or -possibly to a list of entity and text nodes. All non-predefined entity -references like &Gnome; will be stored internally as an entity node, hence -the result of the function may not be a single node.

-
+
xmlNodePtr xmlStringGetNodeList(xmlDocPtr doc, const CHAR + *value);
+

This function takes an "external" string and convert it to one text + node or possibly to a list of entity and text nodes. All non-predefined + entity references like &Gnome; will be stored internally as an + entity node, hence the result of the function may not be a single + node.

+
-
CHAR *xmlNodeListGetString(xmlDocPtr doc, xmlNodePtr list, int -inLine);
-

-this is the dual function, which generate a new string containing the content -of the text and entity nodes. Note the extra argument inLine, if set to 1 -instead of returning the &Gnome; XML encoding in the string it will -substitute it with it's value say "GNU Network Object Model Environment". Set -it if you want to use the string for non XML usage like User Interface.

-
+
CHAR *xmlNodeListGetString(xmlDocPtr doc, xmlNodePtr list, int + inLine);
+

this is the dual function, which generate a new string containing + the content of the text and entity nodes. Note the extra argument + inLine, if set to 1 instead of returning the &Gnome; XML encoding in + the string it will substitute it with it's value say "GNU Network Object + Model Environment". Set it if you want to use the string for non XML + usage like User Interface.

+

Saving a tree

-

-Basically 3 options are possible:

+ +

Basically 3 options are possible:

-
void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int -*size);
-

-returns a buffer where the document has been saved

-
+
void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int + *size);
+

returns a buffer where the document has been saved

+
-
extern void xmlDocDump(FILE *f, xmlDocPtr doc);
-

-dumps a buffer to an open file descriptor

-
+
extern void xmlDocDump(FILE *f, xmlDocPtr doc);
+

dumps a buffer to an open file descriptor

+
-
int xmlSaveFile(const char *filename, xmlDocPtr cur);
-

-save the document ot a file. In that case the compression interface is -triggered if turned on

-
+
int xmlSaveFile(const char *filename, xmlDocPtr cur);
+

save the document ot a file. In that case the compression interface + is triggered if turned on

+

Compression

-

-The library handle transparently compression when doing file based accesses, -the level of compression on saves can be tuned either globally or individually -for one file:

+ +

The library handle transparently compression when doing file based +accesses, the level of compression on saves can be tuned either globally or +individually for one file:

-
int xmlGetDocCompressMode (xmlDocPtr doc);
-

-Get the document compression ratio (0-9)

-
+
int xmlGetDocCompressMode (xmlDocPtr doc);
+

Get the document compression ratio (0-9)

+
-
void xmlSetDocCompressMode (xmlDocPtr doc, int mode);
-

-Set the document compression ratio

-
+
void xmlSetDocCompressMode (xmlDocPtr doc, int mode);
+

Set the document compression ratio

+
-
int xmlGetCompressMode(void);
-

-Get the default compression ratio

-
+
int xmlGetCompressMode(void);
+

Get the default compression ratio

+
-
void xmlSetCompressMode(int mode);
-

-set the default compression ratio

-
+
void xmlSetCompressMode(int mode);
+

set the default compression ratio

+

DOM Principles

-

-DOM stands for the Document Object + +

DOM stands for the Document Object Model this is an API for accessing XML or HTML structured documents. Native support for DOM in Gnome is on the way (module gnome-dom), and it will be based on gnome-xml. This will be a far cleaner interface to manipulate XML @@ -280,20 +300,20 @@ files within Gnome since it won't expose the internal structure. DOM defiles a set of IDL (or Java) interfaces allowing to traverse and manipulate a document. The DOM library will allow accessing and modifying "live" documents presents on other programs like this:

-

- DOM.gif

-

-This should help greatly doing things like modifying a gnumeric spreadsheet + +

 DOM.gif

+ +

This should help greatly doing things like modifying a gnumeric spreadsheet embedded in a GWP document for example.

A real example

-

-Here is a real size example, where the actual content of the application data -is not kept in the DOM tree but uses internal structures. It is based on + +

Here is a real size example, where the actual content of the application +data is not kept in the DOM tree but uses internal structures. It is based on a proposal to keep a database of jobs related to Gnome, with an XML based -storage structure. Here is an XML encoded jobs base: -

-<?xml version="1.0"?>
+storage structure. Here is an XML encoded jobs
+base:

+
<?xml version="1.0"?>
 <gjob:Helping xmlns:gjob="http://www.gnome.org/some-location">
   <gjob:Jobs>
 
@@ -303,8 +323,8 @@ storage structure. Here is an XML encoded jobs base:
       <gjob:Category>Development</gjob:Category>
 
       <gjob:Update>
-	<gjob:Status>Open</gjob:Status>
-	<gjob:Modified>Mon, 07 Jun 1999 20:27:45 -0400 MET DST</gjob:Modified>
+        <gjob:Status>Open</gjob:Status>
+        <gjob:Modified>Mon, 07 Jun 1999 20:27:45 -0400 MET DST</gjob:Modified>
         <gjob:Salary>USD 0.00</gjob:Salary>
       </gjob:Update>
 
@@ -315,17 +335,17 @@ storage structure. Here is an XML encoded jobs base:
 
       <gjob:Contact>
         <gjob:Person>Nathan Clemons</gjob:Person>
-	<gjob:Email>nathan@windsofstorm.net</gjob:Email>
+        <gjob:Email>nathan@windsofstorm.net</gjob:Email>
         <gjob:Company>
-	</gjob:Company>
+        </gjob:Company>
         <gjob:Organisation>
-	</gjob:Organisation>
+        </gjob:Organisation>
         <gjob:Webpage>
-	</gjob:Webpage>
-	<gjob:Snailmail>
-	</gjob:Snailmail>
-	<gjob:Phone>
-	</gjob:Phone>
+        </gjob:Webpage>
+        <gjob:Snailmail>
+        </gjob:Snailmail>
+        <gjob:Phone>
+        </gjob:Phone>
       </gjob:Contact>
 
       <gjob:Requirements>
@@ -349,23 +369,18 @@ storage structure. Here is an XML encoded jobs base:
 
   </gjob:Jobs>
 </gjob:Helping>
-
 
-

-While loading the XML file into an internal DOM tree is a matter of calling -only a couple of functions, browsing the tree to gather the informations -and generate the internals structures is harder, and more error prone. -

-

-The suggested principle is to be tolerant with respect to the input -structure. For example the ordering of the attributes is not significant, -Cthe XML specification is clear about it. It's also usually a good idea -to not be dependant of the orders of the childs of a given node, unless it -really makes things harder. Here is some code to parse the informations -for a person: -

-
-/*
+
+

While loading the XML file into an internal DOM tree is a matter of calling +only a couple of functions, browsing the tree to gather the informations and +generate the internals structures is harder, and more error prone.

+ +

The suggested principle is to be tolerant with respect to the input +structure. For example the ordering of the attributes is not significant, Cthe +XML specification is clear about it. It's also usually a good idea to not be +dependant of the orders of the childs of a given node, unless it really makes +things harder. Here is some code to parse the informations for a person:

+
/*
  * A person record
  */
 typedef struct person {
@@ -391,7 +406,7 @@ DEBUG("parsePerson\n");
     ret = (personPtr) malloc(sizeof(person));
     if (ret == NULL) {
         fprintf(stderr,"out of memory\n");
-	return(NULL);
+        return(NULL);
     }
     memset(ret, 0, sizeof(person));
 
@@ -399,38 +414,36 @@ DEBUG("parsePerson\n");
     cur = cur->childs;
     while (cur != NULL) {
         if ((!strcmp(cur->name, "Person")) && (cur->ns == ns))
-	    ret->name = xmlNodeListGetString(doc, cur->childs, 1);
+            ret->name = xmlNodeListGetString(doc, cur->childs, 1);
         if ((!strcmp(cur->name, "Email")) && (cur->ns == ns))
-	    ret->email = xmlNodeListGetString(doc, cur->childs, 1);
-	cur = cur->next;
+            ret->email = xmlNodeListGetString(doc, cur->childs, 1);
+        cur = cur->next;
     }
 
     return(ret);
-}
-
-

-Here is a couple of things to notice:

+}
+ +

Here is a couple of things to notice:

    -
  • Usually a recursive parsing style is the more convenient one, -XML data being by nature subject to repetitive constructs and usualy exibit -highly stuctured patterns. -
  • The two arguments of type xmlDocPtr and xmlNsPtr, i.e. -the pointer to the global XML document and the namespace reserved to the -application. Document wide information are needed for example to decode -entities and it's a good coding practice to define a namespace for your -application set of data and test that the element and attributes you're -analyzing actually pertains to your application space. This is done by a simple -equality test (cur->ns == ns). -
  • To retrieve text and attributes value, it is suggested to use -the function xmlNodeListGetString to gather all the text and -entity reference nodes generated by the DOM output and produce an -single text string. +
  • Usually a recursive parsing style is the more convenient one, XML data + being by nature subject to repetitive constructs and usualy exibit highly + stuctured patterns.
  • +
  • The two arguments of type xmlDocPtr and xmlNsPtr, i.e. + the pointer to the global XML document and the namespace reserved to the + application. Document wide information are needed for example to decode + entities and it's a good coding practice to define a namespace for your + application set of data and test that the element and attributes you're + analyzing actually pertains to your application space. This is done by a + simple equality test (cur->ns == ns).
  • +
  • To retrieve text and attributes value, it is suggested to use the + function xmlNodeListGetString to gather all the text and entity + reference nodes generated by the DOM output and produce an single text + string.
-

-Here is another piece of code used to parse another level of the structure: -

-
-/*
+
+

Here is another piece of code used to parse another level of the +structure:

+
/*
  * a Description for a Job
  */
 typedef struct job {
@@ -455,7 +468,7 @@ DEBUG("parseJob\n");
     ret = (jobPtr) malloc(sizeof(job));
     if (ret == NULL) {
         fprintf(stderr,"out of memory\n");
-	return(NULL);
+        return(NULL);
     }
     memset(ret, 0, sizeof(job));
 
@@ -464,34 +477,32 @@ DEBUG("parseJob\n");
     while (cur != NULL) {
         
         if ((!strcmp(cur->name, "Project")) && (cur->ns == ns)) {
-	    ret->projectID = xmlGetProp(cur, "ID");
-	    if (ret->projectID == NULL) {
-		fprintf(stderr, "Project has no ID\n");
-	    }
-	}
+            ret->projectID = xmlGetProp(cur, "ID");
+            if (ret->projectID == NULL) {
+                fprintf(stderr, "Project has no ID\n");
+            }
+        }
         if ((!strcmp(cur->name, "Application")) && (cur->ns == ns))
-	    ret->application = xmlNodeListGetString(doc, cur->childs, 1);
+            ret->application = xmlNodeListGetString(doc, cur->childs, 1);
         if ((!strcmp(cur->name, "Category")) && (cur->ns == ns))
-	    ret->category = xmlNodeListGetString(doc, cur->childs, 1);
+            ret->category = xmlNodeListGetString(doc, cur->childs, 1);
         if ((!strcmp(cur->name, "Contact")) && (cur->ns == ns))
-	    ret->contact = parsePerson(doc, ns, cur);
-	cur = cur->next;
+            ret->contact = parsePerson(doc, ns, cur);
+        cur = cur->next;
     }
 
     return(ret);
-}
-
-

-One can notice that once used to it, writing this kind of code -is quite simple, but boring. Ultimately, it could be possble to write -stubbers taking either C data structure definitions, a set of XML examples -or an XML DTD and produce the code needed to import and export the -content between C data and XML storage. This is left as an exercise to -the reader :-)

-

-Feel free to use the code for the full C parsing -example as a template, +}

-Daniel Veillard +

One can notice that once used to it, writing this kind of code is quite +simple, but boring. Ultimately, it could be possble to write stubbers taking +either C data structure definitions, a set of XML examples or an XML DTD and +produce the code needed to import and export the content between C data and +XML storage. This is left as an exercise to the reader :-)

+ +

Feel free to use the code for the full C parsing +example as a template,

+ +

Daniel Veillard

diff --git a/encoding.c b/encoding.c index 8ea34490..1771ec1c 100644 --- a/encoding.c +++ b/encoding.c @@ -23,7 +23,13 @@ #include #include #include "encoding.h" +#ifdef HAVE_UNICODE_H +#include +#endif +#ifdef HAVE_UNICODE_H + +#else /* ! HAVE_UNICODE_H */ /* * From rfc2044: encoding of the Unicode values on UTF-8: * @@ -206,6 +212,7 @@ UTF8ToUTF16(unsigned short* out, int outlen, unsigned char* in, int inlen) return out-outstart; } +#endif /* ! HAVE_UNICODE_H */ /** * xmlDetectCharEncoding: @@ -407,8 +414,11 @@ xmlInitCharEncodingHandlers(void) { return; } xmlNewCharEncodingHandler("UTF-8", NULL, NULL); +#ifdef HAVE_UNICODE_H +#else xmlNewCharEncodingHandler("UTF-16", UTF16ToUTF8, UTF8ToUTF16); xmlNewCharEncodingHandler("ISO-8859-1", isolat1ToUTF8, UTF8Toisolat1); +#endif } /** diff --git a/entities.c b/entities.c index e1ec0af6..f0971d1c 100644 --- a/entities.c +++ b/entities.c @@ -68,7 +68,17 @@ xmlAddEntity(xmlEntitiesTablePtr table, const CHAR *name, int type, * The entity is already defined in this Dtd, the spec says to NOT * override it ... Is it worth a Warning ??? !!! */ - return; + if (((type == XML_INTERNAL_PARAMETER_ENTITY) || + (type == XML_EXTERNAL_PARAMETER_ENTITY)) && + ((cur->type == XML_INTERNAL_PARAMETER_ENTITY) || + (cur->type == XML_EXTERNAL_PARAMETER_ENTITY))) + return; + else + if (((type != XML_INTERNAL_PARAMETER_ENTITY) && + (type != XML_EXTERNAL_PARAMETER_ENTITY)) && + ((cur->type != XML_INTERNAL_PARAMETER_ENTITY) && + (cur->type != XML_EXTERNAL_PARAMETER_ENTITY))) + return; } } if (table->nb_entities >= table->max_entities) { @@ -78,9 +88,9 @@ xmlAddEntity(xmlEntitiesTablePtr table, const CHAR *name, int type, table->max_entities *= 2; table->table = (xmlEntityPtr) realloc(table->table, table->max_entities * sizeof(xmlEntity)); - if (table->table) { + if (table->table == NULL) { perror("realloc failed"); - exit(1); + return; } } cur = &table->table[table->nb_entities]; @@ -218,6 +228,43 @@ xmlAddDocEntity(xmlDocPtr doc, const CHAR *name, int type, xmlAddEntity(table, name, type, ExternalID, SystemID, content); } +/** + * xmlGetParameterEntity: + * @doc: the document referencing the entity + * @name: the entity name + * + * Do an entity lookup in the internal and external subsets and + * returns the corresponding parameter entity, if found. + * + * Returns A pointer to the entity structure or NULL if not found. + */ +xmlEntityPtr +xmlGetParameterEntity(xmlDocPtr doc, const CHAR *name) { + int i; + xmlEntityPtr cur; + xmlEntitiesTablePtr table; + + if ((doc->intSubset != NULL) && (doc->intSubset->entities != NULL)) { + table = (xmlEntitiesTablePtr) doc->intSubset->entities; + for (i = 0;i < table->nb_entities;i++) { + cur = &table->table[i]; + if (((cur->type == XML_INTERNAL_PARAMETER_ENTITY) || + (cur->type == XML_EXTERNAL_PARAMETER_ENTITY)) && + (!xmlStrcmp(cur->name, name))) return(cur); + } + } + if ((doc->extSubset != NULL) && (doc->extSubset->entities != NULL)) { + table = (xmlEntitiesTablePtr) doc->extSubset->entities; + for (i = 0;i < table->nb_entities;i++) { + cur = &table->table[i]; + if (((cur->type == XML_INTERNAL_PARAMETER_ENTITY) || + (cur->type == XML_EXTERNAL_PARAMETER_ENTITY)) && + (!xmlStrcmp(cur->name, name))) return(cur); + } + } + return(NULL); +} + /** * xmlGetDtdEntity: * @doc: the document referencing the entity @@ -238,7 +285,9 @@ xmlGetDtdEntity(xmlDocPtr doc, const CHAR *name) { table = (xmlEntitiesTablePtr) doc->extSubset->entities; for (i = 0;i < table->nb_entities;i++) { cur = &table->table[i]; - if (!xmlStrcmp(cur->name, name)) return(cur); + if ((cur->type != XML_INTERNAL_PARAMETER_ENTITY) && + (cur->type != XML_EXTERNAL_PARAMETER_ENTITY) && + (!xmlStrcmp(cur->name, name))) return(cur); } } return(NULL); @@ -265,7 +314,9 @@ xmlGetDocEntity(xmlDocPtr doc, const CHAR *name) { table = (xmlEntitiesTablePtr) doc->intSubset->entities; for (i = 0;i < table->nb_entities;i++) { cur = &table->table[i]; - if (!xmlStrcmp(cur->name, name)) return(cur); + if ((cur->type != XML_INTERNAL_PARAMETER_ENTITY) && + (cur->type != XML_EXTERNAL_PARAMETER_ENTITY) && + (!xmlStrcmp(cur->name, name))) return(cur); } } if (xmlPredefinedEntities == NULL) @@ -273,7 +324,9 @@ xmlGetDocEntity(xmlDocPtr doc, const CHAR *name) { table = xmlPredefinedEntities; for (i = 0;i < table->nb_entities;i++) { cur = &table->table[i]; - if (!xmlStrcmp(cur->name, name)) return(cur); + if ((cur->type != XML_INTERNAL_PARAMETER_ENTITY) && + (cur->type != XML_EXTERNAL_PARAMETER_ENTITY) && + (!xmlStrcmp(cur->name, name))) return(cur); } return(NULL); @@ -291,8 +344,7 @@ xmlGetDocEntity(xmlDocPtr doc, const CHAR *name) { /* * A buffer used for converting entities to their equivalent and back. * - * TODO: remove this, this helps performances but forbid reentrancy in a - * stupid way. + * TODO: remove this, once we are not afraid of breaking binary compatibility */ static int buffer_size = 0; static CHAR *buffer = NULL; @@ -315,13 +367,10 @@ void growBuffer(void) { * Do a global encoding of a string, replacing the predefined entities * and non ASCII values with their entities and CharRef counterparts. * - * TODO !!!! Once moved to UTF-8 internal encoding, the encoding of non-ascii - * get erroneous. - * - * TODO This routine is not reentrant, the interface - * should not be modified though. + * TODO: remove this, once we are not afraid of breaking binary compatibility * * People must migrate their code to xmlEncodeEntitiesReentrant ! + * This routine will issue a warning when encountered. * * Returns A newly allocated string with the substitution done. */ @@ -329,6 +378,13 @@ const CHAR * xmlEncodeEntities(xmlDocPtr doc, const CHAR *input) { const CHAR *cur = input; CHAR *out = buffer; + static int warning = 1; + + if (warning) { + fprintf(stderr, "Deprecated API xmlEncodeEntities() used\n"); + fprintf(stderr, " change code to use xmlEncodeEntitiesReentrant()\n"); + warning = 0; + } if (input == NULL) return(NULL); if (buffer == NULL) { diff --git a/entities.h b/entities.h index 86040574..180a40c0 100644 --- a/entities.h +++ b/entities.h @@ -66,6 +66,7 @@ void xmlAddDtdEntity(xmlDocPtr doc, const CHAR *name, int type, xmlEntityPtr xmlGetPredefinedEntity(const CHAR *name); xmlEntityPtr xmlGetDocEntity(xmlDocPtr doc, const CHAR *name); xmlEntityPtr xmlGetDtdEntity(xmlDocPtr doc, const CHAR *name); +xmlEntityPtr xmlGetParameterEntity(xmlDocPtr doc, const CHAR *name); const CHAR *xmlEncodeEntities(xmlDocPtr doc, const CHAR *input); CHAR *xmlEncodeEntitiesReentrant(xmlDocPtr doc, const CHAR *input); xmlEntitiesTablePtr xmlCreateEntitiesTable(void); diff --git a/error.c b/error.c index 6d1f57dd..4fbdd987 100644 --- a/error.c +++ b/error.c @@ -10,35 +10,24 @@ #include #include "parser.h" -/** - * xmlParserError: - * @ctx: an XML parser context - * @msg: the message to display/transmit - * @...: extra parameters for the message display - * - * Display and format an error messages, gives file, line, position and - * extra parameters. - */ -void -xmlParserError(void *ctx, const char *msg, ...) -{ - xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; +static void +xmlParserPrintFileInfo(xmlParserInputPtr input) { + if (input != NULL) { + if (input->filename) + fprintf(stderr, "%s:%d: ", input->filename, + input->line); + else + fprintf(stderr, "line %d: ", input->line); + } +} + +static void +xmlParserPrintFileContext(xmlParserInputPtr input) { const CHAR *cur, *base; - va_list args; int n; - va_start(args, msg); - if (ctxt->input->filename) - fprintf(stderr, "%s:%d: ", ctxt->input->filename, - ctxt->input->line); - else - fprintf(stderr, "line %d: ", ctxt->input->line); - - fprintf(stderr, "error: "); - vfprintf(stderr, msg, args); - va_end(args); - cur = ctxt->input->cur; - base = ctxt->input->base; + cur = input->cur; + base = input->base; while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) { cur--; } @@ -53,7 +42,7 @@ xmlParserError(void *ctx, const char *msg, ...) n++; } fprintf(stderr, "\n"); - cur = ctxt->input->cur; + cur = input->cur; while ((*cur == '\n') || (*cur == '\r')) cur--; n = 0; @@ -64,6 +53,36 @@ xmlParserError(void *ctx, const char *msg, ...) fprintf(stderr,"^\n"); } +/** + * xmlParserError: + * @ctx: an XML parser context + * @msg: the message to display/transmit + * @...: extra parameters for the message display + * + * Display and format an error messages, gives file, line, position and + * extra parameters. + */ +void +xmlParserError(void *ctx, const char *msg, ...) +{ + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; + xmlParserInputPtr input; + va_list args; + + input = ctxt->input; + if ((input->filename == NULL) && (ctxt->inputNr > 1)) + input = ctxt->inputTab[ctxt->inputNr - 2]; + + xmlParserPrintFileInfo(input); + + fprintf(stderr, "error: "); + va_start(args, msg); + vfprintf(stderr, msg, args); + va_end(args); + + xmlParserPrintFileContext(input); +} + /** * xmlParserWarning: * @ctx: an XML parser context @@ -77,44 +96,80 @@ void xmlParserWarning(void *ctx, const char *msg, ...) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; - const CHAR *cur, *base; + xmlParserInputPtr input; va_list args; - int n; - va_start(args, msg); - if (ctxt->input->filename) - fprintf(stderr, "%s:%d: ", ctxt->input->filename, - ctxt->input->line); - else - fprintf(stderr, "line %d: ", ctxt->input->line); + input = ctxt->input; + if ((input->filename == NULL) && (ctxt->inputNr > 1)) + input = ctxt->inputTab[ctxt->inputNr - 2]; + + xmlParserPrintFileInfo(input); fprintf(stderr, "warning: "); + va_start(args, msg); vfprintf(stderr, msg, args); va_end(args); - cur = ctxt->input->cur; - base = ctxt->input->base; - while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) { - cur--; - } - n = 0; - while ((n++ < 80) && (cur > base) && (*cur != '\n') && (*cur != '\r')) - cur--; - if ((*cur == '\n') || (*cur == '\r')) cur++; - base = cur; - n = 0; - while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) { - fprintf(stderr, "%c", (unsigned char) *cur++); - n++; - } - fprintf(stderr, "\n"); - cur = ctxt->input->cur; - while ((*cur == '\n') || (*cur == '\r')) - cur--; - n = 0; - while ((cur != base) && (n++ < 80)) { - fprintf(stderr, " "); - base++; - } - fprintf(stderr,"^\n"); + + xmlParserPrintFileContext(input); +} + +/** + * xmlParserValidityError: + * @ctx: an XML parser context + * @msg: the message to display/transmit + * @...: extra parameters for the message display + * + * Display and format an validity error messages, gives file, + * line, position and extra parameters. + */ +void +xmlParserValidityError(void *ctx, const char *msg, ...) +{ + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; + xmlParserInputPtr input; + va_list args; + + input = ctxt->input; + if ((input->filename == NULL) && (ctxt->inputNr > 1)) + input = ctxt->inputTab[ctxt->inputNr - 2]; + + xmlParserPrintFileInfo(input); + + fprintf(stderr, "validity error: "); + va_start(args, msg); + vfprintf(stderr, msg, args); + va_end(args); + + xmlParserPrintFileContext(input); +} + +/** + * xmlParserValidityWarning: + * @ctx: an XML parser context + * @msg: the message to display/transmit + * @...: extra parameters for the message display + * + * Display and format a validity warning messages, gives file, line, + * position and extra parameters. + */ +void +xmlParserValidityWarning(void *ctx, const char *msg, ...) +{ + xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; + xmlParserInputPtr input; + va_list args; + + input = ctxt->input; + if ((input->filename == NULL) && (ctxt->inputNr > 1)) + input = ctxt->inputTab[ctxt->inputNr - 2]; + + xmlParserPrintFileInfo(input); + + fprintf(stderr, "validity warning: "); + va_start(args, msg); + vfprintf(stderr, msg, args); + va_end(args); + + xmlParserPrintFileContext(input); } diff --git a/include/libxml/entities.h b/include/libxml/entities.h index 86040574..180a40c0 100644 --- a/include/libxml/entities.h +++ b/include/libxml/entities.h @@ -66,6 +66,7 @@ void xmlAddDtdEntity(xmlDocPtr doc, const CHAR *name, int type, xmlEntityPtr xmlGetPredefinedEntity(const CHAR *name); xmlEntityPtr xmlGetDocEntity(xmlDocPtr doc, const CHAR *name); xmlEntityPtr xmlGetDtdEntity(xmlDocPtr doc, const CHAR *name); +xmlEntityPtr xmlGetParameterEntity(xmlDocPtr doc, const CHAR *name); const CHAR *xmlEncodeEntities(xmlDocPtr doc, const CHAR *input); CHAR *xmlEncodeEntitiesReentrant(xmlDocPtr doc, const CHAR *input); xmlEntitiesTablePtr xmlCreateEntitiesTable(void); diff --git a/include/libxml/parser.h b/include/libxml/parser.h index 43d183e0..6659cdf7 100644 --- a/include/libxml/parser.h +++ b/include/libxml/parser.h @@ -1,5 +1,5 @@ /* - * parser.h : constants and stuff related to the XML parser. + * parser.h : Interfaces, constants and types related to the XML parser. * * See Copyright for the status of this software. * @@ -10,6 +10,7 @@ #define __XML_PARSER_H__ #include "tree.h" +#include "valid.h" #include "xmlIO.h" #ifdef __cplusplus @@ -21,12 +22,22 @@ extern "C" { */ #define XML_DEFAULT_VERSION "1.0" +/** + * an xmlParserInput is an input flow for the XML processor. + * Each entity parsed is associated an xmlParserInput (except the + * few predefined ones). This is the case both for internal entities + * - in which case the flow is already completely in memory - or + * external entities - in which case we use the buf structure for + * progressive reading and I18N conversions to the internal UTF-8 format. + */ + typedef void (* xmlParserInputDeallocate)(CHAR *); typedef struct xmlParserInput { /* Input buffer */ xmlParserInputBufferPtr buf; /* UTF-8 encoded buffer */ const char *filename; /* The file analyzed, if any */ + const char *directory; /* the directory/base of teh file */ const CHAR *base; /* Base of the array to parse */ const CHAR *cur; /* Current char being parsed */ int line; /* Current line */ @@ -36,6 +47,11 @@ typedef struct xmlParserInput { } xmlParserInput; typedef xmlParserInput *xmlParserInputPtr; +/** + * the parser can be asked to collect Node informations, i.e. at what + * place in the file they were detected. + * NOTE: This is off by default and not very well tested. + */ typedef struct _xmlParserNodeInfo { const struct xmlNode* node; /* Position & line # that text that created the node begins & ends on */ @@ -54,24 +70,63 @@ typedef struct xmlParserNodeInfoSeq { typedef _xmlParserNodeInfoSeq xmlParserNodeInfoSeq; typedef xmlParserNodeInfoSeq *xmlParserNodeInfoSeqPtr; +/** + * The parser is not a state based parser, but we need to maintain + * minimum state informations, especially for entities processing. + */ +typedef enum xmlParserInputState { + XML_PARSER_EOF = 0, + XML_PARSER_PROLOG, + XML_PARSER_CONTENT, + XML_PARSER_ENTITY_DECL, + XML_PARSER_ENTITY_VALUE, + XML_PARSER_ATTRIBUTE_VALUE, + XML_PARSER_DTD, + XML_PARSER_EPILOG, + XML_PARSER_COMMENT, + XML_PARSER_CDATA_SECTION, +} xmlParserInputState; + +/** + * The parser context. + * NOTE This doesn't completely defines the parser state, the (current ?) + * design of the parser uses recursive function calls since this allow + * and easy mapping from the production rules of the specification + * to the actual code. The drawback is that the actual function call + * also reflect the parser state. However most of the parsing routines + * takes as the only argument the parser context pointer, so migrating + * to a state based parser for progressive parsing shouldn't be too hard. + */ typedef struct _xmlParserCtxt { struct xmlSAXHandler *sax; /* The SAX handler */ void *userData; /* the document being built */ xmlDocPtr myDoc; /* the document being built */ - int wellFormed; /* is the document well formed */ int replaceEntities; /* shall we replace entities ? */ - const CHAR *version; /* the XML version string */ - const CHAR *encoding; /* encoding, if any */ - int standalone; /* standalone document */ - int html; /* are we parsing an HTML document */ + const CHAR *version; /* the XML version string */ + const CHAR *encoding; /* encoding, if any */ + int standalone; /* standalone document */ + int hasExternalSubset; /* reference and external subset */ + int hasPErefs; /* the internal subset has PE refs */ + int html; /* are we parsing an HTML document */ + int external; /* are we parsing an external entity */ + int wellFormed; /* is the document well formed */ + int valid; /* is the document valid */ + int validate; /* shall we try to validate ? */ + xmlValidCtxt vctxt; /* The validity context */ + + xmlParserInputState instate; /* current type of input */ + int token; /* next char look-ahead */ + + char *directory; /* the data directory */ + /* Input stream stack */ xmlParserInputPtr input; /* Current input stream */ int inputNr; /* Number of current input streams */ int inputMax; /* Max number of input streams */ xmlParserInputPtr *inputTab; /* stack of inputs */ - /* Node analysis stack */ + /* Node analysis stack only used for DOM building */ xmlNodePtr node; /* Current parsed Node */ int nodeNr; /* Depth of the parsing stack */ int nodeMax; /* Max depth of the parsing stack */ @@ -83,10 +138,9 @@ typedef struct _xmlParserCtxt { typedef _xmlParserCtxt xmlParserCtxt; typedef xmlParserCtxt *xmlParserCtxtPtr; -/* +/** * a SAX Locator. */ - typedef struct xmlSAXLocator { const CHAR *(*getPublicId)(void *ctx); const CHAR *(*getSystemId)(void *ctx); @@ -96,8 +150,9 @@ typedef struct xmlSAXLocator { typedef _xmlSAXLocator xmlSAXLocator; typedef xmlSAXLocator *xmlSAXLocatorPtr; -/* - * a SAX Exception. +/** + * a SAX handler is bunch of callbacks called by the parser when processing + * of the input generate data or structure informations. */ #include "entities.h" @@ -108,6 +163,8 @@ typedef void (*internalSubsetSAXFunc) (void *ctx, const CHAR *name, const CHAR *ExternalID, const CHAR *SystemID); typedef xmlEntityPtr (*getEntitySAXFunc) (void *ctx, const CHAR *name); +typedef xmlEntityPtr (*getParameterEntitySAXFunc) (void *ctx, + const CHAR *name); typedef void (*entityDeclSAXFunc) (void *ctx, const CHAR *name, int type, const CHAR *publicId, const CHAR *systemId, CHAR *content); @@ -138,6 +195,7 @@ typedef void (*ignorableWhitespaceSAXFunc) (void *ctx, typedef void (*processingInstructionSAXFunc) (void *ctx, const CHAR *target, const CHAR *data); typedef void (*commentSAXFunc) (void *ctx, const CHAR *value); +typedef void (*cdataBlockSAXFunc) (void *ctx, const CHAR *value, int len); typedef void (*warningSAXFunc) (void *ctx, const char *msg, ...); typedef void (*errorSAXFunc) (void *ctx, const char *msg, ...); typedef void (*fatalErrorSAXFunc) (void *ctx, const char *msg, ...); @@ -170,12 +228,13 @@ typedef struct xmlSAXHandler { warningSAXFunc warning; errorSAXFunc error; fatalErrorSAXFunc fatalError; + getParameterEntitySAXFunc getParameterEntity; + cdataBlockSAXFunc cdataBlock; } xmlSAXHandler; typedef xmlSAXHandler *xmlSAXHandlerPtr; -/* - * Global variables: just the SAX interface tables we are looking for full - * reentrancy of the code and version infos. +/** + * Global variables: just the default SAX interface tables and XML version infos. */ extern const char *xmlParserVersion; @@ -186,14 +245,14 @@ extern xmlSAXHandler htmlDefaultSAXHandler; #include "entities.h" #include "xml-error.h" -/* +/** * Input functions */ int xmlParserInputRead(xmlParserInputPtr in, int len); int xmlParserInputGrow(xmlParserInputPtr in, int len); -/* +/** * CHAR handling */ CHAR *xmlStrdup(const CHAR *cur); @@ -207,23 +266,23 @@ int xmlStrlen(const CHAR *str); CHAR *xmlStrcat(CHAR *cur, const CHAR *add); CHAR *xmlStrncat(CHAR *cur, const CHAR *add, int len); -/* - * Interfaces +/** + * Basic parsing Interfaces */ xmlDocPtr xmlParseDoc(CHAR *cur); xmlDocPtr xmlParseMemory(char *buffer, int size); xmlDocPtr xmlParseFile(const char *filename); int xmlSubstituteEntitiesDefault(int val); -/* +/** * Recovery mode */ xmlDocPtr xmlRecoverDoc(CHAR *cur); xmlDocPtr xmlRecoverMemory(char *buffer, int size); xmlDocPtr xmlRecoverFile(const char *filename); -/* - * Internal routines +/** + * Less common routines and SAX interfaces */ int xmlParseDocument(xmlParserCtxtPtr ctxt); xmlDocPtr xmlSAXParseDoc(xmlSAXHandlerPtr sax, CHAR *cur, int recovery); diff --git a/include/libxml/parserInternals.h b/include/libxml/parserInternals.h index b1077188..ae8e2cc2 100644 --- a/include/libxml/parserInternals.h +++ b/include/libxml/parserInternals.h @@ -18,6 +18,26 @@ extern "C" { /** * A few macros needed to help building the parser. */ +/* #define UNICODE */ + +#ifdef UNICODE +typedef unsigned long CHARVAL; + +#define NEXTCHARVAL(p) (unsigned long) \ + ((*(p) == 0) ? (unsigned long) 0 : \ + ((*(p) < 0x80) ? (unsigned long) (*(p)++) : \ + (*(p) < 0xC0) ? (unsigned long) 0 : \ + (*(p) < 0xE0) ? ((((unsigned long) *(p)++) << 6) + (*(p)++ & 0x3F)) : \ + (*(p) < 0xF0) ? (((((unsigned long) *(p)++) << 6) + (*(p)++ & 0x3F)) << 6 + \ + (*(p)++ & 0x3F)) : \ + (*(p) < 0xF8) ? ((((((unsigned long) *(p)++) << 6) + (*(p)++ & 0x3F)) << 6 + \ + (*(p)++ & 0x3F)) << 6 + (*(p)++ & 0x3F)) : 0)) +#else +typedef unsigned char CHARVAL; + +#define NEXTCHARVAL(p) (unsigned long) *(p); +#define SKIPCHARVAL(p) (p)++; +#endif #ifdef UNICODE /************************************************************************ @@ -402,7 +422,6 @@ extern "C" { #define IS_LETTER(c) (IS_BASECHAR(c) || IS_IDEOGRAPHIC(c)) #else -#ifndef USE_UTF_8 /************************************************************************ * * * 8bits / ISO-Latin version of the macros. * @@ -453,15 +472,6 @@ extern "C" { */ #define IS_EXTENDER(c) ((c) == 0xb7) -#else /* USE_UTF_8 */ -/************************************************************************ - * * - * 8bits / UTF-8 version of the macros. * - * * - ************************************************************************/ - -TODO !!! -#endif /* USE_UTF_8 */ #endif /* !UNICODE */ /* @@ -513,6 +523,10 @@ xmlParserCtxtPtr xmlCreateMemoryParserCtxt(char *buffer, int size); void xmlFreeParserCtxt(xmlParserCtxtPtr ctxt); +xmlParserCtxtPtr +xmlNewParserCtxt(); +void +xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc); /** * Entities @@ -554,6 +568,8 @@ xmlParseNamespace(xmlParserCtxtPtr ctxt); * Generic production rules */ CHAR * +xmlScanName(xmlParserCtxtPtr ctxt); +CHAR * xmlParseName(xmlParserCtxtPtr ctxt); CHAR * xmlParseNmtoken(xmlParserCtxtPtr ctxt); @@ -638,6 +654,9 @@ void xmlParseXMLDecl(xmlParserCtxtPtr ctxt); void xmlParseMisc(xmlParserCtxtPtr ctxt); +void +xmlParseExternalSubset(xmlParserCtxtPtr ctxt, const CHAR *ExternalID, + const CHAR *SystemID); /* * Entities substitution diff --git a/include/libxml/tree.h b/include/libxml/tree.h index fddabb7e..a627d921 100644 --- a/include/libxml/tree.h +++ b/include/libxml/tree.h @@ -97,6 +97,7 @@ typedef xmlEnumeration *xmlEnumerationPtr; typedef struct xmlAttribute { const CHAR *elem; /* Element holding the attribute */ const CHAR *name; /* Attribute name */ + struct xmlAttribute *next; /* list of attributes of an element */ xmlAttributeType type; /* The type */ xmlAttributeDefault def; /* the default */ const CHAR *defaultValue;/* or the default value */ @@ -138,9 +139,10 @@ typedef enum { } xmlElementTypeVal; typedef struct xmlElement { - const CHAR *name; /* Element name */ - xmlElementTypeVal type; /* The type */ + const CHAR *name; /* Element name */ + xmlElementTypeVal type; /* The type */ xmlElementContentPtr content; /* the allowed element content */ + xmlAttributePtr attributes; /* List of the declared attributes */ } xmlElement; typedef xmlElement *xmlElementPtr; @@ -188,7 +190,7 @@ typedef struct xmlAttr { #endif xmlElementType type; /* XML_ATTRIBUTE_NODE, must be third ! */ struct xmlNode *node; /* attr->node link */ - struct xmlAttr *next; /* parent->childs link */ + struct xmlAttr *next; /* attribute list link */ const CHAR *name; /* the name of the property */ struct xmlNode *val; /* the value of the property */ } xmlAttr; @@ -310,6 +312,7 @@ xmlNodePtr xmlNewDocTextLen(xmlDocPtr doc, const CHAR *content, int len); xmlNodePtr xmlNewTextLen(const CHAR *content, int len); xmlNodePtr xmlNewDocComment(xmlDocPtr doc, const CHAR *content); xmlNodePtr xmlNewComment(const CHAR *content); +xmlNodePtr xmlNewCDataBlock(xmlDocPtr doc, const CHAR *content, int len); xmlNodePtr xmlNewReference(xmlDocPtr doc, const CHAR *name); xmlNodePtr xmlCopyNode(xmlNodePtr node, int recursive); xmlNodePtr xmlCopyNodeList(xmlNodePtr node); diff --git a/include/libxml/valid.h b/include/libxml/valid.h index 084d97fa..7d58459e 100644 --- a/include/libxml/valid.h +++ b/include/libxml/valid.h @@ -11,6 +11,22 @@ #define __XML_VALID_H__ #include "tree.h" +/** + * an xmlValidCtxt is used for error reporting when validating + */ + +typedef void (*xmlValidityErrorFunc) (void *ctx, const char *msg, ...); +typedef void (*xmlValidityWarningFunc) (void *ctx, const char *msg, ...); + +typedef struct xmlValidCtxt { + void *userData; /* user specific data block */ + xmlValidityErrorFunc error; /* the callback in case of errors */ + xmlValidityWarningFunc warning; /* the callback in case of warning */ +} xmlValidCtxt, *xmlValidCtxtPtr; + +extern void xmlParserValidityError(void *ctx, const char *msg, ...); +extern void xmlParserValidityWarning(void *ctx, const char *msg, ...); + /* * ALl notation declarations are stored in a table * there is one table per DTD @@ -21,7 +37,7 @@ typedef struct xmlNotationTable { int nb_notations; /* number of notations stored */ int max_notations; /* maximum number of notations */ - xmlNotationPtr table; /* the table of attributes */ + xmlNotationPtr *table; /* the table of attributes */ } xmlNotationTable; typedef xmlNotationTable *xmlNotationTablePtr; @@ -35,7 +51,7 @@ typedef xmlNotationTable *xmlNotationTablePtr; typedef struct xmlElementTable { int nb_elements; /* number of elements stored */ int max_elements; /* maximum number of elements */ - xmlElementPtr table; /* the table of elements */ + xmlElementPtr *table; /* the table of elements */ } xmlElementTable; typedef xmlElementTable *xmlElementTablePtr; @@ -49,13 +65,13 @@ typedef xmlElementTable *xmlElementTablePtr; typedef struct xmlAttributeTable { int nb_attributes; /* number of attributes stored */ int max_attributes; /* maximum number of attributes */ - xmlAttributePtr table; /* the table of attributes */ + xmlAttributePtr *table; /* the table of attributes */ } xmlAttributeTable; typedef xmlAttributeTable *xmlAttributeTablePtr; /* Notation */ -xmlNotationPtr xmlAddNotationDecl(xmlDtdPtr dtd, const CHAR *name, - const CHAR *PublicID, const CHAR *SystemID); +xmlNotationPtr xmlAddNotationDecl(xmlValidCtxtPtr ctxt, xmlDtdPtr dtd, + const CHAR *name, const CHAR *PublicID, const CHAR *SystemID); xmlNotationTablePtr xmlCopyNotationTable(xmlNotationTablePtr table); void xmlFreeNotationTable(xmlNotationTablePtr table); void xmlDumpNotationTable(xmlBufferPtr buf, xmlNotationTablePtr table); @@ -66,8 +82,8 @@ xmlElementContentPtr xmlCopyElementContent(xmlElementContentPtr content); void xmlFreeElementContent(xmlElementContentPtr cur); /* Element */ -xmlElementPtr xmlAddElementDecl(xmlDtdPtr dtd, const CHAR *name, int type, - xmlElementContentPtr content); +xmlElementPtr xmlAddElementDecl(xmlValidCtxtPtr ctxt, xmlDtdPtr dtd, + const CHAR *name, int type, xmlElementContentPtr content); xmlElementTablePtr xmlCopyElementTable(xmlElementTablePtr table); void xmlFreeElementTable(xmlElementTablePtr table); void xmlDumpElementTable(xmlBufferPtr buf, xmlElementTablePtr table); @@ -78,11 +94,32 @@ void xmlFreeEnumeration(xmlEnumerationPtr cur); xmlEnumerationPtr xmlCopyEnumeration(xmlEnumerationPtr cur); /* Attribute */ -xmlAttributePtr xmlAddAttributeDecl(xmlDtdPtr dtd, const CHAR *elem, - const CHAR *name, int type, int def, +xmlAttributePtr xmlAddAttributeDecl(xmlValidCtxtPtr ctxt, xmlDtdPtr dtd, + const CHAR *elem, const CHAR *name, int type, int def, const CHAR *defaultValue, xmlEnumerationPtr tree); xmlAttributeTablePtr xmlCopyAttributeTable(xmlAttributeTablePtr table); void xmlFreeAttributeTable(xmlAttributeTablePtr table); void xmlDumpAttributeTable(xmlBufferPtr buf, xmlAttributeTablePtr table); +/** + * The public function calls related to validity checking + */ + +int xmlValidateRoot(xmlValidCtxtPtr ctxt, xmlDocPtr doc); +int xmlValidateElementDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc, + xmlElementPtr elem); +int xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc, + xmlAttributePtr attr); +int xmlValidateNotationDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc, + xmlNotationPtr nota); +int xmlValidateDtd(xmlValidCtxtPtr ctxt, xmlDocPtr doc, xmlDtdPtr dtd); + +int xmlValidateDocument(xmlValidCtxtPtr ctxt, xmlDocPtr doc); +int xmlValidateElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc, xmlNodePtr elem); +int xmlValidateOneElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc, + xmlNodePtr elem); +int xmlValidateOneAttribute(xmlValidCtxtPtr ctxt, xmlDocPtr doc, + xmlNodePtr elem, xmlAttrPtr attr, const CHAR *value); + +int xmlIsMixedElement(xmlDocPtr doc, const CHAR *name); #endif /* __XML_VALID_H__ */ diff --git a/include/libxml/xmlIO.h b/include/libxml/xmlIO.h index bdeecc3f..0e086d77 100644 --- a/include/libxml/xmlIO.h +++ b/include/libxml/xmlIO.h @@ -45,6 +45,7 @@ int xmlParserInputBufferRead(xmlParserInputBufferPtr in, int len); int xmlParserInputBufferGrow(xmlParserInputBufferPtr in, int len); void xmlFreeParserInputBuffer(xmlParserInputBufferPtr in); +char *xmlParserGetDirectory(const char *filename); #ifdef __cplusplus } diff --git a/libxml.spec.in b/libxml.spec.in index 8f9f9412..6486dd0f 100644 --- a/libxml.spec.in +++ b/libxml.spec.in @@ -12,6 +12,7 @@ Copyright: LGPL Group: X11/Libraries Source: ftp://ftp.gnome.org/pub/GNOME/sources/libxml/libxml-%{ver}.tar.gz BuildRoot: /var/tmp/libxml-%{PACKAGE_VERSION}-root +Provides: libxml.so.0 URL: http://www.gnome.org Prereq: /sbin/install-info @@ -76,6 +77,14 @@ fi rm -rf $RPM_BUILD_ROOT make prefix=$RPM_BUILD_ROOT%{prefix} install +# +# hack to get libxml.so.0 too ! +# Get rid of it once deps to libxml.so.0 have disapeared. +# +if [ -f $RPM_BUILD_ROOT/%{prefix}/lib/libxml.so.@VERSION@ ] +then + (cd $RPM_BUILD_ROOT/%{prefix}/lib/ ; cp libxml.so.@VERSION@ libxml.so.0.99.0 ; ln -sf libxml.so.0.99.0 libxml.so.0) +fi %clean @@ -97,5 +106,4 @@ rm -rf $RPM_BUILD_ROOT %{prefix}/lib/lib*.so %{prefix}/lib/*a -%{prefix}/lib/*.sh %{prefix}/include/* diff --git a/parser.c b/parser.c index 2bc3d879..8fd47977 100644 --- a/parser.c +++ b/parser.c @@ -47,13 +47,12 @@ const char *xmlParserVersion = LIBXML_VERSION; /* #define DEBUG_INPUT */ -#define INPUT_CHUNK 50 +#define INPUT_CHUNK 250 +/* we need to keep enough input to show errors in context */ +#define LINE_LEN 80 #ifdef DEBUG_INPUT #define CHECK_BUFFER(in) check_buffer(in) -#else -#define CHECK_BUFFER(in) -#endif void check_buffer(xmlParserInputPtr in) { if (in->base != in->buf->buffer->content) { @@ -70,6 +69,10 @@ void check_buffer(xmlParserInputPtr in) { in->buf->buffer->use, in->buf->buffer->size); } +#else +#define CHECK_BUFFER(in) +#endif + /** * xmlParserInputRead: @@ -191,7 +194,7 @@ xmlParserInputShrink(xmlParserInputPtr in) { used = in->cur - in->buf->buffer->content; if (used > INPUT_CHUNK) { - ret = xmlBufferShrink(in->buf->buffer, used); + ret = xmlBufferShrink(in->buf->buffer, used - LINE_LEN); if (ret > 0) { in->cur -= ret; in->consumed += ret; @@ -223,6 +226,7 @@ xmlParserInputShrink(xmlParserInputPtr in) { ************************************************************************/ int xmlSubstituteEntitiesDefaultValue = 0; +int xmlDoValidityCheckingDefaultValue = 0; /* * Generic function for accessing stacks in the Parser Context @@ -285,19 +289,31 @@ PUSH_AND_POP(xmlNodePtr, node) * COPY(to) copy one char to *to, increment CUR_PTR and to accordingly */ -#define CUR (*ctxt->input->cur) +#define CUR (ctxt->token ? ctxt->token : (*ctxt->input->cur)) #define SKIP(val) ctxt->input->cur += (val) #define NXT(val) ctxt->input->cur[(val)] #define CUR_PTR ctxt->input->cur -#define SHRINK xmlParserInputShrink(ctxt->input) -#define GROW xmlParserInputGrow(ctxt->input, INPUT_CHUNK) +#define SHRINK xmlParserInputShrink(ctxt->input); \ + if ((*ctxt->input->cur == 0) && \ + (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) \ + xmlPopInput(ctxt) + +#define GROW xmlParserInputGrow(ctxt->input, INPUT_CHUNK); \ + if ((*ctxt->input->cur == 0) && \ + (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) \ + xmlPopInput(ctxt) #define SKIP_BLANKS \ - while (IS_BLANK(*(ctxt->input->cur))) NEXT + do { \ + while (IS_BLANK(CUR)) NEXT; \ + if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt); \ + if (*ctxt->input->cur == '&') xmlParserHandleReference(ctxt); \ + } while (IS_BLANK(CUR)); -#ifndef USE_UTF_8 #define CURRENT (*ctxt->input->cur) #define NEXT { \ + if (ctxt->token != 0) ctxt->token = 0; \ + else { \ if ((*ctxt->input->cur == 0) && \ (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) { \ xmlPopInput(ctxt); \ @@ -308,25 +324,17 @@ PUSH_AND_POP(xmlNodePtr, node) ctxt->input->cur++; \ if (*ctxt->input->cur == 0) \ xmlParserInputGrow(ctxt->input, INPUT_CHUNK); \ - }} + } \ + if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt); \ + if (*ctxt->input->cur == '&') xmlParserHandleReference(ctxt); \ +}} -/**************************************** -#define NEXT ((*ctxt->input->cur) ? \ - (((*(ctxt->input->cur) == '\n') ? \ - (ctxt->input->line++, ctxt->input->col = 1) : \ - (ctxt->input->col++)), \ - (ctxt->input->cur++), \ - ((*ctxt->input->cur) ? \ - (xmlParserInputGrow(ctxt->input, 100), \ - ctxt->input->cur): \ - (ctxt->input->cur))) : \ - ((xmlParserInputGrow(ctxt->input, 100) > 0) ? \ - ctxt->input->cur: \ - (xmlPopInput(ctxt), ctxt->input->cur))) - ****************************************/ -#else -#endif +/************************************************************************ + * * + * Commodity functions to handle entities processing * + * * + ************************************************************************/ /** * xmlPopInput: @@ -335,14 +343,15 @@ PUSH_AND_POP(xmlNodePtr, node) * xmlPopInput: the current input pointed by ctxt->input came to an end * pop it and return the next char. * - * TODO A deallocation of the popped Input structure is needed - * * Returns the current CHAR in the parser context */ CHAR xmlPopInput(xmlParserCtxtPtr ctxt) { if (ctxt->inputNr == 1) return(0); /* End of main Input */ xmlFreeInputStream(inputPop(ctxt)); + if ((*ctxt->input->cur == 0) && + (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) + return(xmlPopInput(ctxt)); return(CUR); } @@ -362,7 +371,7 @@ xmlPushInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr input) { /** * xmlFreeInputStream: - * @input: an xmlParserInputPtr + * @input: an xmlP arserInputPtr * * Free up an input stream. */ @@ -371,6 +380,7 @@ xmlFreeInputStream(xmlParserInputPtr input) { if (input == NULL) return; if (input->filename != NULL) free((char *) input->filename); + if (input->directory != NULL) free((char *) input->directory); if ((input->free != NULL) && (input->base != NULL)) input->free((char *) input->base); if (input->buf != NULL) @@ -379,6 +389,36 @@ xmlFreeInputStream(xmlParserInputPtr input) { free(input); } +/** + * xmlNewInputStream: + * @ctxt: an XML parser context + * + * Create a new input stream structure + * Returns the new input stream or NULL + */ +xmlParserInputPtr +xmlNewInputStream(xmlParserCtxtPtr ctxt) { + xmlParserInputPtr input; + + input = (xmlParserInputPtr) malloc(sizeof(xmlParserInput)); + if (input == NULL) { + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, "malloc: couldn't allocate a new input stream\n"); + return(NULL); + } + input->filename = NULL; + input->directory = NULL; + input->base = NULL; + input->cur = NULL; + input->buf = NULL; + input->line = 1; + input->col = 1; + input->buf = NULL; + input->free = NULL; + input->consumed = 0; + return(input); +} + /** * xmlNewEntityInputStream: * @ctxt: an XML parser context @@ -403,56 +443,40 @@ xmlNewEntityInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) { "internal: xmlNewEntityInputStream entity->input = NULL\n"); return(NULL); } - input = (xmlParserInputPtr) malloc(sizeof(xmlParserInput)); + input = xmlNewInputStream(ctxt); if (input == NULL) { - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, "malloc: couldn't allocate a new input stream\n"); return(NULL); } input->filename = entity->SystemID; /* TODO !!! char <- CHAR */ input->base = entity->content; input->cur = entity->content; - input->buf = NULL; - input->line = 1; - input->col = 1; - input->buf = NULL; - input->free = NULL; - input->consumed = 0; return(input); } /** * xmlNewStringInputStream: * @ctxt: an XML parser context - * @entity: an Entity memory buffer + * @buffer: an memory buffer * * Create a new input stream based on a memory buffer. * Returns the new input stream */ xmlParserInputPtr -xmlNewStringInputStream(xmlParserCtxtPtr ctxt, CHAR *entity) { +xmlNewStringInputStream(xmlParserCtxtPtr ctxt, const CHAR *buffer) { xmlParserInputPtr input; - if (entity == NULL) { + if (buffer == NULL) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) ctxt->sax->error(ctxt->userData, "internal: xmlNewStringInputStream string = NULL\n"); return(NULL); } - input = (xmlParserInputPtr) malloc(sizeof(xmlParserInput)); + input = xmlNewInputStream(ctxt); if (input == NULL) { - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, "malloc: couldn't allocate a new input stream\n"); return(NULL); } - input->filename = NULL; - input->base = entity; - input->cur = entity; - input->buf = NULL; - input->line = 1; - input->col = 1; - input->free = NULL; - input->consumed = 0; + input->base = buffer; + input->cur = buffer; return(input); } @@ -469,36 +493,639 @@ xmlParserInputPtr xmlNewInputFromFile(xmlParserCtxtPtr ctxt, const char *filename) { xmlParserInputBufferPtr buf; xmlParserInputPtr inputStream; + char *directory = NULL; + if (ctxt == NULL) return(NULL); buf = xmlParserInputBufferCreateFilename(filename, XML_CHAR_ENCODING_NONE); - if (buf == NULL) return(NULL); + if (buf == NULL) { + char name[1024]; - inputStream = (xmlParserInputPtr) malloc(sizeof(xmlParserInput)); + if ((ctxt->input != NULL) && (ctxt->input->directory != NULL)) { +#ifdef WIN32 + sprintf(name, "%s\\%s", ctxt->input->directory, filename); +#else + sprintf(name, "%s/%s", ctxt->input->directory, filename); +#endif + buf = xmlParserInputBufferCreateFilename(name, + XML_CHAR_ENCODING_NONE); + if (buf != NULL) + directory = strdup(ctxt->input->directory); + } + if ((buf == NULL) && (ctxt->directory != NULL)) { +#ifdef WIN32 + sprintf(name, "%s\\%s", ctxt->directory, filename); +#else + sprintf(name, "%s/%s", ctxt->directory, filename); +#endif + buf = xmlParserInputBufferCreateFilename(name, + XML_CHAR_ENCODING_NONE); + if (buf != NULL) + directory = strdup(ctxt->directory); + } + if (buf == NULL) + return(NULL); + } + if (directory == NULL) + directory = xmlParserGetDirectory(filename); + + inputStream = xmlNewInputStream(ctxt); if (inputStream == NULL) { - perror("malloc"); - free(ctxt); + if (directory != NULL) free((char *) directory); return(NULL); } inputStream->filename = strdup(filename); - inputStream->line = 1; - inputStream->col = 1; + inputStream->directory = directory; inputStream->buf = buf; inputStream->base = inputStream->buf->buffer->content; inputStream->cur = inputStream->buf->buffer->content; - inputStream->free = NULL; - inputStream->consumed = 0; - + if ((ctxt->directory == NULL) && (directory != NULL)) + ctxt->directory = directory; return(inputStream); } +/************************************************************************ + * * + * Commodity functions to handle parser contexts * + * * + ************************************************************************/ + +/** + * xmlInitParserCtxt: + * @ctxt: an XML parser context + * + * Initialize a parser context + */ + +void +xmlInitParserCtxt(xmlParserCtxtPtr ctxt) +{ + xmlSAXHandler *sax; + + sax = (xmlSAXHandler *) malloc(sizeof(xmlSAXHandler)); + if (sax == NULL) { + fprintf(stderr, "xmlInitParserCtxt: out of memory\n"); + } + + /* Allocate the Input stack */ + ctxt->inputTab = (xmlParserInputPtr *) malloc(5 * sizeof(xmlParserInputPtr)); + ctxt->inputNr = 0; + ctxt->inputMax = 5; + ctxt->input = NULL; + ctxt->version = NULL; + ctxt->encoding = NULL; + ctxt->standalone = -1; + ctxt->hasExternalSubset = 0; + ctxt->hasPErefs = 0; + ctxt->html = 0; + ctxt->external = 0; + ctxt->instate = XML_PARSER_PROLOG; + ctxt->token = 0; + ctxt->directory = NULL; + + /* Allocate the Node stack */ + ctxt->nodeTab = (xmlNodePtr *) malloc(10 * sizeof(xmlNodePtr)); + ctxt->nodeNr = 0; + ctxt->nodeMax = 10; + ctxt->node = NULL; + + if (sax == NULL) ctxt->sax = &xmlDefaultSAXHandler; + else { + ctxt->sax = sax; + memcpy(sax, &xmlDefaultSAXHandler, sizeof(xmlSAXHandler)); + } + ctxt->userData = ctxt; + ctxt->myDoc = NULL; + ctxt->wellFormed = 1; + ctxt->valid = 1; + ctxt->validate = xmlDoValidityCheckingDefaultValue; + ctxt->vctxt.userData = ctxt; + ctxt->vctxt.error = xmlParserValidityError; + ctxt->vctxt.warning = xmlParserValidityWarning; + ctxt->replaceEntities = xmlSubstituteEntitiesDefaultValue; + ctxt->record_info = 0; + xmlInitNodeInfoSeq(&ctxt->node_seq); +} + +/** + * xmlFreeParserCtxt: + * @ctxt: an XML parser context + * + * Free all the memory used by a parser context. However the parsed + * document in ctxt->myDoc is not freed. + */ + +void +xmlFreeParserCtxt(xmlParserCtxtPtr ctxt) +{ + xmlParserInputPtr input; + + if (ctxt == NULL) return; + + while ((input = inputPop(ctxt)) != NULL) { + xmlFreeInputStream(input); + } + + if (ctxt->nodeTab != NULL) free(ctxt->nodeTab); + if (ctxt->inputTab != NULL) free(ctxt->inputTab); + if (ctxt->version != NULL) free((char *) ctxt->version); + if (ctxt->encoding != NULL) free((char *) ctxt->encoding); + if ((ctxt->sax != NULL) && (ctxt->sax != &xmlDefaultSAXHandler)) + free(ctxt->sax); + if (ctxt->directory != NULL) free((char *) ctxt->directory); + free(ctxt); +} + +/** + * xmlNewParserCtxt: + * + * Allocate and initialize a new parser context. + * + * Returns the xmlParserCtxtPtr or NULL + */ + +xmlParserCtxtPtr +xmlNewParserCtxt() +{ + xmlParserCtxtPtr ctxt; + + ctxt = (xmlParserCtxtPtr) malloc(sizeof(xmlParserCtxt)); + if (ctxt == NULL) { + fprintf(stderr, "xmlNewParserCtxt : cannot allocate context\n"); + perror("malloc"); + return(NULL); + } + xmlInitParserCtxt(ctxt); + return(ctxt); +} + +/** + * xmlClearParserCtxt: + * @ctxt: an XML parser context + * + * Clear (release owned resources) and reinitialize a parser context + */ + +void +xmlClearParserCtxt(xmlParserCtxtPtr ctxt) +{ + xmlClearNodeInfoSeq(&ctxt->node_seq); + xmlInitParserCtxt(ctxt); +} + /************************************************************************ * * * Commodity functions to handle entities * * * ************************************************************************/ +void xmlParserHandleReference(xmlParserCtxtPtr ctxt); +void xmlParserHandlePEReference(xmlParserCtxtPtr ctxt); + +/** + * xmlParseCharRef: + * @ctxt: an XML parser context + * + * parse Reference declarations + * + * [66] CharRef ::= '&#' [0-9]+ ';' | + * '&#x' [0-9a-fA-F]+ ';' + * + * [ WFC: Legal Character ] + * Characters referred to using character references must match the + * production for Char. + * + * Returns the value parsed (as an int) + */ +int +xmlParseCharRef(xmlParserCtxtPtr ctxt) { + int val = 0; + + if (ctxt->token != 0) { + val = ctxt->token; + ctxt->token = 0; + return(val); + } + if ((CUR == '&') && (NXT(1) == '#') && + (NXT(2) == 'x')) { + SKIP(3); + while (CUR != ';') { + if ((CUR >= '0') && (CUR <= '9')) + val = val * 16 + (CUR - '0'); + else if ((CUR >= 'a') && (CUR <= 'f')) + val = val * 16 + (CUR - 'a') + 10; + else if ((CUR >= 'A') && (CUR <= 'F')) + val = val * 16 + (CUR - 'A') + 10; + else { + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "xmlParseCharRef: invalid hexadecimal value\n"); + ctxt->wellFormed = 0; + val = 0; + break; + } + NEXT; + } + if (CUR == ';') + NEXT; + } else if ((CUR == '&') && (NXT(1) == '#')) { + SKIP(2); + while (CUR != ';') { + if ((CUR >= '0') && (CUR <= '9')) + val = val * 10 + (CUR - '0'); + else { + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "xmlParseCharRef: invalid decimal value\n"); + ctxt->wellFormed = 0; + val = 0; + break; + } + NEXT; + } + if (CUR == ';') + NEXT; + } else { + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "xmlParseCharRef: invalid value\n"); + ctxt->wellFormed = 0; + } + + /* + * [ WFC: Legal Character ] + * Characters referred to using character references must match the + * production for Char. + */ + if (IS_CHAR(val)) { + return(val); + } else { + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, "CharRef: invalid CHAR value %d\n", + val); + ctxt->wellFormed = 0; + } + return(0); +} + +/** + * xmlParserHandleReference: + * @ctxt: the parser context + * + * [67] Reference ::= EntityRef | CharRef + * + * [68] EntityRef ::= '&' Name ';' + * + * [ WFC: Entity Declared ] + * the Name given in the entity reference must match that in an entity + * declaration, except that well-formed documents need not declare any + * of the following entities: amp, lt, gt, apos, quot. + * + * [ WFC: Parsed Entity ] + * An entity reference must not contain the name of an unparsed entity + * + * [66] CharRef ::= '&#' [0-9]+ ';' | + * '&#x' [0-9a-fA-F]+ ';' + * + * A PEReference may have been detectect in the current input stream + * the handling is done accordingly to + * http://www.w3.org/TR/REC-xml#entproc + */ +void +xmlParserHandleReference(xmlParserCtxtPtr ctxt) { + xmlParserInputPtr input; + CHAR *name; + xmlEntityPtr ent = NULL; + + if (ctxt->token != 0) return; + if (CUR != '&') return; + GROW; + if ((CUR == '&') && (NXT(1) == '#')) { + switch(ctxt->instate) { + case XML_PARSER_CDATA_SECTION: + return; + case XML_PARSER_COMMENT: + return; + case XML_PARSER_EOF: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, "CharRef at EOF\n"); + ctxt->wellFormed = 0; + return; + case XML_PARSER_PROLOG: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, "CharRef in prolog!\n"); + ctxt->wellFormed = 0; + return; + case XML_PARSER_EPILOG: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, "CharRef in epilog!\n"); + ctxt->wellFormed = 0; + return; + case XML_PARSER_DTD: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "CharRef are forbiden in DTDs!\n"); + ctxt->wellFormed = 0; + return; + case XML_PARSER_ENTITY_DECL: + /* we just ignore it there */ + return; + case XML_PARSER_ENTITY_VALUE: + /* + * NOTE: in the case of entity values, we don't do the + * substitution here since we need the litteral + * entity value to be able to save the internal + * subset of the document. + * This will be handled by xmlDecodeEntities + */ + return; + case XML_PARSER_CONTENT: + case XML_PARSER_ATTRIBUTE_VALUE: + /* TODO this may not be Ok for UTF-8, multibyte sequence */ + ctxt->token = xmlParseCharRef(ctxt); + return; + } + return; + } + + switch(ctxt->instate) { + case XML_PARSER_CDATA_SECTION: + return; + case XML_PARSER_COMMENT: + return; + case XML_PARSER_EOF: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, "Reference at EOF\n"); + ctxt->wellFormed = 0; + return; + case XML_PARSER_PROLOG: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, "Reference in prolog!\n"); + ctxt->wellFormed = 0; + return; + case XML_PARSER_EPILOG: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, "Reference in epilog!\n"); + ctxt->wellFormed = 0; + return; + case XML_PARSER_ENTITY_VALUE: + /* + * NOTE: in the case of entity values, we don't do the + * substitution here since we need the litteral + * entity value to be able to save the internal + * subset of the document. + * This will be handled by xmlDecodeEntities + */ + return; + case XML_PARSER_ATTRIBUTE_VALUE: + /* + * NOTE: in the case of attributes values, we don't do the + * substitution here unless we are in a mode where + * the parser is explicitely asked to substitute + * entities. The SAX callback is called with values + * without entity substitution. + * This will then be handled by xmlDecodeEntities + */ + if (ctxt->replaceEntities == 0) return; + break; + case XML_PARSER_ENTITY_DECL: + /* + * we just ignore it there + * the substitution will be done once the entity is referenced + */ + return; + case XML_PARSER_DTD: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "Entity references are forbiden in DTDs!\n"); + ctxt->wellFormed = 0; + return; + case XML_PARSER_CONTENT: + if (ctxt->replaceEntities == 0) return; + break; + } + + NEXT; + name = xmlScanName(ctxt); + if (name == NULL) { + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, "Entity reference: no name\n"); + ctxt->wellFormed = 0; + ctxt->token = '&'; + return; + } + if (NXT(xmlStrlen(name)) != ';') { + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "Entity reference: ';' expected\n"); + ctxt->wellFormed = 0; + ctxt->token = '&'; + free(name); + return; + } + SKIP(xmlStrlen(name) + 1); + if (ctxt->sax != NULL) { + if (ctxt->sax->getEntity != NULL) + ent = ctxt->sax->getEntity(ctxt->userData, name); + } + + /* + * [ WFC: Entity Declared ] + * the Name given in the entity reference must match that in an entity + * declaration, except that well-formed documents need not declare any + * of the following entities: amp, lt, gt, apos, quot. + */ + if (ent == NULL) + ent = xmlGetPredefinedEntity(name); + if (ent == NULL) { + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "Entity reference: entity %s not declared\n", + name); + ctxt->wellFormed = 0; + free(name); + return; + } + + /* + * [ WFC: Parsed Entity ] + * An entity reference must not contain the name of an unparsed entity + */ + if (ent->type == XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) { + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "Entity reference to unparsed entity %s\n", name); + ctxt->wellFormed = 0; + } + + if (ent->type == XML_INTERNAL_PREDEFINED_ENTITY) { + ctxt->token = ent->content[0]; + free(name); + return; + } + input = xmlNewEntityInputStream(ctxt, ent); + xmlPushInput(ctxt, input); + free(name); + return; +} + +/** + * xmlParserHandlePEReference: + * @ctxt: the parser context + * + * [69] PEReference ::= '%' Name ';' + * + * [ WFC: No Recursion ] + * TODO A parsed entity must not contain a recursive + * reference to itself, either directly or indirectly. + * + * [ WFC: Entity Declared ] + * In a document without any DTD, a document with only an internal DTD + * subset which contains no parameter entity references, or a document + * with "standalone='yes'", ... ... The declaration of a parameter + * entity must precede any reference to it... + * + * [ VC: Entity Declared ] + * In a document with an external subset or external parameter entities + * with "standalone='no'", ... ... The declaration of a parameter entity + * must precede any reference to it... + * + * [ WFC: In DTD ] + * Parameter-entity references may only appear in the DTD. + * NOTE: misleading but this is handled. + * + * A PEReference may have been detected in the current input stream + * the handling is done accordingly to + * http://www.w3.org/TR/REC-xml#entproc + * i.e. + * - Included in literal in entity values + * - Included as Paraemeter Entity reference within DTDs + */ +void +xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) { + CHAR *name; + xmlEntityPtr entity = NULL; + xmlParserInputPtr input; + + if (ctxt->token != 0) return; + if (CUR != '%') return; + switch(ctxt->instate) { + case XML_PARSER_CDATA_SECTION: + return; + case XML_PARSER_COMMENT: + return; + case XML_PARSER_EOF: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, "PEReference at EOF\n"); + ctxt->wellFormed = 0; + return; + case XML_PARSER_PROLOG: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, "PEReference in prolog!\n"); + ctxt->wellFormed = 0; + return; + case XML_PARSER_ENTITY_DECL: + case XML_PARSER_CONTENT: + case XML_PARSER_ATTRIBUTE_VALUE: + /* we just ignore it there */ + return; + case XML_PARSER_EPILOG: + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, "PEReference in epilog!\n"); + ctxt->wellFormed = 0; + return; + case XML_PARSER_ENTITY_VALUE: + /* + * NOTE: in the case of entity values, we don't do the + * substitution here since we need the litteral + * entity value to be able to save the internal + * subset of the document. + * This will be handled by xmlDecodeEntities + */ + return; + case XML_PARSER_DTD: + /* + * [WFC: Well-Formedness Constraint: PEs in Internal Subset] + * In the internal DTD subset, parameter-entity references + * can occur only where markup declarations can occur, not + * within markup declarations. + * In that case this is handled in xmlParseMarkupDecl + */ + if ((ctxt->external == 0) && (ctxt->inputNr == 1)) + return; + } + + NEXT; + name = xmlParseName(ctxt); + if (name == NULL) { + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, "xmlHandlePEReference: no name\n"); + ctxt->wellFormed = 0; + } else { + if (CUR == ';') { + NEXT; + if ((ctxt->sax != NULL) && (ctxt->sax->getParameterEntity != NULL)) + entity = ctxt->sax->getParameterEntity(ctxt->userData, name); + if (entity == NULL) { + + /* + * [ WFC: Entity Declared ] + * In a document without any DTD, a document with only an + * internal DTD subset which contains no parameter entity + * references, or a document with "standalone='yes'", ... + * ... The declaration of a parameter entity must precede + * any reference to it... + */ + if ((ctxt->standalone == 1) || + ((ctxt->hasExternalSubset == 0) && + (ctxt->hasPErefs == 0))) { + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "PEReference: %%%s; not found\n", name); + ctxt->wellFormed = 0; + } else { + /* + * [ VC: Entity Declared ] + * In a document with an external subset or external + * parameter entities with "standalone='no'", ... + * ... The declaration of a parameter entity must precede + * any reference to it... + */ + if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) + ctxt->sax->warning(ctxt->userData, + "PEReference: %%%s; not found\n", name); + ctxt->valid = 0; + } + } else { + if ((entity->type == XML_INTERNAL_PARAMETER_ENTITY) || + (entity->type == XML_EXTERNAL_PARAMETER_ENTITY)) { + /* + * TODO !!!! handle the extra spaces added before and after + * c.f. http://www.w3.org/TR/REC-xml#as-PE + * TODO !!!! Avoid quote processing in parameters value + * c.f. http://www.w3.org/TR/REC-xml#inliteral + */ + input = xmlNewEntityInputStream(ctxt, entity); + xmlPushInput(ctxt, input); + } else { + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "xmlHandlePEReference: %s is not a parameter entity\n", + name); + ctxt->wellFormed = 0; + } + } + } else { + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "xmlHandlePEReference: expecting ';'\n"); + ctxt->wellFormed = 0; + } + free(name); + } +} + /* * Macro used to grow the current buffer. */ @@ -511,7 +1138,6 @@ xmlNewInputFromFile(xmlParserCtxtPtr ctxt, const char *filename) { } \ } - /** * xmlDecodeEntities: * @ctxt: the parser context @@ -535,10 +1161,11 @@ xmlDecodeEntities(xmlParserCtxtPtr ctxt, int len, int what, int buffer_size = 0; CHAR *out = NULL; - CHAR *cur = NULL; + CHAR *current = NULL; xmlEntityPtr ent; int nbchars = 0; unsigned int max = (unsigned int) len; + CHAR cur; /* * allocate a translation buffer. @@ -554,32 +1181,47 @@ xmlDecodeEntities(xmlParserCtxtPtr ctxt, int len, int what, /* * Ok loop until we reach one of the ending char or a size limit. */ - while ((nbchars < max) && (CUR != end) && - (CUR != end2) && (CUR != end3)) { + cur = CUR; + while ((nbchars < max) && (cur != end) && + (cur != end2) && (cur != end3)) { - if (CUR == '&' && (what & XML_SUBSTITUTE_REF)) { - if (NXT(1) == '#') { - int val = xmlParseCharRef(ctxt); - /* TODO: invalid for UTF-8 variable encoding !!! */ - *out++ = val; - nbchars += 3; /* !!!! */ - } else { - ent = xmlParseEntityRef(ctxt); - if (ent != NULL) { - cur = ent->content; - while (*cur != 0) { - *out++ = *cur++; - if (out - buffer > buffer_size - 100) { - int index = out - buffer; + if (cur == 0) break; + if ((cur == '&') && (NXT(1) == '#')) { + int val = xmlParseCharRef(ctxt); + *out++ = val; + nbchars += 3; + } else if ((cur == '&') && (what & XML_SUBSTITUTE_REF)) { + ent = xmlParseEntityRef(ctxt); + if ((ent != NULL) && + (ctxt->replaceEntities != 0)) { + current = ent->content; + while (*current != 0) { + *out++ = *current++; + if (out - buffer > buffer_size - 100) { + int index = out - buffer; - growBuffer(buffer); - out = &buffer[index]; - } + growBuffer(buffer); + out = &buffer[index]; } - nbchars += 3 + xmlStrlen(ent->name); } + nbchars += 3 + xmlStrlen(ent->name); + } else if (ent != NULL) { + int i = xmlStrlen(ent->name); + const CHAR *cur = ent->name; + + nbchars += i + 2; + *out++ = '&'; + if (out - buffer > buffer_size - i - 100) { + int index = out - buffer; + + growBuffer(buffer); + out = &buffer[index]; + } + for (;i > 0;i--) + *out++ = *cur++; + *out++ = ';'; } - } else if (CUR == '%' && (what & XML_SUBSTITUTE_PEREF)) { + } else if (cur == '%' && (what & XML_SUBSTITUTE_PEREF)) { /* * a PEReference induce to switch the entity flow, * we break here to flush the current set of chars @@ -595,10 +1237,10 @@ xmlDecodeEntities(xmlParserCtxtPtr ctxt, int len, int what, while ((CUR == 0) && (ctxt->inputNr > 1)) xmlPopInput(ctxt); - break; + break; } else { /* TODO: invalid for UTF-8 , use COPY(out); */ - *out++ = CUR; + *out++ = cur; nbchars++; if (out - buffer > buffer_size - 100) { int index = out - buffer; @@ -608,6 +1250,7 @@ xmlDecodeEntities(xmlParserCtxtPtr ctxt, int len, int what, } NEXT; } + cur = CUR; } *out++ = 0; return(buffer); @@ -1045,13 +1688,14 @@ xmlStrcat(CHAR *cur, const CHAR *add) { * * Is this a sequence of blank chars that one can ignore ? * - * TODO: to be corrected accodingly to DTD information if available + * TODO: Whether white space are significant has to be checked accordingly + * to DTD informations if available * * Returns 1 if ignorable 0 otherwise. */ static int areBlanks(xmlParserCtxtPtr ctxt, const CHAR *str, int len) { - int i; + int i, ret; xmlNodePtr lastChild; for (i = 0;i < len;i++) @@ -1059,11 +1703,22 @@ static int areBlanks(xmlParserCtxtPtr ctxt, const CHAR *str, int len) { if (CUR != '<') return(0); if (ctxt->node == NULL) return(0); + if (ctxt->myDoc != NULL) { + ret = xmlIsMixedElement(ctxt->myDoc, ctxt->node->name); + if (ret == 0) return(1); + if (ret == 1) return(0); + } + /* + * heuristic + */ lastChild = xmlGetLastChild(ctxt->node); if (lastChild == NULL) { if (ctxt->node->content != NULL) return(0); } else if (xmlNodeIsText(lastChild)) return(0); + else if ((ctxt->node->childs != NULL) && + (xmlNodeIsText(ctxt->node->childs))) + return(0); return(1); } @@ -1074,7 +1729,8 @@ static int areBlanks(xmlParserCtxtPtr ctxt, const CHAR *str, int len) { * * Default handling of defined entities, when should we define a new input * stream ? When do we just handle that as a set of chars ? - * TODO: we should call the SAX handler here and have it resolve the issue + * + * OBSOLETE: to be removed at some point. */ void @@ -1285,6 +1941,7 @@ xmlNamespaceParseNSDef(xmlParserCtxtPtr ctxt) { * @ctxt: an XML parser context * * [OLD] Parse and return a string between quotes or doublequotes + * To be removed at next drop of binary compatibility * * Returns the string parser or NULL. */ @@ -1330,6 +1987,8 @@ xmlParseQuotedString(xmlParserCtxtPtr ctxt) { * This is what the older xml-name Working Draft specified, a bunch of * other stuff may still rely on it, so support is still here as * if ot was declared on the root of the Tree:-( + * + * To be removed at next drop of binary compatibility */ void @@ -1431,6 +2090,56 @@ xmlParseNamespace(xmlParserCtxtPtr ctxt) { * * ************************************************************************/ +/** + * xmlScanName: + * @ctxt: an XML parser context + * + * Trickery: parse an XML name but without consuming the input flow + * Needed for rollback cases. + * + * [4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | + * CombiningChar | Extender + * + * [5] Name ::= (Letter | '_' | ':') (NameChar)* + * + * [6] Names ::= Name (S Name)* + * + * Returns the Name parsed or NULL + */ + +CHAR * +xmlScanName(xmlParserCtxtPtr ctxt) { + CHAR buf[XML_MAX_NAMELEN]; + int len = 0; + + GROW; + if (!IS_LETTER(CUR) && (CUR != '_') && + (CUR != ':')) { + return(NULL); + } + + while ((IS_LETTER(NXT(len))) || (IS_DIGIT(NXT(len))) || + (NXT(len) == '.') || (NXT(len) == '-') || + (NXT(len) == '_') || (NXT(len) == ':') || + (IS_COMBINING(NXT(len))) || + (IS_EXTENDER(NXT(len)))) { + buf[len] = NXT(len); + len++; + if (len >= XML_MAX_NAMELEN) { + fprintf(stderr, + "xmlScanName: reached XML_MAX_NAMELEN limit\n"); + while ((IS_LETTER(NXT(len))) || (IS_DIGIT(NXT(len))) || + (NXT(len) == '.') || (NXT(len) == '-') || + (NXT(len) == '_') || (NXT(len) == ':') || + (IS_COMBINING(NXT(len))) || + (IS_EXTENDER(NXT(len)))) + len++; + break; + } + } + return(xmlStrndup(buf, len)); +} + /** * xmlParseName: * @ctxt: an XML parser context @@ -1451,29 +2160,34 @@ CHAR * xmlParseName(xmlParserCtxtPtr ctxt) { CHAR buf[XML_MAX_NAMELEN]; int len = 0; + CHAR cur; GROW; - if (!IS_LETTER(CUR) && (CUR != '_') && - (CUR != ':')) { + cur = CUR; + if (!IS_LETTER(cur) && (cur != '_') && + (cur != ':')) { return(NULL); } - while ((IS_LETTER(CUR)) || (IS_DIGIT(CUR)) || - (CUR == '.') || (CUR == '-') || - (CUR == '_') || (CUR == ':') || - (IS_COMBINING(CUR)) || - (IS_EXTENDER(CUR))) { - buf[len++] = CUR; + while ((IS_LETTER(cur)) || (IS_DIGIT(cur)) || + (cur == '.') || (cur == '-') || + (cur == '_') || (cur == ':') || + (IS_COMBINING(cur)) || + (IS_EXTENDER(cur))) { + buf[len++] = cur; NEXT; + cur = CUR; if (len >= XML_MAX_NAMELEN) { fprintf(stderr, "xmlParseName: reached XML_MAX_NAMELEN limit\n"); - while ((IS_LETTER(CUR)) || (IS_DIGIT(CUR)) || - (CUR == '.') || (CUR == '-') || - (CUR == '_') || (CUR == ':') || - (IS_COMBINING(CUR)) || - (IS_EXTENDER(CUR))) - NEXT; + while ((IS_LETTER(cur)) || (IS_DIGIT(cur)) || + (cur == '.') || (cur == '-') || + (cur == '_') || (cur == ':') || + (IS_COMBINING(cur)) || + (IS_EXTENDER(cur))) { + NEXT; + cur = CUR; + } break; } } @@ -1540,44 +2254,125 @@ xmlParseEntityValue(xmlParserCtxtPtr ctxt, CHAR **orig) { const CHAR *org = NULL; const CHAR *tst = NULL; const CHAR *temp = NULL; + xmlParserInputPtr input; SHRINK; if (CUR == '"') { + ctxt->instate = XML_PARSER_ENTITY_VALUE; + input = ctxt->input; NEXT; org = CUR_PTR; - while (CUR != '"') { + /* + * NOTE: 4.4.5 Included in Literal + * When a parameter entity reference appears in a literal entity + * value, ... a single or double quote character in the replacement + * text is always treated as a normal data character and will not + * terminate the literal. + * In practice it means we stop the loop only when back at parsing + * the initial entity and the quote is found + */ + while ((CUR != '"') || (ctxt->input != input)) { tst = CUR_PTR; - temp = xmlDecodeEntities(ctxt, -1, XML_SUBSTITUTE_BOTH, '"', 0, 0); - if ((temp == NULL) && (tst == CUR_PTR)) break; + /* + * NOTE: 4.4.7 Bypassed + * When a general entity reference appears in the EntityValue in + * an entity declaration, it is bypassed and left as is. + * so XML_SUBSTITUTE_REF is not set. + */ + if (ctxt->input != input) + temp = xmlDecodeEntities(ctxt, -1, XML_SUBSTITUTE_PEREF, + 0, 0, 0); + else + temp = xmlDecodeEntities(ctxt, -1, XML_SUBSTITUTE_PEREF, + '"', 0, 0); + + /* + * Pop-up of finished entities. + */ + while ((CUR == 0) && (ctxt->inputNr > 1)) + xmlPopInput(ctxt); + + if ((temp == NULL) && (tst == CUR_PTR)) { + ret = xmlStrndup("", 0); + break; + } + if ((temp[0] == 0) && (tst == CUR_PTR)) { + free((char *)temp); + ret = xmlStrndup("", 0); + break; + } ret = xmlStrcat(ret, temp); if (temp != NULL) free((char *)temp); + GROW; } if (CUR != '"') { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) ctxt->sax->error(ctxt->userData, "EntityValue: \" expected\n"); ctxt->wellFormed = 0; } else { - if (orig != NULL) + if (orig != NULL) /* !!!!!!!!! */ *orig = xmlStrndup(org, CUR_PTR - org); + if (ret == NULL) + ret = xmlStrndup("", 0); NEXT; } } else if (CUR == '\'') { + ctxt->instate = XML_PARSER_ENTITY_VALUE; + input = ctxt->input; NEXT; org = CUR_PTR; - while (CUR != '\'') { + /* + * NOTE: 4.4.5 Included in Literal + * When a parameter entity reference appears in a literal entity + * value, ... a single or double quote character in the replacement + * text is always treated as a normal data character and will not + * terminate the literal. + * In practice it means we stop the loop only when back at parsing + * the initial entity and the quote is found + */ + while ((CUR != '\'') || (ctxt->input != input)) { tst = CUR_PTR; - temp = xmlDecodeEntities(ctxt, -1, XML_SUBSTITUTE_BOTH, '\'', 0, 0); - if ((temp == NULL) && (tst == CUR_PTR)) break; + /* + * NOTE: 4.4.7 Bypassed + * When a general entity reference appears in the EntityValue in + * an entity declaration, it is bypassed and left as is. + * so XML_SUBSTITUTE_REF is not set. + */ + if (ctxt->input != input) + temp = xmlDecodeEntities(ctxt, -1, XML_SUBSTITUTE_PEREF, + 0, 0, 0); + else + temp = xmlDecodeEntities(ctxt, -1, XML_SUBSTITUTE_PEREF, + '\'', 0, 0); + + /* + * Pop-up of finished entities. + */ + while ((CUR == 0) && (ctxt->inputNr > 1)) + xmlPopInput(ctxt); + + if ((temp == NULL) && (tst == CUR_PTR)) { + ret = xmlStrndup("", 0); + break; + } + if ((temp[0] == 0) && (tst == CUR_PTR)) { + free((char *)temp); + ret = xmlStrndup("", 0); + break; + } ret = xmlStrcat(ret, temp); if (temp != NULL) free((char *)temp); + GROW; } if (CUR != '\'') { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) ctxt->sax->error(ctxt->userData, "EntityValue: ' expected\n"); ctxt->wellFormed = 0; } else { - if (orig != NULL) + if (orig != NULL) /* !!!!!!!!! */ *orig = xmlStrndup(org, CUR_PTR - org); + if (ret == NULL) + ret = xmlStrndup("", 0); NEXT; } } else { @@ -1610,11 +2405,9 @@ xmlParseAttValue(xmlParserCtxtPtr ctxt) { SHRINK; if (CUR == '"') { + ctxt->instate = XML_PARSER_ATTRIBUTE_VALUE; NEXT; - if (ctxt->replaceEntities != 0) - ret = xmlDecodeEntities(ctxt, -1, XML_SUBSTITUTE_REF, '"', '<', 0); - else - ret = xmlDecodeEntities(ctxt, -1, XML_SUBSTITUTE_NONE, '"', '<', 0); + ret = xmlDecodeEntities(ctxt, -1, XML_SUBSTITUTE_REF, '"', '<', 0); if (CUR == '<') { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) ctxt->sax->error(ctxt->userData, @@ -1628,11 +2421,9 @@ xmlParseAttValue(xmlParserCtxtPtr ctxt) { } else NEXT; } else if (CUR == '\'') { + ctxt->instate = XML_PARSER_ATTRIBUTE_VALUE; NEXT; - if (ctxt->replaceEntities != 0) - ret = xmlDecodeEntities(ctxt, -1, XML_SUBSTITUTE_REF, '\'', '<', 0); - else - ret = xmlDecodeEntities(ctxt, -1, XML_SUBSTITUTE_NONE, '\'', '<', 0); + ret = xmlDecodeEntities(ctxt, -1, XML_SUBSTITUTE_REF, '\'', '<', 0); if (CUR == '<') { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) ctxt->sax->error(ctxt->userData, @@ -1774,11 +2565,18 @@ void xmlParseCharData(xmlParserCtxtPtr ctxt, int cdata) { CHAR buf[1000]; int nbchar = 0; + CHAR cur; SHRINK; - while ((IS_CHAR(CUR)) && (CUR != '<') && - (CUR != '&')) { - if ((CUR == ']') && (NXT(1) == ']') && + /* + * !!!!!!!!!!!! + * NOTE: NXT(0) is used here to avoid breaking on < or & + * entities substitutions. + */ + cur = CUR; + while ((IS_CHAR(cur)) && (cur != '<') && + (cur != '&')) { + if ((cur == ']') && (NXT(1) == ']') && (NXT(2) == '>')) { if (cdata) break; else { @@ -1806,6 +2604,7 @@ xmlParseCharData(xmlParserCtxtPtr ctxt, int cdata) { nbchar = 0; } NEXT; + cur = CUR; } if (nbchar != 0) { /* @@ -1944,6 +2743,7 @@ xmlParseComment(xmlParserCtxtPtr ctxt, int create) { if ((CUR != '<') || (NXT(1) != '!') || (NXT(2) != '-') || (NXT(3) != '-')) return; + ctxt->instate = XML_PARSER_COMMENT; SHRINK; SKIP(4); start = q = CUR_PTR; @@ -2028,9 +2828,6 @@ xmlParsePI(xmlParserCtxtPtr ctxt) { /* * Parse the target name and check for special support like * namespace. - * - * TODO : PI handling should be dynamically redefinable using an - * API. Only namespace should be in the code IMHO ... */ target = xmlParsePITarget(ctxt); if (target != NULL) { @@ -2055,24 +2852,16 @@ xmlParsePI(xmlParserCtxtPtr ctxt) { */ if ((ctxt->sax) && (ctxt->sax->processingInstruction != NULL)) - ctxt->sax->processingInstruction(ctxt->userData, target, data); + ctxt->sax->processingInstruction(ctxt->userData, + target, data); free(data); } free(target); } else { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, "xmlParsePI : no target name\n"); + ctxt->sax->error(ctxt->userData, + "xmlParsePI : no target name\n"); ctxt->wellFormed = 0; - - /********* Should we try to complete parsing the PI ??? - while (IS_CHAR(CUR) && - (CUR != '?') && (CUR != '>')) - NEXT; - if (!IS_CHAR(CUR)) { - fprintf(stderr, "xmlParsePI: PI %s never end ...\n", - target); - } - ********************************************************/ } } } @@ -2169,6 +2958,9 @@ xmlParseNotationDecl(xmlParserCtxtPtr ctxt) { * [74] PEDef ::= EntityValue | ExternalID * * [76] NDataDecl ::= S 'NDATA' S Name + * + * [ VC: Notation Declared ] + * TODO The Name must match the declared name of a notation. */ void @@ -2180,10 +2972,12 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) { int isParameter = 0; CHAR *orig = NULL; + GROW; if ((CUR == '<') && (NXT(1) == '!') && (NXT(2) == 'E') && (NXT(3) == 'N') && (NXT(4) == 'T') && (NXT(5) == 'I') && (NXT(6) == 'T') && (NXT(7) == 'Y')) { + ctxt->instate = XML_PARSER_ENTITY_DECL; SHRINK; SKIP(8); if (!IS_BLANK(CUR)) { @@ -2290,15 +3084,25 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) { NEXT; if (orig != NULL) { /* - * TODO: somwhat unclean, extending the SAx API would be better ! + * Ugly mechanism to save the raw entity value. */ xmlEntityPtr cur = NULL; - if ((ctxt->sax != NULL) && (ctxt->sax->getEntity != NULL)) - cur = ctxt->sax->getEntity(ctxt, name); - if (cur != NULL) - cur->orig = orig; - else + if (isParameter) { + if ((ctxt->sax != NULL) && + (ctxt->sax->getParameterEntity != NULL)) + cur = ctxt->sax->getParameterEntity(ctxt, name); + } else { + if ((ctxt->sax != NULL) && + (ctxt->sax->getEntity != NULL)) + cur = ctxt->sax->getEntity(ctxt, name); + } + if (cur != NULL) { + if (cur->orig != NULL) + free(orig); + else + cur->orig = orig; + } else free(orig); } if (name != NULL) free(name); @@ -2318,6 +3122,22 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) { * * [60] DefaultDecl ::= '#REQUIRED' | '#IMPLIED' | (('#FIXED' S)? AttValue) * + * [ VC: Required Attribute ] + * TODO if the default declaration is the keyword #REQUIRED, then the + * attribute must be specified for all elements of the type in the + * attribute-list declaration. + * + * [ VC: Attribute Default Legal ] + * The declared default value must meet the lexical constraints of + * the declared attribute type c.f. xmlValidateAttributeDecl() + * + * [ VC: Fixed Attribute Default ] + * TODO if an attribute has a default value declared with the #FIXED + * keyword, instances of that attribute must match the default value. + * + * [ WFC: No < in Attribute Values ] + * handled in xmlParseAttValue() + * * returns: XML_ATTRIBUTE_NONE, XML_ATTRIBUTE_REQUIRED, XML_ATTRIBUTE_IMPLIED * or XML_ATTRIBUTE_FIXED. */ @@ -2357,6 +3177,7 @@ xmlParseDefaultDecl(xmlParserCtxtPtr ctxt, CHAR **value) { SKIP_BLANKS; } ret = xmlParseAttValue(ctxt); + ctxt->instate = XML_PARSER_DTD; if (ret == NULL) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) ctxt->sax->error(ctxt->userData, @@ -2373,9 +3194,13 @@ xmlParseDefaultDecl(xmlParserCtxtPtr ctxt, CHAR **value) { * * parse an Notation attribute type. * + * Note: the leading 'NOTATION' S part has already being parsed... + * * [58] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')' * - * Note: the leading 'NOTATION' S part has already being parsed... + * [ VC: Notation Attributes ] + * TODO Values of this type must match one of the notation names included + * in the declaration; all notation names in the declaration must be declared. * * Returns: the notation attribute tree built while parsing */ @@ -2432,6 +3257,10 @@ xmlParseNotationType(xmlParserCtxtPtr ctxt) { * * [59] Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')' * + * [ VC: Enumeration ] + * TODO Values of this type must match one of the Nmtoken tokens in + * the declaration + * * Returns: the enumeration attribute tree built while parsing */ @@ -2532,6 +3361,35 @@ xmlParseEnumeratedType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree) { * [56] TokenizedType ::= 'ID' | 'IDREF' | 'IDREFS' | 'ENTITY' | * 'ENTITIES' | 'NMTOKEN' | 'NMTOKENS' * + * Validity constraints for attribute values syntax are checked in + * xmlValidateAttributeValue() + * + * [ VC: ID ] + * Values of type ID must match the Name production. TODO A name must not + * appear more than once in an XML document as a value of this type; + * i.e., ID values must uniquely identify the elements which bear them. + * + * [ VC: One ID per Element Type ] + * TODO No element type may have more than one ID attribute specified. + * + * [ VC: ID Attribute Default ] + * TODO An ID attribute must have a declared default of #IMPLIED or #REQUIRED. + * + * [ VC: IDREF ] + * Values of type IDREF must match the Name production, and values + * of type IDREFS must match Names; TODO each Name must match the value of + * an ID attribute on some element in the XML document; i.e. IDREF + * values must match the value of some ID attribute. + * + * [ VC: Entity Name ] + * Values of type ENTITY must match the Name production, values + * of type ENTITIES must match Names; TODO each Name must match the name of + * an unparsed entity declared in the DTD. + * + * [ VC: Name Token ] + * Values of type NMTOKEN must match the Nmtoken production; values + * of type NMTOKENS must match Nmtokens. + * * Returns the attribute type */ int @@ -2542,6 +3400,11 @@ xmlParseAttributeType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree) { (NXT(4) == 'A')) { SKIP(5); return(XML_ATTRIBUTE_CDATA); + } else if ((CUR == 'I') && (NXT(1) == 'D') && + (NXT(2) == 'R') && (NXT(3) == 'E') && + (NXT(4) == 'F') && (NXT(5) == 'S')) { + SKIP(6); + return(XML_ATTRIBUTE_IDREFS); } else if ((CUR == 'I') && (NXT(1) == 'D') && (NXT(2) == 'R') && (NXT(3) == 'E') && (NXT(4) == 'F')) { @@ -2550,11 +3413,6 @@ xmlParseAttributeType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree) { } else if ((CUR == 'I') && (NXT(1) == 'D')) { SKIP(2); return(XML_ATTRIBUTE_ID); - } else if ((CUR == 'I') && (NXT(1) == 'D') && - (NXT(2) == 'R') && (NXT(3) == 'E') && - (NXT(4) == 'F') && (NXT(5) == 'S')) { - SKIP(6); - return(XML_ATTRIBUTE_IDREFS); } else if ((CUR == 'E') && (NXT(1) == 'N') && (NXT(2) == 'T') && (NXT(3) == 'I') && (NXT(4) == 'T') && (NXT(5) == 'Y')) { @@ -2597,7 +3455,7 @@ void xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) { CHAR *elemName; CHAR *attrName; - xmlEnumerationPtr tree = NULL; + xmlEnumerationPtr tree; if ((CUR == '<') && (NXT(1) == '!') && (NXT(2) == 'A') && (NXT(3) == 'T') && @@ -2625,6 +3483,7 @@ xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) { int def; CHAR *defaultValue = NULL; + tree = NULL; attrName = xmlParseName(ctxt); if (attrName == NULL) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) @@ -2632,6 +3491,7 @@ xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) { ctxt->wellFormed = 0; break; } + GROW; if (!IS_BLANK(CUR)) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) ctxt->sax->error(ctxt->userData, @@ -2644,6 +3504,7 @@ xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) { type = xmlParseAttributeType(ctxt, &tree); if (type <= 0) break; + GROW; if (!IS_BLANK(CUR)) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) ctxt->sax->error(ctxt->userData, @@ -2656,6 +3517,7 @@ xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) { def = xmlParseDefaultDecl(ctxt, &defaultValue); if (def <= 0) break; + GROW; if (CUR != '>') { if (!IS_BLANK(CUR)) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) @@ -2679,6 +3541,7 @@ xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) { free(attrName); if (defaultValue != NULL) free(defaultValue); + GROW; } if (CUR == '>') NEXT; @@ -2697,6 +3560,12 @@ xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) { * [51] Mixed ::= '(' S? '#PCDATA' (S? '|' S? Name)* S? ')*' | * '(' S? '#PCDATA' S? ')' * + * [ VC: Proper Group/PE Nesting ] applies to [51] too (see [49]) + * + * [ VC: No Duplicate Types ] + * TODO The same name must not appear more than once in a single + * mixed-content declaration. + * * returns: the list of the xmlElementContentPtr describing the element choices */ xmlElementContentPtr @@ -2704,6 +3573,7 @@ xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt) { xmlElementContentPtr ret = NULL, cur = NULL, n; CHAR *elem = NULL; + GROW; if ((CUR == '#') && (NXT(1) == 'P') && (NXT(2) == 'C') && (NXT(3) == 'D') && (NXT(4) == 'A') && (NXT(5) == 'T') && @@ -2719,13 +3589,7 @@ xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt) { if ((CUR == '(') || (CUR == '|')) { ret = cur = xmlNewElementContent(NULL, XML_ELEMENT_CONTENT_PCDATA); if (ret == NULL) return(NULL); - } /********** else { - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, - "xmlParseElementMixedContentDecl : '|' or ')' expected\n"); - ctxt->wellFormed = 0; - return(NULL); - } **********/ + } while (CUR == '|') { NEXT; if (elem == NULL) { @@ -2752,6 +3616,7 @@ xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt) { return(NULL); } SKIP_BLANKS; + GROW; } if ((CUR == ')') && (NXT(1) == '*')) { if (elem != NULL) { @@ -2796,6 +3661,17 @@ xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt) { * * [50] seq ::= '(' S? cp ( S? ',' S? cp )* S? ')' * + * [ VC: Proper Group/PE Nesting ] applies to [49] and [50] + * TODO Parameter-entity replacement text must be properly nested + * with parenthetized groups. That is to say, if either of the + * opening or closing parentheses in a choice, seq, or Mixed + * construct is contained in the replacement text for a parameter + * entity, both must be contained in the same replacement text. For + * interoperability, if a parameter-entity reference appears in a + * choice, seq, or Mixed construct, its replacement text should not + * be empty, and neither the first nor last non-blank character of + * the replacement text should be a connector (| or ,). + * * returns: the tree of xmlElementContentPtr describing the element * hierarchy. */ @@ -2806,12 +3682,14 @@ xmlParseElementChildrenContentDecl(xmlParserCtxtPtr ctxt) { CHAR type = 0; SKIP_BLANKS; + GROW; if (CUR == '(') { /* Recurse on first child */ NEXT; SKIP_BLANKS; cur = ret = xmlParseElementChildrenContentDecl(ctxt); SKIP_BLANKS; + GROW; } else { elem = xmlParseName(ctxt); if (elem == NULL) { @@ -2822,19 +3700,21 @@ xmlParseElementChildrenContentDecl(xmlParserCtxtPtr ctxt) { return(NULL); } cur = ret = xmlNewElementContent(elem, XML_ELEMENT_CONTENT_ELEMENT); + GROW; if (CUR == '?') { - ret->ocur = XML_ELEMENT_CONTENT_OPT; + cur->ocur = XML_ELEMENT_CONTENT_OPT; NEXT; } else if (CUR == '*') { - ret->ocur = XML_ELEMENT_CONTENT_MULT; + cur->ocur = XML_ELEMENT_CONTENT_MULT; NEXT; } else if (CUR == '+') { - ret->ocur = XML_ELEMENT_CONTENT_PLUS; + cur->ocur = XML_ELEMENT_CONTENT_PLUS; NEXT; } else { - ret->ocur = XML_ELEMENT_CONTENT_ONCE; + cur->ocur = XML_ELEMENT_CONTENT_ONCE; } free(elem); + GROW; } SKIP_BLANKS; SHRINK; @@ -2912,7 +3792,9 @@ xmlParseElementChildrenContentDecl(xmlParserCtxtPtr ctxt) { xmlFreeElementContent(ret); return(NULL); } + GROW; SKIP_BLANKS; + GROW; if (CUR == '(') { /* Recurse on second child */ NEXT; @@ -2930,20 +3812,21 @@ xmlParseElementChildrenContentDecl(xmlParserCtxtPtr ctxt) { } last = xmlNewElementContent(elem, XML_ELEMENT_CONTENT_ELEMENT); free(elem); - } - if (CUR == '?') { - ret->ocur = XML_ELEMENT_CONTENT_OPT; - NEXT; - } else if (CUR == '*') { - ret->ocur = XML_ELEMENT_CONTENT_MULT; - NEXT; - } else if (CUR == '+') { - ret->ocur = XML_ELEMENT_CONTENT_PLUS; - NEXT; - } else { - ret->ocur = XML_ELEMENT_CONTENT_ONCE; + if (CUR == '?') { + last->ocur = XML_ELEMENT_CONTENT_OPT; + NEXT; + } else if (CUR == '*') { + last->ocur = XML_ELEMENT_CONTENT_MULT; + NEXT; + } else if (CUR == '+') { + last->ocur = XML_ELEMENT_CONTENT_PLUS; + NEXT; + } else { + last->ocur = XML_ELEMENT_CONTENT_ONCE; + } } SKIP_BLANKS; + GROW; } if ((cur != NULL) && (last != NULL)) { cur->c2 = last; @@ -2958,8 +3841,6 @@ xmlParseElementChildrenContentDecl(xmlParserCtxtPtr ctxt) { } else if (CUR == '+') { ret->ocur = XML_ELEMENT_CONTENT_PLUS; NEXT; - } else { - ret->ocur = XML_ELEMENT_CONTENT_ONCE; } return(ret); } @@ -2995,6 +3876,7 @@ xmlParseElementContentDecl(xmlParserCtxtPtr ctxt, CHAR *name, return(-1); } NEXT; + GROW; SKIP_BLANKS; if ((CUR == '#') && (NXT(1) == 'P') && (NXT(2) == 'C') && (NXT(3) == 'D') && @@ -3028,7 +3910,8 @@ xmlParseElementContentDecl(xmlParserCtxtPtr ctxt, CHAR *name, * * [45] elementdecl ::= '' * - * TODO There is a check [ VC: Unique Element Type Declaration ] + * [ VC: Unique Element Type Declaration ] + * TODO No element type may be declared more than once * * Returns the type of the element, or -1 in case of error */ @@ -3038,6 +3921,7 @@ xmlParseElementDecl(xmlParserCtxtPtr ctxt) { int ret = -1; xmlElementContentPtr content = NULL; + GROW; if ((CUR == '<') && (NXT(1) == '!') && (NXT(2) == 'E') && (NXT(3) == 'L') && (NXT(4) == 'E') && (NXT(5) == 'M') && @@ -3084,9 +3968,19 @@ xmlParseElementDecl(xmlParserCtxtPtr ctxt) { } else if (CUR == '(') { ret = xmlParseElementContentDecl(ctxt, name, &content); } else { - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, - "xmlParseElementDecl: 'EMPTY', 'ANY' or '(' expected\n"); + /* + * [ WFC: PEs in Internal Subset ] error handling. + */ + if ((CUR == '%') && (ctxt->external == 0) && + (ctxt->inputNr == 1)) { + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "PEReference: forbidden within markup decl in internal subset\n"); + } else { + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "xmlParseElementDecl: 'EMPTY', 'ANY' or '(' expected\n"); + } ctxt->wellFormed = 0; if (name != NULL) free(name); return(-1); @@ -3122,16 +4016,35 @@ xmlParseElementDecl(xmlParserCtxtPtr ctxt) { * [29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl | * NotationDecl | PI | Comment * - * TODO There is a check [ VC: Proper Declaration/PE Nesting ] + * [ VC: Proper Declaration/PE Nesting ] + * TODO Parameter-entity replacement text must be properly nested with + * markup declarations. That is to say, if either the first character + * or the last character of a markup declaration (markupdecl above) is + * contained in the replacement text for a parameter-entity reference, + * both must be contained in the same replacement text. + * + * [ WFC: PEs in Internal Subset ] + * In the internal DTD subset, parameter-entity references can occur + * only where markup declarations can occur, not within markup declarations. + * (This does not apply to references that occur in external parameter + * entities or to the external subset.) */ void xmlParseMarkupDecl(xmlParserCtxtPtr ctxt) { + GROW; xmlParseElementDecl(ctxt); xmlParseAttributeListDecl(ctxt); xmlParseEntityDecl(ctxt); xmlParseNotationDecl(ctxt); xmlParsePI(ctxt); xmlParseComment(ctxt, 0); + /* + * This is only for internal subset. On external entities, + * the replacement is done before parsing stage + */ + if ((ctxt->external == 0) && (ctxt->inputNr == 1)) + xmlParsePEReference(ctxt); + ctxt->instate = XML_PARSER_DTD; } /** @@ -3166,11 +4079,13 @@ xmlParseTextDecl(xmlParserCtxtPtr ctxt) { * We may have the VersionInfo here. */ version = xmlParseVersionInfo(ctxt); + /* TODO: we should actually inherit from the referencing doc if absent if (version == NULL) version = xmlCharStrdup(XML_DEFAULT_VERSION); ctxt->version = xmlStrdup(version); */ + if (version != NULL) free(version); @@ -3260,6 +4175,8 @@ xmlParseExternalSubset(xmlParserCtxtPtr ctxt, const CHAR *ExternalID, if ((ctxt->myDoc != NULL) && (ctxt->myDoc->intSubset == NULL)) xmlCreateIntSubset(ctxt->myDoc, NULL, ExternalID, SystemID); + ctxt->instate = XML_PARSER_DTD; + ctxt->external = 1; while (((CUR == '<') && (NXT(1) == '?')) || ((CUR == '<') && (NXT(1) == '!')) || IS_BLANK(CUR)) { @@ -3289,79 +4206,6 @@ xmlParseExternalSubset(xmlParserCtxtPtr ctxt, const CHAR *ExternalID, } -/** - * xmlParseCharRef: - * @ctxt: an XML parser context - * - * parse Reference declarations - * - * [66] CharRef ::= '&#' [0-9]+ ';' | - * '&#x' [0-9a-fA-F]+ ';' - * - * Returns the value parsed (as an int) - */ -int -xmlParseCharRef(xmlParserCtxtPtr ctxt) { - int val = 0; - - if ((CUR == '&') && (NXT(1) == '#') && - (NXT(2) == 'x')) { - SKIP(3); - while (CUR != ';') { - if ((CUR >= '0') && (CUR <= '9')) - val = val * 16 + (CUR - '0'); - else if ((CUR >= 'a') && (CUR <= 'f')) - val = val * 16 + (CUR - 'a') + 10; - else if ((CUR >= 'A') && (CUR <= 'F')) - val = val * 16 + (CUR - 'A') + 10; - else { - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, - "xmlParseCharRef: invalid hexadecimal value\n"); - ctxt->wellFormed = 0; - val = 0; - break; - } - NEXT; - } - if (CUR == ';') - NEXT; - } else if ((CUR == '&') && (NXT(1) == '#')) { - SKIP(2); - while (CUR != ';') { - if ((CUR >= '0') && (CUR <= '9')) - val = val * 10 + (CUR - '0'); - else { - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, - "xmlParseCharRef: invalid decimal value\n"); - ctxt->wellFormed = 0; - val = 0; - break; - } - NEXT; - } - if (CUR == ';') - NEXT; - } else { - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, "xmlParseCharRef: invalid value\n"); - ctxt->wellFormed = 0; - } - /* - * Check the value IS_CHAR ... - */ - if (IS_CHAR(val)) { - return(val); - } else { - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, "xmlParseCharRef: invalid CHAR value %d\n", - val); - ctxt->wellFormed = 0; - } - return(0); -} - /** * xmlParseReference: * @ctxt: an XML parser context @@ -3419,6 +4263,24 @@ xmlParseReference(xmlParserCtxtPtr ctxt) { * * [68] EntityRef ::= '&' Name ';' * + * [ WFC: Entity Declared ] + * In a document without any DTD, a document with only an internal DTD + * subset which contains no parameter entity references, or a document + * with "standalone='yes'", the Name given in the entity reference + * must match that in an entity declaration, except that well-formed + * documents need not declare any of the following entities: amp, lt, + * gt, apos, quot. The declaration of a parameter entity must precede + * any reference to it. Similarly, the declaration of a general entity + * must precede any reference to it which appears in a default value in an + * attribute-list declaration. Note that if entities are declared in the + * external subset or in external parameter entities, a non-validating + * processor is not obligated to read and process their declarations; + * for such documents, the rule that an entity must be declared is a + * well-formedness constraint only if standalone='yes'. + * + * [ WFC: Parsed Entity ] + * An entity reference must not contain the name of an unparsed entity + * * Returns the xmlEntityPtr if found, or NULL otherwise. */ xmlEntityPtr @@ -3427,12 +4289,14 @@ xmlParseEntityRef(xmlParserCtxtPtr ctxt) { xmlEntityPtr ent = NULL; GROW; + if (CUR == '&') { NEXT; name = xmlParseName(ctxt); if (name == NULL) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, "xmlParseEntityRef: no name\n"); + ctxt->sax->error(ctxt->userData, + "xmlParseEntityRef: no name\n"); ctxt->wellFormed = 0; } else { if (CUR == ';') { @@ -3447,42 +4311,86 @@ xmlParseEntityRef(xmlParserCtxtPtr ctxt) { if (ent == NULL) ent = xmlGetPredefinedEntity(name); } - /* - * Well Formedness Constraint if: - * - standalone - * or - * - no external subset and no external parameter entities - * referenced - * then - * the entity referenced must have been declared - * - * TODO: to be double checked !!! This is wrong ! + * [ WFC: Entity Declared ] + * In a document without any DTD, a document with only an + * internal DTD subset which contains no parameter entity + * references, or a document with "standalone='yes'", the + * Name given in the entity reference must match that in an + * entity declaration, except that well-formed documents + * need not declare any of the following entities: amp, lt, + * gt, apos, quot. + * The declaration of a parameter entity must precede any + * reference to it. + * Similarly, the declaration of a general entity must + * precede any reference to it which appears in a default + * value in an attribute-list declaration. Note that if + * entities are declared in the external subset or in + * external parameter entities, a non-validating processor + * is not obligated to read and process their declarations; + * for such documents, the rule that an entity must be + * declared is a well-formedness constraint only if + * standalone='yes'. */ if (ent == NULL) { - if (ctxt->sax != NULL) { - if (((ctxt->sax->isStandalone != NULL) && - ctxt->sax->isStandalone(ctxt->userData) == 1) || - (((ctxt->sax->hasInternalSubset == NULL) || - ctxt->sax->hasInternalSubset(ctxt->userData) == 0) && - ((ctxt->sax->hasExternalSubset == NULL) || - ctxt->sax->hasExternalSubset(ctxt->userData) == 0))) { - if (ctxt->sax->error != NULL) + if ((ctxt->standalone == 1) || + ((ctxt->hasExternalSubset == 0) && + (ctxt->hasPErefs == 0))) { + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) ctxt->sax->error(ctxt->userData, "Entity '%s' not defined\n", name); ctxt->wellFormed = 0; - } } else { - fprintf(stderr, "Entity '%s' not defined\n", name); - ctxt->wellFormed = 0; + if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) + ctxt->sax->warning(ctxt->userData, + "Entity '%s' not defined\n", name); } } /* - * Well Formedness Constraint : - * The referenced entity must be a parsed entity. + * [ WFC: Parsed Entity ] + * An entity reference must not contain the name of an + * unparsed entity */ - if (ent != NULL) { + else if (ent->type == XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) { + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "Entity reference to unparsed entity %s\n", name); + ctxt->wellFormed = 0; + } + + /* + * [ WFC: No External Entity References ] + * Attribute values cannot contain direct or indirect + * entity references to external entities. + */ + else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) && + (ent->type == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) { + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "Attribute references external entity '%s'\n", name); + ctxt->wellFormed = 0; + } + /* + * [ WFC: No < in Attribute Values ] + * The replacement text of any entity referred to directly or + * indirectly in an attribute value (other than "<") must + * not contain a <. + */ + else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) && + (ent != NULL) && (xmlStrcmp(ent->name, "lt")) && + (ent->content != NULL) && + (xmlStrchr(ent->content, '<'))) { + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "'<' in entity '%s' is not allowed in attributes values\n", name); + ctxt->wellFormed = 0; + } + + /* + * Internal check, no parameter entities here ... + */ + else { switch (ent->type) { case XML_INTERNAL_PARAMETER_ENTITY: case XML_EXTERNAL_PARAMETER_ENTITY: @@ -3491,22 +4399,14 @@ xmlParseEntityRef(xmlParserCtxtPtr ctxt) { "Attempt to reference the parameter entity '%s'\n", name); ctxt->wellFormed = 0; break; - - case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY: - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, - "Attempt to reference unparsed entity '%s'\n", name); - ctxt->wellFormed = 0; - break; } } /* - * TODO: !!! - * Well Formedness Constraint : - * The referenced entity must not lead to recursion ! + * [ WFC: No Recursion ] + * TODO A parsed entity must not contain a recursive + * reference to itself, either directly or indirectly. */ - } else { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) @@ -3530,6 +4430,24 @@ xmlParseEntityRef(xmlParserCtxtPtr ctxt) { * * [69] PEReference ::= '%' Name ';' * + * [ WFC: No Recursion ] + * TODO A parsed entity must not contain a recursive + * reference to itself, either directly or indirectly. + * + * [ WFC: Entity Declared ] + * In a document without any DTD, a document with only an internal DTD + * subset which contains no parameter entity references, or a document + * with "standalone='yes'", ... ... The declaration of a parameter + * entity must precede any reference to it... + * + * [ VC: Entity Declared ] + * In a document with an external subset or external parameter entities + * with "standalone='no'", ... ... The declaration of a parameter entity + * must precede any reference to it... + * + * [ WFC: In DTD ] + * Parameter-entity references may only appear in the DTD. + * NOTE: misleading but this is handled. */ void xmlParsePEReference(xmlParserCtxtPtr ctxt) { @@ -3547,17 +4465,54 @@ xmlParsePEReference(xmlParserCtxtPtr ctxt) { } else { if (CUR == ';') { NEXT; - if ((ctxt->sax != NULL) && (ctxt->sax->getEntity != NULL)) - entity = ctxt->sax->getEntity(ctxt->userData, name); - /* TODO !!!! Must check that it's of the proper type !!! */ + if ((ctxt->sax != NULL) && + (ctxt->sax->getParameterEntity != NULL)) + entity = ctxt->sax->getParameterEntity(ctxt->userData, + name); if (entity == NULL) { - if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) - ctxt->sax->warning(ctxt->userData, - "xmlParsePEReference: %%%s; not found\n", name); + /* + * [ WFC: Entity Declared ] + * In a document without any DTD, a document with only an + * internal DTD subset which contains no parameter entity + * references, or a document with "standalone='yes'", ... + * ... The declaration of a parameter entity must precede + * any reference to it... + */ + if ((ctxt->standalone == 1) || + ((ctxt->hasExternalSubset == 0) && + (ctxt->hasPErefs == 0))) { + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, + "PEReference: %%%s; not found\n", name); + ctxt->wellFormed = 0; + } else { + /* + * [ VC: Entity Declared ] + * In a document with an external subset or external + * parameter entities with "standalone='no'", ... + * ... The declaration of a parameter entity must precede + * any reference to it... + */ + if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) + ctxt->sax->warning(ctxt->userData, + "PEReference: %%%s; not found\n", name); + ctxt->valid = 0; + } } else { - input = xmlNewEntityInputStream(ctxt, entity); - xmlPushInput(ctxt, input); + /* + * Internal checking in case the entity quest barfed + */ + if ((entity->type != XML_INTERNAL_PARAMETER_ENTITY) && + (entity->type != XML_EXTERNAL_PARAMETER_ENTITY)) { + if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) + ctxt->sax->warning(ctxt->userData, + "Internal: %%%s; is not a parameter entity\n", name); + } else { + input = xmlNewEntityInputStream(ctxt, entity); + xmlPushInput(ctxt, input); + } } + ctxt->hasPErefs = 1; } else { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) ctxt->sax->error(ctxt->userData, @@ -3577,6 +4532,10 @@ xmlParsePEReference(xmlParserCtxtPtr ctxt) { * * [28] doctypedecl ::= '' + * + * [ VC: Root Element Type ] + * The Name in the document type declaration must match the element + * type of the root element. */ void @@ -3608,6 +4567,11 @@ xmlParseDocTypeDecl(xmlParserCtxtPtr ctxt) { * Check for SystemID and ExternalID */ URI = xmlParseExternalID(ctxt, &ExternalID, 1); + + if ((URI != NULL) || (ExternalID != NULL)) { + ctxt->hasExternalSubset = 1; + } + SKIP_BLANKS; /* @@ -3621,6 +4585,7 @@ xmlParseDocTypeDecl(xmlParserCtxtPtr ctxt) { * Is there any DTD definition ? */ if (CUR == '[') { + ctxt->instate = XML_PARSER_DTD; NEXT; /* * Parse the succession of Markup declarations and @@ -3664,8 +4629,7 @@ xmlParseDocTypeDecl(xmlParserCtxtPtr ctxt) { NEXT; /* - * Cleanup, since we don't use all those identifiers - * TODO : the DOCTYPE if available should be stored ! + * Cleanup */ if (URI != NULL) free(URI); if (ExternalID != NULL) free(ExternalID); @@ -3681,6 +4645,18 @@ xmlParseDocTypeDecl(xmlParserCtxtPtr ctxt) { * * [41] Attribute ::= Name Eq AttValue * + * [ WFC: No External Entity References ] + * Attribute values cannot contain direct or indirect entity references + * to external entities. + * + * [ WFC: No < in Attribute Values ] + * The replacement text of any entity referred to directly or indirectly in + * an attribute value (other than "<") must not contain a <. + * + * [ VC: Attribute Value Type ] + * TODO The attribute must have been declared; the value must be of the type + * declared for it. + * * [25] Eq ::= S? '=' S? * * With namespace: @@ -3714,6 +4690,7 @@ xmlParseAttribute(xmlParserCtxtPtr ctxt, CHAR **value) { NEXT; SKIP_BLANKS; val = xmlParseAttValue(ctxt); + ctxt->instate = XML_PARSER_CONTENT; } else { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) ctxt->sax->error(ctxt->userData, @@ -3735,8 +4712,16 @@ xmlParseAttribute(xmlParserCtxtPtr ctxt, CHAR **value) { * * [40] STag ::= '<' Name (S Attribute)* S? '>' * + * [ WFC: Unique Att Spec ] + * No attribute name may appear more than once in the same start-tag or + * empty-element tag. + * * [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>' * + * [ WFC: Unique Att Spec ] + * No attribute name may appear more than once in the same start-tag or + * empty-element tag. + * * With namespace: * * [NS 8] STag ::= '<' QName (S Attribute)* S? '>' @@ -3784,17 +4769,20 @@ xmlParseStartTag(xmlParserCtxtPtr ctxt) { attname = xmlParseAttribute(ctxt, &attvalue); if ((attname != NULL) && (attvalue != NULL)) { /* - * Well formedness requires at most one declaration of an attribute + * [ WFC: Unique Att Spec ] + * No attribute name may appear more than once in the same + * start-tag or empty-element tag. */ for (i = 0; i < nbatts;i += 2) { if (!xmlStrcmp(atts[i], attname)) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, "Attribute %s redefined\n", - name); + ctxt->sax->error(ctxt->userData, + "Attribute %s redefined\n", + attname); ctxt->wellFormed = 0; free(attname); free(attvalue); - break; + goto failed; } } @@ -3822,6 +4810,7 @@ xmlParseStartTag(xmlParserCtxtPtr ctxt) { atts[nbatts++] = attvalue; atts[nbatts] = NULL; atts[nbatts + 1] = NULL; +failed: } SKIP_BLANKS; @@ -3890,7 +4879,10 @@ xmlParseEndTag(xmlParserCtxtPtr ctxt, CHAR *tagname) { NEXT; /* - * Well formedness constraints, opening and closing must match. + * [ WFC: Element Type Match ] + * The Name in an element's end-tag must match the element type in the + * start-tag. + * */ if (xmlStrcmp(name, tagname)) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) @@ -3927,9 +4919,11 @@ xmlParseEndTag(xmlParserCtxtPtr ctxt, CHAR *tagname) { */ void xmlParseCDSect(xmlParserCtxtPtr ctxt) { - const CHAR *r, *s, *base; + const CHAR *base; + CHAR r, s; + CHAR cur; - if ((CUR == '<') && (NXT(1) == '!') && + if ((NXT(0) == '<') && (NXT(1) == '!') && (NXT(2) == '[') && (NXT(3) == 'C') && (NXT(4) == 'D') && (NXT(5) == 'A') && (NXT(6) == 'T') && (NXT(7) == 'A') && @@ -3937,46 +4931,50 @@ xmlParseCDSect(xmlParserCtxtPtr ctxt) { SKIP(9); } else return; + + ctxt->instate = XML_PARSER_CDATA_SECTION; base = CUR_PTR; if (!IS_CHAR(CUR)) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) ctxt->sax->error(ctxt->userData, "CData section not finished\n%.50s\n", base); ctxt->wellFormed = 0; + ctxt->instate = XML_PARSER_CONTENT; return; } - r = CUR_PTR; + r = CUR; NEXT; + if (!IS_CHAR(CUR)) { + if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) + ctxt->sax->error(ctxt->userData, "CData section not finished\n%.50s\n", base); + ctxt->wellFormed = 0; + ctxt->instate = XML_PARSER_CONTENT; + return; + } + s = CUR; + NEXT; + cur = CUR; + while (IS_CHAR(cur) && + ((r != ']') || (s != ']') || (cur != '>'))) { + r = s; + s = cur; + NEXT; + cur = CUR; + } + ctxt->instate = XML_PARSER_CONTENT; if (!IS_CHAR(CUR)) { if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) ctxt->sax->error(ctxt->userData, "CData section not finished\n%.50s\n", base); ctxt->wellFormed = 0; return; } - s = CUR_PTR; NEXT; - while (IS_CHAR(CUR) && - ((*r != ']') || (*s != ']') || (CUR != '>'))) { - r++;s++;NEXT; - } - if (!IS_CHAR(CUR)) { - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, "CData section not finished\n%.50s\n", base); - ctxt->wellFormed = 0; - return; - } /* * Ok the segment [base CUR_PTR] is to be consumed as chars. */ if (ctxt->sax != NULL) { - if (areBlanks(ctxt, base, CUR_PTR - base)) { - if (ctxt->sax->ignorableWhitespace != NULL) - ctxt->sax->ignorableWhitespace(ctxt->userData, base, - (CUR_PTR - base) - 2); - } else { - if (ctxt->sax->characters != NULL) - ctxt->sax->characters(ctxt->userData, base, (CUR_PTR - base) - 2); - } + if (ctxt->sax->cdataBlock != NULL) + ctxt->sax->cdataBlock(ctxt->userData, base, (CUR_PTR - base) - 3); } } @@ -3991,6 +4989,7 @@ xmlParseCDSect(xmlParserCtxtPtr ctxt) { void xmlParseContent(xmlParserCtxtPtr ctxt) { + GROW; while ((CUR != '<') || (NXT(1) != '/')) { const CHAR *test = CUR_PTR; int cons = ctxt->input->consumed; @@ -4019,6 +5018,7 @@ xmlParseContent(xmlParserCtxtPtr ctxt) { else if ((CUR == '<') && (NXT(1) == '!') && (NXT(2) == '-') && (NXT(3) == '-')) { xmlParseComment(ctxt, 1); + ctxt->instate = XML_PARSER_CONTENT; } /* @@ -4032,6 +5032,7 @@ xmlParseContent(xmlParserCtxtPtr ctxt) { * Fifth case : a reference. If if has not been resolved, * parsing returns it's Name, create the node */ + else if (CUR == '&') { xmlParseReference(ctxt); } @@ -4068,7 +5069,22 @@ xmlParseContent(xmlParserCtxtPtr ctxt) { * * [39] element ::= EmptyElemTag | STag content ETag * - * [41] Attribute ::= Name Eq AttValue + * [ WFC: Element Type Match ] + * The Name in an element's end-tag must match the element type in the + * start-tag. + * + * [ VC: Element Valid ] + * TODO An element is valid if there is a declaration matching elementdecl + * where the Name matches the element type and one of the following holds: + * - The declaration matches EMPTY and the element has no content. + * - The declaration matches children and the sequence of child elements + * belongs to the language generated by the regular expression in the + * content model, with optional white space (characters matching the + * nonterminal S) between each pair of child elements. + * - The declaration matches Mixed and the content consists of character + * data and child elements whose types match names in the content model. + * - The declaration matches ANY, and the types of any child elements have + * been declared. */ void @@ -4086,6 +5102,15 @@ xmlParseElement(xmlParserCtxtPtr ctxt) { return; } + /* + * [ VC: Root Element Type ] + * The Name in the document type declaration must match the element + * type of the root element. + */ + if (ctxt->validate && ctxt->wellFormed && ctxt->myDoc && + ctxt->node && (ctxt->node == ctxt->myDoc->root)) + ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc); + /* * Check for an Empty Element. */ @@ -4328,6 +5353,20 @@ xmlParseEncodingDecl(xmlParserCtxtPtr ctxt) { * [32] SDDecl ::= S 'standalone' Eq * (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no')'"')) * + * [ VC: Standalone Document Declaration ] + * TODO The standalone document declaration must have the value "no" + * if any external markup declarations contain declarations of: + * - attributes with default values, if elements to which these + * attributes apply appear in the document without specifications + * of values for these attributes, or + * - entities (other than amp, lt, gt, apos, quot), if references + * to those entities appear in the document, or + * - attributes with values subject to normalization, where the + * attribute appears in the document with a value which will change + * as a result of normalization, or + * - element types with element content, if white space occurs directly + * within any instance of those types. + * * Returns 1 if standalone, 0 otherwise */ @@ -4599,6 +5638,7 @@ xmlParseDocument(xmlParserCtxtPtr ctxt) { (NXT(6) == 'Y') && (NXT(7) == 'P') && (NXT(8) == 'E')) { xmlParseDocTypeDecl(ctxt); + ctxt->instate = XML_PARSER_PROLOG; xmlParseMisc(ctxt); } @@ -4606,7 +5646,9 @@ xmlParseDocument(xmlParserCtxtPtr ctxt) { * Time to start parsing the tree itself */ GROW; + ctxt->instate = XML_PARSER_CONTENT; xmlParseElement(ctxt); + ctxt->instate = XML_PARSER_EPILOG; /* * The Misc part at the end @@ -4619,6 +5661,7 @@ xmlParseDocument(xmlParserCtxtPtr ctxt) { "Extra content at the end of the document\n"); ctxt->wellFormed = 0; } + ctxt->instate = XML_PARSER_EOF; /* * SAX: end of the document processing. @@ -4629,6 +5672,12 @@ xmlParseDocument(xmlParserCtxtPtr ctxt) { return(0); } +/************************************************************************ + * * + * I/O front end functions to the parser * + * * + ************************************************************************/ + /** * xmlCreateDocParserCtxt : * @cur: a pointer to an array of CHAR @@ -4643,16 +5692,13 @@ xmlCreateDocParserCtxt(CHAR *cur) { xmlParserInputPtr input; xmlCharEncoding enc; - ctxt = (xmlParserCtxtPtr) malloc(sizeof(xmlParserCtxt)); + ctxt = xmlNewParserCtxt(); if (ctxt == NULL) { - perror("malloc"); return(NULL); } - xmlInitParserCtxt(ctxt); - input = (xmlParserInputPtr) malloc(sizeof(xmlParserInput)); + input = xmlNewInputStream(ctxt); if (input == NULL) { - perror("malloc"); - free(ctxt); + xmlFreeParserCtxt(ctxt); return(NULL); } @@ -4662,14 +5708,8 @@ xmlCreateDocParserCtxt(CHAR *cur) { enc = xmlDetectCharEncoding(cur); xmlSwitchEncoding(ctxt, enc); - input->filename = NULL; - input->line = 1; - input->col = 1; input->base = cur; input->cur = cur; - input->buf = NULL; - input->free = NULL; - input->consumed = 0; inputPush(ctxt, input); return(ctxt); @@ -4753,12 +5793,10 @@ xmlSAXParseDTD(xmlSAXHandlerPtr sax, const CHAR *ExternalID, if ((ExternalID == NULL) && (SystemID == NULL)) return(NULL); - ctxt = (xmlParserCtxtPtr) malloc(sizeof(xmlParserCtxt)); + ctxt = xmlNewParserCtxt(); if (ctxt == NULL) { - perror("malloc"); return(NULL); } - xmlInitParserCtxt(ctxt); /* * Set-up the SAX context @@ -4790,7 +5828,8 @@ xmlSAXParseDTD(xmlSAXHandlerPtr sax, const CHAR *ExternalID, enc = xmlDetectCharEncoding(ctxt->input->cur); xmlSwitchEncoding(ctxt, enc); - input->filename = xmlStrdup(SystemID); + if (input->filename == NULL) + input->filename = xmlStrdup(SystemID); input->line = 1; input->col = 1; input->base = ctxt->input->cur; @@ -4864,34 +5903,33 @@ xmlCreateFileParserCtxt(const char *filename) xmlParserCtxtPtr ctxt; xmlParserInputPtr inputStream; xmlParserInputBufferPtr buf; + char *directory = NULL; buf = xmlParserInputBufferCreateFilename(filename, XML_CHAR_ENCODING_NONE); if (buf == NULL) return(NULL); - ctxt = (xmlParserCtxtPtr) malloc(sizeof(xmlParserCtxt)); + ctxt = xmlNewParserCtxt(); if (ctxt == NULL) { - perror("malloc"); return(NULL); } - xmlInitParserCtxt(ctxt); - inputStream = (xmlParserInputPtr) malloc(sizeof(xmlParserInput)); + + inputStream = xmlNewInputStream(ctxt); if (inputStream == NULL) { - perror("malloc"); - free(ctxt); + xmlFreeParserCtxt(ctxt); return(NULL); } inputStream->filename = strdup(filename); - inputStream->line = 1; - inputStream->col = 1; inputStream->buf = buf; - inputStream->consumed = 0; - inputStream->base = inputStream->buf->buffer->content; inputStream->cur = inputStream->buf->buffer->content; - inputStream->free = NULL; inputPush(ctxt, inputStream); + if ((ctxt->directory == NULL) && (directory == NULL)) + directory = xmlParserGetDirectory(filename); + if ((ctxt->directory == NULL) && (directory != NULL)) + ctxt->directory = directory; + return(ctxt); } @@ -4915,6 +5953,7 @@ xmlSAXParseFile(xmlSAXHandlerPtr sax, const char *filename, int recovery) { xmlDocPtr ret; xmlParserCtxtPtr ctxt; + char *directory = NULL; ctxt = xmlCreateFileParserCtxt(filename); if (ctxt == NULL) return(NULL); @@ -4925,6 +5964,11 @@ xmlSAXParseFile(xmlSAXHandlerPtr sax, const char *filename, ctxt->userData = NULL; } + if ((ctxt->directory == NULL) && (directory == NULL)) + directory = xmlParserGetDirectory(filename); + if ((ctxt->directory == NULL) && (directory != NULL)) + ctxt->directory = xmlStrdup(directory); + xmlParseDocument(ctxt); if ((ctxt->wellFormed) || recovery) ret = ctxt->myDoc; @@ -4971,28 +6015,6 @@ xmlRecoverFile(const char *filename) { return(xmlSAXParseFile(NULL, filename, 1)); } -/** - * xmlSubstituteEntitiesDefault : - * @val: int 0 or 1 - * - * Set and return the previous value for default entity support. - * Initially the parser always keep entity references instead of substituting - * entity values in the output. This function has to be used to change the - * default parser behaviour - * SAX::subtituteEntities() has to be used for changing that on a file by - * file basis. - * - * Returns the last value for 0 for no substitution, 1 for substitution. - */ - -int -xmlSubstituteEntitiesDefault(int val) { - int old = xmlSubstituteEntitiesDefaultValue; - - xmlSubstituteEntitiesDefaultValue = val; - return(old); -} - /** * xmlCreateMemoryParserCtxt : * @buffer: an pointer to a char array @@ -5010,24 +6032,21 @@ xmlCreateMemoryParserCtxt(char *buffer, int size) { buffer[size - 1] = '\0'; - ctxt = (xmlParserCtxtPtr) malloc(sizeof(xmlParserCtxt)); + ctxt = xmlNewParserCtxt(); if (ctxt == NULL) { - perror("malloc"); return(NULL); } - xmlInitParserCtxt(ctxt); - input = (xmlParserInputPtr) malloc(sizeof(xmlParserInput)); + + input = xmlNewInputStream(ctxt); if (input == NULL) { - perror("malloc"); - free(ctxt->nodeTab); - free(ctxt->inputTab); - free(ctxt); + xmlFreeParserCtxt(ctxt); return(NULL); } input->filename = NULL; input->line = 1; input->col = 1; + input->buf = NULL; input->consumed = 0; /* @@ -5114,92 +6133,6 @@ xmlDocPtr xmlRecoverMemory(char *buffer, int size) { return(xmlSAXParseMemory(NULL, buffer, size, 1)); } -/** - * xmlInitParserCtxt: - * @ctxt: an XML parser context - * - * Initialize a parser context - */ - -void -xmlInitParserCtxt(xmlParserCtxtPtr ctxt) -{ - xmlSAXHandler *sax; - - sax = (xmlSAXHandler *) malloc(sizeof(xmlSAXHandler)); - if (sax == NULL) { - fprintf(stderr, "xmlInitParserCtxt: out of memory\n"); - } - - /* Allocate the Input stack */ - ctxt->inputTab = (xmlParserInputPtr *) malloc(5 * sizeof(xmlParserInputPtr)); - ctxt->inputNr = 0; - ctxt->inputMax = 5; - ctxt->input = NULL; - ctxt->version = NULL; - ctxt->encoding = NULL; - ctxt->standalone = -1; - - /* Allocate the Node stack */ - ctxt->nodeTab = (xmlNodePtr *) malloc(10 * sizeof(xmlNodePtr)); - ctxt->nodeNr = 0; - ctxt->nodeMax = 10; - ctxt->node = NULL; - - if (sax == NULL) ctxt->sax = &xmlDefaultSAXHandler; - else { - ctxt->sax = sax; - memcpy(sax, &xmlDefaultSAXHandler, sizeof(xmlSAXHandler)); - } - ctxt->userData = ctxt; - ctxt->myDoc = NULL; - ctxt->wellFormed = 1; - ctxt->replaceEntities = xmlSubstituteEntitiesDefaultValue; - ctxt->record_info = 0; - xmlInitNodeInfoSeq(&ctxt->node_seq); -} - -/** - * xmlFreeParserCtxt: - * @ctxt: an XML parser context - * - * Free all the memory used by a parser context. However the parsed - * document in ctxt->myDoc is not freed. - */ - -void -xmlFreeParserCtxt(xmlParserCtxtPtr ctxt) -{ - xmlParserInputPtr input; - - if (ctxt == NULL) return; - - while ((input = inputPop(ctxt)) != NULL) { - xmlFreeInputStream(input); - } - - if (ctxt->nodeTab != NULL) free(ctxt->nodeTab); - if (ctxt->inputTab != NULL) free(ctxt->inputTab); - if (ctxt->version != NULL) free((char *) ctxt->version); - if ((ctxt->sax != NULL) && (ctxt->sax != &xmlDefaultSAXHandler)) - free(ctxt->sax); - free(ctxt); -} - -/** - * xmlClearParserCtxt: - * @ctxt: an XML parser context - * - * Clear (release owned resources) and reinitialize a parser context - */ - -void -xmlClearParserCtxt(xmlParserCtxtPtr ctxt) -{ - xmlClearNodeInfoSeq(&ctxt->node_seq); - xmlInitParserCtxt(ctxt); -} - /** * xmlSetupParserForBuffer: @@ -5215,29 +6148,31 @@ void xmlSetupParserForBuffer(xmlParserCtxtPtr ctxt, const CHAR* buffer, const char* filename) { - xmlParserInputPtr input; + xmlParserInputPtr input; - input = (xmlParserInputPtr) malloc(sizeof(xmlParserInput)); - if (input == NULL) { - perror("malloc"); - free(ctxt); - exit(1); - } - - xmlClearParserCtxt(ctxt); - if (input->filename != NULL) - input->filename = strdup(filename); - else - input->filename = NULL; - input->line = 1; - input->col = 1; - input->base = buffer; - input->cur = buffer; - - inputPush(ctxt, input); + input = xmlNewInputStream(ctxt); + if (input == NULL) { + perror("malloc"); + free(ctxt); + exit(1); + } + + xmlClearParserCtxt(ctxt); + if (filename != NULL) + input->filename = strdup(filename); + input->base = buffer; + input->cur = buffer; + inputPush(ctxt, input); } +/************************************************************************ + * * + * Miscelaneous * + * * + ************************************************************************/ + + /** * xmlParserFindNodeInfo: * @ctxt: an XML parser context @@ -5388,3 +6323,25 @@ xmlParserAddNodeInfo(xmlParserCtxtPtr ctxt, } +/** + * xmlSubstituteEntitiesDefault : + * @val: int 0 or 1 + * + * Set and return the previous value for default entity support. + * Initially the parser always keep entity references instead of substituting + * entity values in the output. This function has to be used to change the + * default parser behaviour + * SAX::subtituteEntities() has to be used for changing that on a file by + * file basis. + * + * Returns the last value for 0 for no substitution, 1 for substitution. + */ + +int +xmlSubstituteEntitiesDefault(int val) { + int old = xmlSubstituteEntitiesDefaultValue; + + xmlSubstituteEntitiesDefaultValue = val; + return(old); +} + diff --git a/parser.h b/parser.h index 43d183e0..6659cdf7 100644 --- a/parser.h +++ b/parser.h @@ -1,5 +1,5 @@ /* - * parser.h : constants and stuff related to the XML parser. + * parser.h : Interfaces, constants and types related to the XML parser. * * See Copyright for the status of this software. * @@ -10,6 +10,7 @@ #define __XML_PARSER_H__ #include "tree.h" +#include "valid.h" #include "xmlIO.h" #ifdef __cplusplus @@ -21,12 +22,22 @@ extern "C" { */ #define XML_DEFAULT_VERSION "1.0" +/** + * an xmlParserInput is an input flow for the XML processor. + * Each entity parsed is associated an xmlParserInput (except the + * few predefined ones). This is the case both for internal entities + * - in which case the flow is already completely in memory - or + * external entities - in which case we use the buf structure for + * progressive reading and I18N conversions to the internal UTF-8 format. + */ + typedef void (* xmlParserInputDeallocate)(CHAR *); typedef struct xmlParserInput { /* Input buffer */ xmlParserInputBufferPtr buf; /* UTF-8 encoded buffer */ const char *filename; /* The file analyzed, if any */ + const char *directory; /* the directory/base of teh file */ const CHAR *base; /* Base of the array to parse */ const CHAR *cur; /* Current char being parsed */ int line; /* Current line */ @@ -36,6 +47,11 @@ typedef struct xmlParserInput { } xmlParserInput; typedef xmlParserInput *xmlParserInputPtr; +/** + * the parser can be asked to collect Node informations, i.e. at what + * place in the file they were detected. + * NOTE: This is off by default and not very well tested. + */ typedef struct _xmlParserNodeInfo { const struct xmlNode* node; /* Position & line # that text that created the node begins & ends on */ @@ -54,24 +70,63 @@ typedef struct xmlParserNodeInfoSeq { typedef _xmlParserNodeInfoSeq xmlParserNodeInfoSeq; typedef xmlParserNodeInfoSeq *xmlParserNodeInfoSeqPtr; +/** + * The parser is not a state based parser, but we need to maintain + * minimum state informations, especially for entities processing. + */ +typedef enum xmlParserInputState { + XML_PARSER_EOF = 0, + XML_PARSER_PROLOG, + XML_PARSER_CONTENT, + XML_PARSER_ENTITY_DECL, + XML_PARSER_ENTITY_VALUE, + XML_PARSER_ATTRIBUTE_VALUE, + XML_PARSER_DTD, + XML_PARSER_EPILOG, + XML_PARSER_COMMENT, + XML_PARSER_CDATA_SECTION, +} xmlParserInputState; + +/** + * The parser context. + * NOTE This doesn't completely defines the parser state, the (current ?) + * design of the parser uses recursive function calls since this allow + * and easy mapping from the production rules of the specification + * to the actual code. The drawback is that the actual function call + * also reflect the parser state. However most of the parsing routines + * takes as the only argument the parser context pointer, so migrating + * to a state based parser for progressive parsing shouldn't be too hard. + */ typedef struct _xmlParserCtxt { struct xmlSAXHandler *sax; /* The SAX handler */ void *userData; /* the document being built */ xmlDocPtr myDoc; /* the document being built */ - int wellFormed; /* is the document well formed */ int replaceEntities; /* shall we replace entities ? */ - const CHAR *version; /* the XML version string */ - const CHAR *encoding; /* encoding, if any */ - int standalone; /* standalone document */ - int html; /* are we parsing an HTML document */ + const CHAR *version; /* the XML version string */ + const CHAR *encoding; /* encoding, if any */ + int standalone; /* standalone document */ + int hasExternalSubset; /* reference and external subset */ + int hasPErefs; /* the internal subset has PE refs */ + int html; /* are we parsing an HTML document */ + int external; /* are we parsing an external entity */ + int wellFormed; /* is the document well formed */ + int valid; /* is the document valid */ + int validate; /* shall we try to validate ? */ + xmlValidCtxt vctxt; /* The validity context */ + + xmlParserInputState instate; /* current type of input */ + int token; /* next char look-ahead */ + + char *directory; /* the data directory */ + /* Input stream stack */ xmlParserInputPtr input; /* Current input stream */ int inputNr; /* Number of current input streams */ int inputMax; /* Max number of input streams */ xmlParserInputPtr *inputTab; /* stack of inputs */ - /* Node analysis stack */ + /* Node analysis stack only used for DOM building */ xmlNodePtr node; /* Current parsed Node */ int nodeNr; /* Depth of the parsing stack */ int nodeMax; /* Max depth of the parsing stack */ @@ -83,10 +138,9 @@ typedef struct _xmlParserCtxt { typedef _xmlParserCtxt xmlParserCtxt; typedef xmlParserCtxt *xmlParserCtxtPtr; -/* +/** * a SAX Locator. */ - typedef struct xmlSAXLocator { const CHAR *(*getPublicId)(void *ctx); const CHAR *(*getSystemId)(void *ctx); @@ -96,8 +150,9 @@ typedef struct xmlSAXLocator { typedef _xmlSAXLocator xmlSAXLocator; typedef xmlSAXLocator *xmlSAXLocatorPtr; -/* - * a SAX Exception. +/** + * a SAX handler is bunch of callbacks called by the parser when processing + * of the input generate data or structure informations. */ #include "entities.h" @@ -108,6 +163,8 @@ typedef void (*internalSubsetSAXFunc) (void *ctx, const CHAR *name, const CHAR *ExternalID, const CHAR *SystemID); typedef xmlEntityPtr (*getEntitySAXFunc) (void *ctx, const CHAR *name); +typedef xmlEntityPtr (*getParameterEntitySAXFunc) (void *ctx, + const CHAR *name); typedef void (*entityDeclSAXFunc) (void *ctx, const CHAR *name, int type, const CHAR *publicId, const CHAR *systemId, CHAR *content); @@ -138,6 +195,7 @@ typedef void (*ignorableWhitespaceSAXFunc) (void *ctx, typedef void (*processingInstructionSAXFunc) (void *ctx, const CHAR *target, const CHAR *data); typedef void (*commentSAXFunc) (void *ctx, const CHAR *value); +typedef void (*cdataBlockSAXFunc) (void *ctx, const CHAR *value, int len); typedef void (*warningSAXFunc) (void *ctx, const char *msg, ...); typedef void (*errorSAXFunc) (void *ctx, const char *msg, ...); typedef void (*fatalErrorSAXFunc) (void *ctx, const char *msg, ...); @@ -170,12 +228,13 @@ typedef struct xmlSAXHandler { warningSAXFunc warning; errorSAXFunc error; fatalErrorSAXFunc fatalError; + getParameterEntitySAXFunc getParameterEntity; + cdataBlockSAXFunc cdataBlock; } xmlSAXHandler; typedef xmlSAXHandler *xmlSAXHandlerPtr; -/* - * Global variables: just the SAX interface tables we are looking for full - * reentrancy of the code and version infos. +/** + * Global variables: just the default SAX interface tables and XML version infos. */ extern const char *xmlParserVersion; @@ -186,14 +245,14 @@ extern xmlSAXHandler htmlDefaultSAXHandler; #include "entities.h" #include "xml-error.h" -/* +/** * Input functions */ int xmlParserInputRead(xmlParserInputPtr in, int len); int xmlParserInputGrow(xmlParserInputPtr in, int len); -/* +/** * CHAR handling */ CHAR *xmlStrdup(const CHAR *cur); @@ -207,23 +266,23 @@ int xmlStrlen(const CHAR *str); CHAR *xmlStrcat(CHAR *cur, const CHAR *add); CHAR *xmlStrncat(CHAR *cur, const CHAR *add, int len); -/* - * Interfaces +/** + * Basic parsing Interfaces */ xmlDocPtr xmlParseDoc(CHAR *cur); xmlDocPtr xmlParseMemory(char *buffer, int size); xmlDocPtr xmlParseFile(const char *filename); int xmlSubstituteEntitiesDefault(int val); -/* +/** * Recovery mode */ xmlDocPtr xmlRecoverDoc(CHAR *cur); xmlDocPtr xmlRecoverMemory(char *buffer, int size); xmlDocPtr xmlRecoverFile(const char *filename); -/* - * Internal routines +/** + * Less common routines and SAX interfaces */ int xmlParseDocument(xmlParserCtxtPtr ctxt); xmlDocPtr xmlSAXParseDoc(xmlSAXHandlerPtr sax, CHAR *cur, int recovery); diff --git a/parserInternals.h b/parserInternals.h index b1077188..ae8e2cc2 100644 --- a/parserInternals.h +++ b/parserInternals.h @@ -18,6 +18,26 @@ extern "C" { /** * A few macros needed to help building the parser. */ +/* #define UNICODE */ + +#ifdef UNICODE +typedef unsigned long CHARVAL; + +#define NEXTCHARVAL(p) (unsigned long) \ + ((*(p) == 0) ? (unsigned long) 0 : \ + ((*(p) < 0x80) ? (unsigned long) (*(p)++) : \ + (*(p) < 0xC0) ? (unsigned long) 0 : \ + (*(p) < 0xE0) ? ((((unsigned long) *(p)++) << 6) + (*(p)++ & 0x3F)) : \ + (*(p) < 0xF0) ? (((((unsigned long) *(p)++) << 6) + (*(p)++ & 0x3F)) << 6 + \ + (*(p)++ & 0x3F)) : \ + (*(p) < 0xF8) ? ((((((unsigned long) *(p)++) << 6) + (*(p)++ & 0x3F)) << 6 + \ + (*(p)++ & 0x3F)) << 6 + (*(p)++ & 0x3F)) : 0)) +#else +typedef unsigned char CHARVAL; + +#define NEXTCHARVAL(p) (unsigned long) *(p); +#define SKIPCHARVAL(p) (p)++; +#endif #ifdef UNICODE /************************************************************************ @@ -402,7 +422,6 @@ extern "C" { #define IS_LETTER(c) (IS_BASECHAR(c) || IS_IDEOGRAPHIC(c)) #else -#ifndef USE_UTF_8 /************************************************************************ * * * 8bits / ISO-Latin version of the macros. * @@ -453,15 +472,6 @@ extern "C" { */ #define IS_EXTENDER(c) ((c) == 0xb7) -#else /* USE_UTF_8 */ -/************************************************************************ - * * - * 8bits / UTF-8 version of the macros. * - * * - ************************************************************************/ - -TODO !!! -#endif /* USE_UTF_8 */ #endif /* !UNICODE */ /* @@ -513,6 +523,10 @@ xmlParserCtxtPtr xmlCreateMemoryParserCtxt(char *buffer, int size); void xmlFreeParserCtxt(xmlParserCtxtPtr ctxt); +xmlParserCtxtPtr +xmlNewParserCtxt(); +void +xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc); /** * Entities @@ -554,6 +568,8 @@ xmlParseNamespace(xmlParserCtxtPtr ctxt); * Generic production rules */ CHAR * +xmlScanName(xmlParserCtxtPtr ctxt); +CHAR * xmlParseName(xmlParserCtxtPtr ctxt); CHAR * xmlParseNmtoken(xmlParserCtxtPtr ctxt); @@ -638,6 +654,9 @@ void xmlParseXMLDecl(xmlParserCtxtPtr ctxt); void xmlParseMisc(xmlParserCtxtPtr ctxt); +void +xmlParseExternalSubset(xmlParserCtxtPtr ctxt, const CHAR *ExternalID, + const CHAR *SystemID); /* * Entities substitution diff --git a/result/XPath/tests/chaptersbase b/result/XPath/tests/chaptersbase index 43cc0538..c9a10f96 100644 --- a/result/XPath/tests/chaptersbase +++ b/result/XPath/tests/chaptersbase @@ -1,5 +1,22 @@ Object is a Node Set : Set contains 1 nodes: +1 ELEMENT EXAMPLE + ATTRIBUTE prop1 + TEXT + content=gnome is great + ATTRIBUTE prop2 + TEXT + content=& linux too +Object is a Node Set : +Set contains 6 nodes: +1 ELEMENT head +2 ELEMENT chapter +3 ELEMENT chapter +4 ELEMENT chapter +5 ELEMENT chapter +6 ELEMENT chapter +Object is a Node Set : +Set contains 1 nodes: 1 ELEMENT head Object is a Node Set : Set contains 6 nodes: diff --git a/result/XPath/tests/simpleabbr b/result/XPath/tests/simpleabbr index 774addb9..aeb5f54d 100644 --- a/result/XPath/tests/simpleabbr +++ b/result/XPath/tests/simpleabbr @@ -1,5 +1,17 @@ Object is a Node Set : Set contains 1 nodes: +1 ELEMENT EXAMPLE + ATTRIBUTE prop1 + TEXT + content=gnome is great + ATTRIBUTE prop2 + TEXT + content=& linux too +Object is a Node Set : +Set contains 1 nodes: +1 ELEMENT chapter +Object is a Node Set : +Set contains 1 nodes: 1 ELEMENT chapter Object is a Node Set : Set contains 2 nodes: diff --git a/result/XPath/tests/simplebase b/result/XPath/tests/simplebase index 32a84bbb..3dcdcd46 100644 --- a/result/XPath/tests/simplebase +++ b/result/XPath/tests/simplebase @@ -1,5 +1,17 @@ Object is a Node Set : Set contains 1 nodes: +1 ELEMENT EXAMPLE + ATTRIBUTE prop1 + TEXT + content=gnome is great + ATTRIBUTE prop2 + TEXT + content=& linux too +Object is a Node Set : +Set contains 1 nodes: +1 ELEMENT chapter +Object is a Node Set : +Set contains 1 nodes: 1 ELEMENT head Object is a Node Set : Set contains 2 nodes: diff --git a/test/HTML/fp40.htm b/test/HTML/fp40.htm new file mode 100644 index 00000000..840b81e9 --- /dev/null +++ b/test/HTML/fp40.htm @@ -0,0 +1,166 @@ + + + + + +README - Microsoft FrontPage 2000 Server Extensions + + + + + +

Microsoft FrontPage 2000 Server Extensions, UNIX

+ +© Copyright Microsoft Corporation, 1999  + + +

The FrontPage Server Extensions are a set of programs on the Web server that support: + +

    +
  • Authoring FrontPage webs
  • +
  • Administering FrontPage webs
  • +
  • Browse-time FrontPage web functionality
  • +
+ + +

Contents 

+ +Release Notes
+Resources for More Information +

 

+
+

Release Notes

+ +

This section provides complementary or late-breaking +information to supplement the Microsoft FrontPage Server Extensions documentation.

+ +

Apache 1.3.4 Support
+Upgrading from previous version of FrontPage Server Extensions
+Uploading files into executable folders

+ + +

Top of Page

+ + +

Apache 1.3.4 Support

+ +

You need to take some special steps to run the FrontPage Server Extensions with Apache 1.3.4. +FrontPage Server Extensions expect to find all resource directives in the main server +configuration file, usually http.conf. To prevent the server extensions from using any secondary +configuration files (access.conf, srm.conf), add the following lines to http.conf:

+ + +
+
+ +ResourceConfig /dev/null 
+AccessConfig /dev/null
+
+ + + +

If you have some settings stored in secondary configuration files, move them to http.conf.

+ +

You must stop and restart the web server for your changes to http.conf to take effect.

+ + + +

Top of Section

+ + + +

Upgrading from previous version of FrontPage Server Extensions

+ +

Custom entries in frontpage.cnf are not migrated to FrontPage 2000.

+ +

When you install FrontPage 2000 Server Extensions, a new frontpage.cnf file is created in the /usr/local/frontpage/version4.0 directory. +Any custom settings stored in a previous-version frontpage.cnf are not used. However, you can copy +your custom settings from the previous-version frontpage.cnf file after you install the FrontPage 2000 Server Extensions.

+ +

Do not overwrite the FrontPage 2000 frontpage.cnf file with a frontpage.cnf file from an +earlier version of the FrontPage Server Extensions.

+ + + +

Top of Section

+ + + +

Uploading files into executable folders

+ + +

After upgrading to FrontPage 2000, FrontPage authors will not be able to upload files into +executable folders. For security reasons, the default setting on FrontPage 2000 webs does not +allow authors to upload executable files into executable folders in a FrontPage web. This +setting protects servers so that authors do not inadvertently upload a program containing a bug +or a virus.

+ +

To allow FrontPage authors to upload executables, set the NoExecutableCgiUpload configuration +variable to zero (0). For information about FrontPage Server Extension configuration variables, +see the FrontPage 2000 Server Extensions Resource Kit at http://officeupdate.microsoft.com/frontpage/wpp/serk/.

+ + + +

Top of Section

+ + + +
+ + + +

Resources for More Information

+ +

This section lists sources of more information about the +FrontPage Server Extensions.

+ +

Server Extensions Resource Kit
+Server Extensions Resource Kit Update
+Knowledge Base

+ + +

Top of Page

+ + +

Server Extensions Resource Kit

+ +

The FrontPage 2000 Server Extensions include a full set of documentation: the Server +Extensions Resource Kit. This is an HTML document installed on the server machine (by +default) in /usr/local/frontpage/version4.0/serk. To view the Server Extensions Resource +Kit, open /usr/local/frontpage/version4.0/serk/default.htm in your Web browser.

+ +

The Server Extensions Resource Kit contains detailed information about installing and +administering the FrontPage Server Extensions along with an overview of the Server +Extensions, a detailed discussion of Server Extensions security on UNIX and Windows, +troubleshooting information, and a full set of appendixes.

+ +

Top of Section

+ + +

Server Extensions Resource Kit Update

+ +

For updated information about installing, setting up, and administrating the FrontPage Server +Extensions, see the Server Extensions Resource Kit Update at: http://officeupdate.microsoft.com/frontpage/wpp/serk/.

+ + +

Top of Section

+ + +

Microsoft Knowledge Base

+ +

For further technical information on FrontPage, please consult Support Online. Use Support +Online to easily search Microsoft Product Support Services' collection of resources including +technical articles from Microsoft's extensive Knowledge Base, FAQs, & troubleshooters to find +fast, accurate answers. You can also customize the site to control your search using either +keywords or the site's natural language search engine, which uses normal everyday language for +answering inquiries, so you can write your question in your own words. To begin, go to +http://support.microsoft.com/support/.

+ +

Top of Section

+ + +

 

+ +
+ + diff --git a/test/VC/AttributeDefaultLegal b/test/VC/AttributeDefaultLegal new file mode 100644 index 00000000..471eb201 --- /dev/null +++ b/test/VC/AttributeDefaultLegal @@ -0,0 +1,12 @@ + + + + + + + + +]> + + diff --git a/test/VC/DuplicateType b/test/VC/DuplicateType new file mode 100644 index 00000000..4b288048 --- /dev/null +++ b/test/VC/DuplicateType @@ -0,0 +1,5 @@ + + +]> + violates [ VC: No Duplicate Types ] diff --git a/test/VC/ElementValid b/test/VC/ElementValid new file mode 100644 index 00000000..c297ce63 --- /dev/null +++ b/test/VC/ElementValid @@ -0,0 +1,3 @@ + + diff --git a/test/VC/ElementValid2 b/test/VC/ElementValid2 new file mode 100644 index 00000000..672a0f52 --- /dev/null +++ b/test/VC/ElementValid2 @@ -0,0 +1,4 @@ + +]> +

diff --git a/test/VC/ElementValid3 b/test/VC/ElementValid3 new file mode 100644 index 00000000..67cbab48 --- /dev/null +++ b/test/VC/ElementValid3 @@ -0,0 +1,4 @@ + +]> +Oops, this element was declared EMPTY diff --git a/test/VC/ElementValid4 b/test/VC/ElementValid4 new file mode 100644 index 00000000..56df55a2 --- /dev/null +++ b/test/VC/ElementValid4 @@ -0,0 +1,7 @@ + + + + +]> + This seems Ok but this was not declared diff --git a/test/VC/ElementValid5 b/test/VC/ElementValid5 new file mode 100644 index 00000000..2cef3c49 --- /dev/null +++ b/test/VC/ElementValid5 @@ -0,0 +1,7 @@ + + + + +]> + but thiswas not declaredseems diff --git a/test/VC/ElementValid6 b/test/VC/ElementValid6 new file mode 100644 index 00000000..fbf721dc --- /dev/null +++ b/test/VC/ElementValid6 @@ -0,0 +1,7 @@ + + + + +]> +lacks c diff --git a/test/VC/ElementValid7 b/test/VC/ElementValid7 new file mode 100644 index 00000000..a88115f3 --- /dev/null +++ b/test/VC/ElementValid7 @@ -0,0 +1,7 @@ + + + + +]> + diff --git a/test/VC/Enumeration b/test/VC/Enumeration new file mode 100644 index 00000000..6c639680 --- /dev/null +++ b/test/VC/Enumeration @@ -0,0 +1,5 @@ + + +]> + diff --git a/test/VC/OneID b/test/VC/OneID new file mode 100644 index 00000000..e9cbc0c8 --- /dev/null +++ b/test/VC/OneID @@ -0,0 +1,6 @@ + + + +]> + diff --git a/test/VC/OneID2 b/test/VC/OneID2 new file mode 100644 index 00000000..ffa9d1fa --- /dev/null +++ b/test/VC/OneID2 @@ -0,0 +1,6 @@ + + + +]> + diff --git a/test/VC/OneID3 b/test/VC/OneID3 new file mode 100644 index 00000000..96967360 --- /dev/null +++ b/test/VC/OneID3 @@ -0,0 +1,4 @@ + +]> + diff --git a/test/VC/PENesting b/test/VC/PENesting new file mode 100644 index 00000000..17332ae8 --- /dev/null +++ b/test/VC/PENesting @@ -0,0 +1,2 @@ + "> + + + diff --git a/test/VC/UniqueElementTypeDeclaration b/test/VC/UniqueElementTypeDeclaration new file mode 100644 index 00000000..2246f177 --- /dev/null +++ b/test/VC/UniqueElementTypeDeclaration @@ -0,0 +1,7 @@ + + + + +]> + violates [ VC: Unique Element Type Declaration ] diff --git a/test/VC/UniqueElementTypeDeclaration2 b/test/VC/UniqueElementTypeDeclaration2 new file mode 100644 index 00000000..0805f8dc --- /dev/null +++ b/test/VC/UniqueElementTypeDeclaration2 @@ -0,0 +1,8 @@ + + + + + +]> + violates [ VC: Unique Element Type Declaration ] diff --git a/test/VC/dtds/a.dtd b/test/VC/dtds/a.dtd new file mode 100644 index 00000000..b8571a4f --- /dev/null +++ b/test/VC/dtds/a.dtd @@ -0,0 +1,2 @@ + + diff --git a/test/VC/dtds/doc.dtd b/test/VC/dtds/doc.dtd new file mode 100644 index 00000000..71f8b412 --- /dev/null +++ b/test/VC/dtds/doc.dtd @@ -0,0 +1,2 @@ + + diff --git a/test/WFC/ElemTypeMatch b/test/WFC/ElemTypeMatch new file mode 100644 index 00000000..11a2df34 --- /dev/null +++ b/test/WFC/ElemTypeMatch @@ -0,0 +1,2 @@ + + violates [ WFC: Element Type Match ] diff --git a/test/WFC/EntityDeclared b/test/WFC/EntityDeclared new file mode 100644 index 00000000..e3427a13 --- /dev/null +++ b/test/WFC/EntityDeclared @@ -0,0 +1,2 @@ + + &unknown; violates [ WFC: Entity Declared ] diff --git a/test/WFC/EntityDeclared2 b/test/WFC/EntityDeclared2 new file mode 100644 index 00000000..e6d16dda --- /dev/null +++ b/test/WFC/EntityDeclared2 @@ -0,0 +1,5 @@ + + +]> + &unknown; violates [ WFC: Entity Declared ] diff --git a/test/WFC/EntityDeclared3 b/test/WFC/EntityDeclared3 new file mode 100644 index 00000000..16709809 --- /dev/null +++ b/test/WFC/EntityDeclared3 @@ -0,0 +1,3 @@ + + + &unknown; violates [ WFC: Entity Declared ] diff --git a/test/WFC/EntityDeclared4 b/test/WFC/EntityDeclared4 new file mode 100644 index 00000000..15354aca --- /dev/null +++ b/test/WFC/EntityDeclared4 @@ -0,0 +1,6 @@ + +"> +]> + violates [ WFC: Entity Declared ] diff --git a/test/WFC/EntityDeclared5 b/test/WFC/EntityDeclared5 new file mode 100644 index 00000000..f125373e --- /dev/null +++ b/test/WFC/EntityDeclared5 @@ -0,0 +1,6 @@ + +"> +]> + violates [ WFC: Entity Declared ] diff --git a/test/WFC/LegalCharacter b/test/WFC/LegalCharacter new file mode 100644 index 00000000..67ff388a --- /dev/null +++ b/test/WFC/LegalCharacter @@ -0,0 +1,2 @@ + +  violates [ WFC: Legal Character ] diff --git a/test/WFC/NoExternalEntityRef b/test/WFC/NoExternalEntityRef new file mode 100644 index 00000000..43cd192d --- /dev/null +++ b/test/WFC/NoExternalEntityRef @@ -0,0 +1,5 @@ + + +]> + violates [ WFC: No External Entity References ] diff --git a/test/WFC/NoLtInAttValue b/test/WFC/NoLtInAttValue new file mode 100644 index 00000000..cc459e91 --- /dev/null +++ b/test/WFC/NoLtInAttValue @@ -0,0 +1,5 @@ + + +]> + violates [ WFC: No < in Attribute Values ] diff --git a/test/WFC/NoRecursion b/test/WFC/NoRecursion new file mode 100644 index 00000000..970b8979 --- /dev/null +++ b/test/WFC/NoRecursion @@ -0,0 +1,7 @@ + + + + +]> + &a; violates [ WFC: No Recursion ] diff --git a/test/WFC/PEintsubset b/test/WFC/PEintsubset new file mode 100644 index 00000000..e1ea331f --- /dev/null +++ b/test/WFC/PEintsubset @@ -0,0 +1,6 @@ + + + +]> + violates [ WFC: PEs in Internal Subset ] diff --git a/test/WFC/UniqueAttSpec b/test/WFC/UniqueAttSpec new file mode 100644 index 00000000..5074ff23 --- /dev/null +++ b/test/WFC/UniqueAttSpec @@ -0,0 +1,2 @@ + + violates [ WFC: Unique Att Spec ] diff --git a/test/WFC/UniqueAttSpec2 b/test/WFC/UniqueAttSpec2 new file mode 100644 index 00000000..e4511f11 --- /dev/null +++ b/test/WFC/UniqueAttSpec2 @@ -0,0 +1,2 @@ + + violates [ WFC: Unique Att Spec ] diff --git a/test/XPath/tests/chaptersbase b/test/XPath/tests/chaptersbase index 997d8c86..b44b2aef 100644 --- a/test/XPath/tests/chaptersbase +++ b/test/XPath/tests/chaptersbase @@ -1,7 +1,9 @@ -/child::head -/child::* -/child::head/child::title -/child::head/child::title/child::text() -/child::head/node() +/child::EXAMPLE +/child::EXAMPLE/child::* +/child::EXAMPLE/child::head +/child::EXAMPLE/child::* +/child::EXAMPLE/child::head/child::title +/child::EXAMPLE/child::head/child::title/child::text() +/child::EXAMPLE/child::head/node() /descendant::title /descendant::p/ancestor::chapter diff --git a/test/XPath/tests/simpleabbr b/test/XPath/tests/simpleabbr index b4431229..5f885b38 100644 --- a/test/XPath/tests/simpleabbr +++ b/test/XPath/tests/simpleabbr @@ -1,4 +1,6 @@ -/chapter[1] +/EXAMPLE +/EXAMPLE/chapter +/EXAMPLE/chapter[1] //p //chapter/image //p/text() diff --git a/test/XPath/tests/simplebase b/test/XPath/tests/simplebase index 997d8c86..11f87223 100644 --- a/test/XPath/tests/simplebase +++ b/test/XPath/tests/simplebase @@ -1,7 +1,9 @@ -/child::head -/child::* -/child::head/child::title -/child::head/child::title/child::text() -/child::head/node() +/child::EXAMPLE +/child::EXAMPLE/child::chapter +/child::EXAMPLE/child::head +/child::EXAMPLE/child::* +/child::EXAMPLE/child::head/child::title +/child::EXAMPLE/child::head/child::title/child::text() +/child::EXAMPLE/child::head/node() /descendant::title /descendant::p/ancestor::chapter diff --git a/test/cdata b/test/cdata new file mode 100644 index 00000000..bd8c4747 --- /dev/null +++ b/test/cdata @@ -0,0 +1,3 @@ + +Hello, world!]]> + diff --git a/test/dtd12 b/test/dtd12 new file mode 100644 index 00000000..033fecab --- /dev/null +++ b/test/dtd12 @@ -0,0 +1,5 @@ + + +]> +&WhatHeSaid; diff --git a/test/dtds/eve.dtd b/test/dtds/eve.dtd new file mode 100644 index 00000000..b1fc883f --- /dev/null +++ b/test/dtds/eve.dtd @@ -0,0 +1,4 @@ + + + diff --git a/test/ent6 b/test/ent6 new file mode 100644 index 00000000..2c880fdc --- /dev/null +++ b/test/ent6 @@ -0,0 +1,8 @@ + + + + + +]> + diff --git a/test/ent7 b/test/ent7 new file mode 100644 index 00000000..3ef20304 --- /dev/null +++ b/test/ent7 @@ -0,0 +1,7 @@ +"> + +%sampleEnt; + +]> +'they called me &sampleEnt;' diff --git a/test/errors/dtd13 b/test/errors/dtd13 new file mode 100644 index 00000000..d7658b02 --- /dev/null +++ b/test/errors/dtd13 @@ -0,0 +1,6 @@ + +]> + + +]> + + diff --git a/test/valid/REC-xml-19980210.xml b/test/valid/REC-xml-19980210.xml new file mode 100644 index 00000000..4e93fb38 --- /dev/null +++ b/test/valid/REC-xml-19980210.xml @@ -0,0 +1,4197 @@ + + + + + + + + + + + + + + + + +"> + +'"> + + + + + + + + + +amp, +lt, +gt, +apos, +quot"> + + + + + +]> + + + + + +

+Extensible Markup Language (XML) 1.0 + +REC-xml-&iso6.doc.date; +W3C Recommendation +&draft.day;&draft.month;&draft.year; + + + +http://www.w3.org/TR/1998/REC-xml-&iso6.doc.date; + +http://www.w3.org/TR/1998/REC-xml-&iso6.doc.date;.xml + +http://www.w3.org/TR/1998/REC-xml-&iso6.doc.date;.html + +http://www.w3.org/TR/1998/REC-xml-&iso6.doc.date;.pdf + +http://www.w3.org/TR/1998/REC-xml-&iso6.doc.date;.ps + + + +http://www.w3.org/TR/REC-xml + + + +http://www.w3.org/TR/PR-xml-971208 + + + +Tim Bray +Textuality and Netscape +tbray@textuality.com +Jean Paoli +Microsoft +jeanpa@microsoft.com +C. M. Sperberg-McQueen +University of Illinois at Chicago +cmsmcq@uic.edu + + +

The Extensible Markup Language (XML) is a subset of +SGML that is completely described in this document. Its goal is to +enable generic SGML to be served, received, and processed on the Web +in the way that is now possible with HTML. XML has been designed for +ease of implementation and for interoperability with both SGML and +HTML.

+
+ +

This document has been reviewed by W3C Members and +other interested parties and has been endorsed by the +Director as a W3C Recommendation. It is a stable +document and may be used as reference material or cited +as a normative reference from another document. W3C's +role in making the Recommendation is to draw attention +to the specification and to promote its widespread +deployment. This enhances the functionality and +interoperability of the Web.

+

+This document specifies a syntax created by subsetting an existing, +widely used international text processing standard (Standard +Generalized Markup Language, ISO 8879:1986(E) as amended and +corrected) for use on the World Wide Web. It is a product of the W3C +XML Activity, details of which can be found at http://www.w3.org/XML. A list of +current W3C Recommendations and other technical documents can be found +at http://www.w3.org/TR. +

+

This specification uses the term URI, which is defined by , a work in progress expected to update and . +

+

The list of known errors in this specification is +available at +http://www.w3.org/XML/xml-19980210-errata.

+

Please report errors in this document to +xml-editor@w3.org. +

+
+ + + +

Chicago, Vancouver, Mountain View, et al.: +World-Wide Web Consortium, XML Working Group, 1996, 1997.

+
+ +

Created in electronic form.

+
+ +English +Extended Backus-Naur Form (formal grammar) + + + +1997-12-03 : CMSMcQ : yet further changes +1997-12-02 : TB : further changes (see TB to XML WG, +2 December 1997) +1997-12-02 : CMSMcQ : deal with as many corrections and +comments from the proofreaders as possible: +entify hard-coded document date in pubdate element, +change expansion of entity WebSGML, +update status description as per Dan Connolly (am not sure +about refernece to Berners-Lee et al.), +add 'The' to abstract as per WG decision, +move Relationship to Existing Standards to back matter and +combine with References, +re-order back matter so normative appendices come first, +re-tag back matter so informative appendices are tagged informdiv1, +remove XXX XXX from list of 'normative' specs in prose, +move some references from Other References to Normative References, +add RFC 1738, 1808, and 2141 to Other References (they are not +normative since we do not require the processor to enforce any +rules based on them), +add reference to 'Fielding draft' (Berners-Lee et al.), +move notation section to end of body, +drop URIchar non-terminal and use SkipLit instead, +lose stray reference to defunct nonterminal 'markupdecls', +move reference to Aho et al. into appendix (Tim's right), +add prose note saying that hash marks and fragment identifiers are +NOT part of the URI formally speaking, and are NOT legal in +system identifiers (processor 'may' signal an error). +Work through: +Tim Bray reacting to James Clark, +Tim Bray on his own, +Eve Maler, + +NOT DONE YET: +change binary / text to unparsed / parsed. +handle James's suggestion about < in attriubte values +uppercase hex characters, +namechar list, + +1997-12-01 : JB : add some column-width parameters +1997-12-01 : CMSMcQ : begin round of changes to incorporate +recent WG decisions and other corrections: +binding sources of character encoding info (27 Aug / 3 Sept), +correct wording of Faust quotation (restore dropped line), +drop SDD from EncodingDecl, +change text at version number 1.0, +drop misleading (wrong!) sentence about ignorables and extenders, +modify definition of PCData to make bar on msc grammatical, +change grammar's handling of internal subset (drop non-terminal markupdecls), +change definition of includeSect to allow conditional sections, +add integral-declaration constraint on internal subset, +drop misleading / dangerous sentence about relationship of +entities with system storage objects, +change table body tag to htbody as per EM change to DTD, +add rule about space normalization in public identifiers, +add description of how to generate our name-space rules from +Unicode character database (needs further work!). + +1997-10-08 : TB : Removed %-constructs again, new rules +for PE appearance. +1997-10-01 : TB : Case-sensitive markup; cleaned up +element-type defs, lotsa little edits for style +1997-09-25 : TB : Change to elm's new DTD, with +substantial detail cleanup as a side-effect +1997-07-24 : CMSMcQ : correct error (lost *) in definition +of ignoreSectContents (thanks to Makoto Murata) +Allow all empty elements to have end-tags, consistent with +SGML TC (as per JJC). +1997-07-23 : CMSMcQ : pre-emptive strike on pending corrections: +introduce the term 'empty-element tag', note that all empty elements +may use it, and elements declared EMPTY must use it. +Add WFC requiring encoding decl to come first in an entity. +Redefine notations to point to PIs as well as binary entities. +Change autodetection table by removing bytes 3 and 4 from +examples with Byte Order Mark. +Add content model as a term and clarify that it applies to both +mixed and element content. + +1997-06-30 : CMSMcQ : change date, some cosmetic changes, +changes to productions for choice, seq, Mixed, NotationType, +Enumeration. Follow James Clark's suggestion and prohibit +conditional sections in internal subset. TO DO: simplify +production for ignored sections as a result, since we don't +need to worry about parsers which don't expand PErefs finding +a conditional section. +1997-06-29 : TB : various edits +1997-06-29 : CMSMcQ : further changes: +Suppress old FINAL EDIT comments and some dead material. +Revise occurrences of % in grammar to exploit Henry Thompson's pun, +especially markupdecl and attdef. +Remove RMD requirement relating to element content (?). + +1997-06-28 : CMSMcQ : Various changes for 1 July draft: +Add text for draconian error handling (introduce +the term Fatal Error). +RE deleta est (changing wording from +original announcement to restrict the requirement to validating +parsers). +Tag definition of validating processor and link to it. +Add colon as name character. +Change def of %operator. +Change standard definitions of lt, gt, amp. +Strip leading zeros from #x00nn forms. +1997-04-02 : CMSMcQ : final corrections of editorial errors +found in last night's proofreading. Reverse course once more on +well-formed: Webster's Second hyphenates it, and that's enough +for me. +1997-04-01 : CMSMcQ : corrections from JJC, EM, HT, and self +1997-03-31 : Tim Bray : many changes +1997-03-29 : CMSMcQ : some Henry Thompson (on entity handling), +some Charles Goldfarb, some ERB decisions (PE handling in miscellaneous +declarations. Changed Ident element to accept def attribute. +Allow normalization of Unicode characters. move def of systemliteral +into section on literals. +1997-03-28 : CMSMcQ : make as many corrections as possible, from +Terry Allen, Norbert Mikula, James Clark, Jon Bosak, Henry Thompson, +Paul Grosso, and self. Among other things: give in on "well formed" +(Terry is right), tentatively rename QuotedCData as AttValue +and Literal as EntityValue to be more informative, since attribute +values are the only place QuotedCData was used, and +vice versa for entity text and Literal. (I'd call it Entity Text, +but 8879 uses that name for both internal and external entities.) +1997-03-26 : CMSMcQ : resynch the two forks of this draft, reapply +my changes dated 03-20 and 03-21. Normalize old 'may not' to 'must not' +except in the one case where it meant 'may or may not'. +1997-03-21 : TB : massive changes on plane flight from Chicago +to Vancouver +1997-03-21 : CMSMcQ : correct as many reported errors as possible. + +1997-03-20 : CMSMcQ : correct typos listed in CMSMcQ hand copy of spec. +1997-03-20 : CMSMcQ : cosmetic changes preparatory to revision for +WWW conference April 1997: restore some of the internal entity +references (e.g. to docdate, etc.), change character xA0 to &nbsp; +and define nbsp as &#160;, and refill a lot of paragraphs for +legibility. +1996-11-12 : CMSMcQ : revise using Tim's edits: +Add list type of NUMBERED and change most lists either to +BULLETS or to NUMBERED. +Suppress QuotedNames, Names (not used). +Correct trivial-grammar doc type decl. +Rename 'marked section' as 'CDATA section' passim. +Also edits from James Clark: +Define the set of characters from which [^abc] subtracts. +Charref should use just [0-9] not Digit. +Location info needs cleaner treatment: remove? (ERB +question). +One example of a PI has wrong pic. +Clarify discussion of encoding names. +Encoding failure should lead to unspecified results; don't +prescribe error recovery. +Don't require exposure of entity boundaries. +Ignore white space in element content. +Reserve entity names of the form u-NNNN. +Clarify relative URLs. +And some of my own: +Correct productions for content model: model cannot +consist of a name, so "elements ::= cp" is no good. + +1996-11-11 : CMSMcQ : revise for style. +Add new rhs to entity declaration, for parameter entities. +1996-11-10 : CMSMcQ : revise for style. +Fix / complete section on names, characters. +Add sections on parameter entities, conditional sections. +Still to do: Add compatibility note on deterministic content models. +Finish stylistic revision. +1996-10-31 : TB : Add Entity Handling section +1996-10-30 : TB : Clean up term & termdef. Slip in +ERB decision re EMPTY. +1996-10-28 : TB : Change DTD. Implement some of Michael's +suggestions. Change comments back to //. Introduce language for +XML namespace reservation. Add section on white-space handling. +Lots more cleanup. +1996-10-24 : CMSMcQ : quick tweaks, implement some ERB +decisions. Characters are not integers. Comments are /* */ not //. +Add bibliographic refs to 10646, HyTime, Unicode. +Rename old Cdata as MsData since it's only seen +in marked sections. Call them attribute-value pairs not +name-value pairs, except once. Internal subset is optional, needs +'?'. Implied attributes should be signaled to the app, not +have values supplied by processor. +1996-10-16 : TB : track down & excise all DSD references; +introduce some EBNF for entity declarations. +1996-10-?? : TB : consistency check, fix up scraps so +they all parse, get formatter working, correct a few productions. +1996-10-10/11 : CMSMcQ : various maintenance, stylistic, and +organizational changes: +Replace a few literals with xmlpio and +pic entities, to make them consistent and ensure we can change pic +reliably when the ERB votes. +Drop paragraph on recognizers from notation section. +Add match, exact match to terminology. +Move old 2.2 XML Processors and Apps into intro. +Mention comments, PIs, and marked sections in discussion of +delimiter escaping. +Streamline discussion of doctype decl syntax. +Drop old section of 'PI syntax' for doctype decl, and add +section on partial-DTD summary PIs to end of Logical Structures +section. +Revise DSD syntax section to use Tim's subset-in-a-PI +mechanism. +1996-10-10 : TB : eliminate name recognizers (and more?) +1996-10-09 : CMSMcQ : revise for style, consistency through 2.3 +(Characters) +1996-10-09 : CMSMcQ : re-unite everything for convenience, +at least temporarily, and revise quickly +1996-10-08 : TB : first major homogenization pass +1996-10-08 : TB : turn "current" attribute on div type into +CDATA +1996-10-02 : TB : remould into skeleton + entities +1996-09-30 : CMSMcQ : add a few more sections prior to exchange + with Tim. +1996-09-20 : CMSMcQ : finish transcribing notes. +1996-09-19 : CMSMcQ : begin transcribing notes for draft. +1996-09-13 : CMSMcQ : made outline from notes of 09-06, +do some housekeeping + + +
+ + +Introduction +

Extensible Markup Language, abbreviated XML, describes a class of +data objects called XML documents and +partially describes the behavior of +computer programs which process them. XML is an application profile or +restricted form of SGML, the Standard Generalized Markup +Language . +By construction, XML documents +are conforming SGML documents. +

+

XML documents are made up of storage units called entities, which contain either parsed +or unparsed data. +Parsed data is made up of characters, +some +of which form character data, +and some of which form markup. +Markup encodes a description of the document's storage layout and +logical structure. XML provides a mechanism to impose constraints on +the storage layout and logical structure.

+

A software module +called an XML processor is used to read XML documents +and provide access to their content and structure. It is assumed that an XML processor is +doing its work on behalf of another module, called the +application. This specification describes the +required behavior of an XML processor in terms of how it must read XML +data and the information it must provide to the application.

+ + +Origin and Goals +

XML was developed by an XML Working Group (originally known as the +SGML Editorial Review Board) formed under the auspices of the World +Wide Web Consortium (W3C) in 1996. +It was chaired by Jon Bosak of Sun +Microsystems with the active participation of an XML Special +Interest Group (previously known as the SGML Working Group) also +organized by the W3C. The membership of the XML Working Group is given +in an appendix. Dan Connolly served as the WG's contact with the W3C. +

+

The design goals for XML are: +

XML shall be straightforwardly usable over the +Internet.

+

XML shall support a wide variety of applications.

+

XML shall be compatible with SGML.

+

It shall be easy to write programs which process XML +documents.

+

The number of optional features in XML is to be kept to the +absolute minimum, ideally zero.

+

XML documents should be human-legible and reasonably +clear.

+

The XML design should be prepared quickly.

+

The design of XML shall be formal and concise.

+

XML documents shall be easy to create.

+

Terseness in XML markup is of minimal importance.

+

+

This specification, +together with associated standards +(Unicode and ISO/IEC 10646 for characters, +Internet RFC 1766 for language identification tags, +ISO 639 for language name codes, and +ISO 3166 for country name codes), +provides all the information necessary to understand +XML Version &XML.version; +and construct computer programs to process it.

+

This version of the XML specification + +&doc.distribution;.

+ +
+ + + + + +Terminology + +

The terminology used to describe XML documents is defined in the body of +this specification. +The terms defined in the following list are used in building those +definitions and in describing the actions of an XML processor: + + + +

Conforming documents and XML +processors are permitted to but need not behave as +described.

+ + + +

Conforming documents and XML processors +are required to behave as described; otherwise they are in error. + +

+
+ + +

A violation of the rules of this +specification; results are +undefined. Conforming software may detect and report an error and may +recover from it.

+
+ + +

An error +which a conforming XML processor +must detect and report to the application. +After encountering a fatal error, the +processor may continue +processing the data to search for further errors and may report such +errors to the application. In order to support correction of errors, +the processor may make unprocessed data from the document (with +intermingled character data and markup) available to the application. +Once a fatal error is detected, however, the processor must not +continue normal processing (i.e., it must not +continue to pass character data and information about the document's +logical structure to the application in the normal way). +

+
+ + +

Conforming software may or must (depending on the modal verb in the +sentence) behave as described; if it does, it must +provide users a means to enable or disable the behavior +described.

+
+ + +

A rule which applies to all +valid XML documents. +Violations of validity constraints are errors; they must, at user option, +be reported by +validating XML processors.

+
+ + +

A rule which applies to all well-formed XML documents. +Violations of well-formedness constraints are +fatal errors.

+
+ + + +

(Of strings or names:) +Two strings or names being compared must be identical. +Characters with multiple possible representations in ISO/IEC 10646 (e.g. +characters with +both precomposed and base+diacritic forms) match only if they have the +same representation in both strings. +At user option, processors may normalize such characters to +some canonical form. +No case folding is performed. +(Of strings and rules in the grammar:) +A string matches a grammatical production if it belongs to the +language generated by that production. +(Of content and content models:) +An element matches its declaration when it conforms +in the fashion described in the constraint +. + +

+
+ + +

A feature of +XML included solely to ensure that XML remains compatible with SGML. +

+
+ + +

A +non-binding recommendation included to increase the chances that XML +documents can be processed by the existing installed base of SGML +processors which predate the +&WebSGML;.

+
+ +

+
+ + +
+ + + +Documents + +

+A data object is an +XML document if it is +well-formed, as +defined in this specification. +A well-formed XML document may in addition be +valid if it meets certain further +constraints.

+ +

Each XML document has both a logical and a physical structure. +Physically, the document is composed of units called entities. An entity may refer to other entities to cause their +inclusion in the document. A document begins in a "root" or document entity. +Logically, the document is composed of declarations, elements, +comments, +character references, and +processing +instructions, all of which are indicated in the document by explicit +markup. +The logical and physical structures must nest properly, as described +in . +

+ + +Well-Formed XML Documents + +

+A textual object is +a well-formed XML document if: + +

Taken as a whole, it +matches the production labeled document.

+

It +meets all the well-formedness constraints given in this specification.

+
+

Each of the parsed entities +which is referenced directly or indirectly within the document is +well-formed.

+

+

+ +Document +document +prolog +element +Misc* + +

+

Matching the document production +implies that: + +

It contains one or more +elements.

+ + +

There is exactly +one element, called the root, or document element, no +part of which appears in the content of any other element. +For all other elements, if the start-tag is in the content of another +element, the end-tag is in the content of the same element. More +simply stated, the elements, delimited by start- and end-tags, nest +properly within each other. +

+ +

+

As a consequence +of this, +for each non-root element +C in the document, there is one other element P +in the document such that +C is in the content of P, but is not in +the content of any other element that is in the content of +P. +P is referred to as the +parent of C, and C as a +child of P.

+ + +Characters + +

A parsed entity contains +text, a sequence of +characters, +which may represent markup or character data. +A character +is an atomic unit of text as specified by +ISO/IEC 10646 . +Legal characters are tab, carriage return, line feed, and the legal +graphic characters of Unicode and ISO/IEC 10646. +The use of "compatibility characters", as defined in section 6.8 +of , is discouraged. + + +Character Range + +Char +#x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] +| [#x10000-#x10FFFF] +any Unicode character, excluding the +surrogate blocks, FFFE, and FFFF. + + +

+ +

The mechanism for encoding character code points into bit patterns may +vary from entity to entity. All XML processors must accept the UTF-8 +and UTF-16 encodings of 10646; the mechanisms for signaling which of +the two is in use, or for bringing other encodings into play, are +discussed later, in . +

+ +
+ + +Common Syntactic Constructs + +

This section defines some symbols used widely in the grammar.

+

S (white space) consists of one or more space (#x20) +characters, carriage returns, line feeds, or tabs. + + +White Space + +S +(#x20 | #x9 | #xD | #xA)+ + + +

+

Characters are classified for convenience as letters, digits, or other +characters. Letters consist of an alphabetic or syllabic +base character possibly +followed by one or more combining characters, or of an ideographic +character. +Full definitions of the specific characters in each class +are given in .

+

A Name is a token +beginning with a letter or one of a few punctuation characters, and continuing +with letters, digits, hyphens, underscores, colons, or full stops, together +known as name characters. +Names beginning with the string "xml", or any string +which would match (('X'|'x') ('M'|'m') ('L'|'l')), are +reserved for standardization in this or future versions of this +specification. +

+ +

The colon character within XML names is reserved for experimentation with +name spaces. +Its meaning is expected to be +standardized at some future point, at which point those documents +using the colon for experimental purposes may need to be updated. +(There is no guarantee that any name-space mechanism +adopted for XML will in fact use the colon as a name-space delimiter.) +In practice, this means that authors should not use the colon in XML +names except as part of name-space experiments, but that XML processors +should accept the colon as a name character.

+
+

An +Nmtoken (name token) is any mixture of +name characters. + +Names and Tokens +NameChar +Letter +| Digit +| '.' | '-' | '_' | ':' +| CombiningChar +| Extender + +Name +(Letter | '_' | ':') +(NameChar)* +Names +Name +(S Name)* +Nmtoken +(NameChar)+ +Nmtokens +Nmtoken (S Nmtoken)* + +

+

Literal data is any quoted string not containing +the quotation mark used as a delimiter for that string. +Literals are used +for specifying the content of internal entities +(EntityValue), +the values of attributes (AttValue), +and external identifiers +(SystemLiteral). +Note that a SystemLiteral +can be parsed without scanning for markup. + +Literals +EntityValue +'"' +([^%&"] +| PEReference +| Reference)* +'"' + +|  +"'" +([^%&'] +| PEReference +| Reference)* +"'" + +AttValue +'"' +([^<&"] +| Reference)* +'"' + +|  +"'" +([^<&'] +| Reference)* +"'" + +SystemLiteral +('"' [^"]* '"') | ("'" [^']* "'") + + +PubidLiteral +'"' PubidChar* +'"' +| "'" (PubidChar - "'")* "'" + +PubidChar +#x20 | #xD | #xA +| [a-zA-Z0-9] +| [-'()+,./:=?;!*#@$_%] + + +

+ +
+ + +Character Data and Markup + +

Text consists of intermingled +character +data and markup. +Markup takes the form of +start-tags, +end-tags, +empty-element tags, +entity references, +character references, +comments, +CDATA section delimiters, +document type declarations, and +processing instructions. + +

+

All text that is not markup +constitutes the character data of +the document.

+

The ampersand character (&) and the left angle bracket (<) +may appear in their literal form only when used as markup +delimiters, or within a comment, a +processing instruction, +or a CDATA section. + +They are also legal within the literal entity +value of an internal entity declaration; see +. + +If they are needed elsewhere, +they must be escaped +using either numeric character references +or the strings +"&amp;" and "&lt;" respectively. +The right angle +bracket (>) may be represented using the string +"&gt;", and must, for +compatibility, +be escaped using +"&gt;" or a character reference +when it appears in the string +"]]>" +in content, +when that string is not marking the end of +a CDATA section. +

+

+In the content of elements, character data +is any string of characters which does +not contain the start-delimiter of any markup. +In a CDATA section, character data +is any string of characters not including the CDATA-section-close +delimiter, "]]>".

+

+To allow attribute values to contain both single and double quotes, the +apostrophe or single-quote character (') may be represented as +"&apos;", and the double-quote character (") as +"&quot;". + +Character Data + +CharData +[^<&]* - ([^<&]* ']]>' [^<&]*) + + +

+
+ + +Comments + +

Comments may +appear anywhere in a document outside other +markup; in addition, +they may appear within the document type declaration +at places allowed by the grammar. +They are not part of the document's character +data; an XML +processor may, but need not, make it possible for an application to +retrieve the text of comments. +For compatibility, the string +"--" (double-hyphen) must not occur within +comments. + +Comments +Comment +'<!--' +((Char - '-') +| ('-' (Char - '-')))* +'-->' + + +

+

An example of a comment: +<!&como; declarations for <head> & <body> &comc;> +

+
+ + +Processing Instructions + +

Processing +instructions (PIs) allow documents to contain instructions +for applications. + + +Processing Instructions +PI +'<?' PITarget +(S +(Char* - +(Char* &pic; Char*)))? +&pic; +PITarget +Name - +(('X' | 'x') ('M' | 'm') ('L' | 'l')) + + +PIs are not part of the document's character +data, but must be passed through to the application. The +PI begins with a target (PITarget) used +to identify the application to which the instruction is directed. +The target names "XML", "xml", and so on are +reserved for standardization in this or future versions of this +specification. +The +XML Notation mechanism +may be used for +formal declaration of PI targets. +

+
+ + +CDATA Sections + +

CDATA sections +may occur +anywhere character data may occur; they are +used to escape blocks of text containing characters which would +otherwise be recognized as markup. CDATA sections begin with the +string "<![CDATA[" and end with the string +"]]>": + +CDATA Sections +CDSect +CDStart +CData +CDEnd +CDStart +'<![CDATA[' + +CData +(Char* - +(Char* ']]>' Char*)) + + +CDEnd +']]>' + + + +Within a CDATA section, only the CDEnd string is +recognized as markup, so that left angle brackets and ampersands may occur in +their literal form; they need not (and cannot) be escaped using +"&lt;" and "&amp;". CDATA sections +cannot nest. +

+ +

An example of a CDATA section, in which "<greeting>" and +"</greeting>" +are recognized as character data, not +markup: +<![CDATA[<greeting>Hello, world!</greeting>]]> +

+
+ + +Prolog and Document Type Declaration + +

XML documents +may, and should, +begin with an XML declaration which specifies +the version of +XML being used. +For example, the following is a complete XML document, well-formed but not +valid: + +Hello, world! +]]> +and so is this: +Hello, world! +]]> +

+ +

The version number "1.0" should be used to indicate +conformance to this version of this specification; it is an error +for a document to use the value "1.0" +if it does not conform to this version of this specification. +It is the intent +of the XML working group to give later versions of this specification +numbers other than "1.0", but this intent does not +indicate a +commitment to produce any future versions of XML, nor if any are produced, to +use any particular numbering scheme. +Since future versions are not ruled out, this construct is provided +as a means to allow the possibility of automatic version recognition, should +it become necessary. +Processors may signal an error if they receive documents labeled with +versions they do not support. +

+

The function of the markup in an XML document is to describe its +storage and logical structure and to associate attribute-value pairs +with its logical structures. XML provides a mechanism, the document type declaration, to define +constraints on the logical structure and to support the use of +predefined storage units. + +An XML document is +valid if it has an associated document type +declaration and if the document +complies with the constraints expressed in it.

+

The document type declaration must appear before +the first element in the document. + +Prolog + +prolog +XMLDecl? +Misc* +(doctypedecl +Misc*)? +XMLDecl +&xmlpio; +VersionInfo +EncodingDecl? +SDDecl? +S? +&pic; + +VersionInfo +S 'version' Eq +(' VersionNum ' +| " VersionNum ") + +Eq +S? '=' S? + +VersionNum +([a-zA-Z0-9_.:] | '-')+ + +Misc +Comment | PI | +S + +

+ +

The XML +document type declaration +contains or points to +markup declarations +that provide a grammar for a +class of documents. +This grammar is known as a document type definition, +or DTD. +The document type declaration can point to an external subset (a +special kind of +external entity) containing markup +declarations, or can +contain the markup declarations directly in an internal subset, or can do +both. +The DTD for a document consists of both subsets taken +together. +

+

+A markup declaration is +an element type declaration, +an attribute-list declaration, +an entity declaration, or +a notation declaration. + +These declarations may be contained in whole or in part +within parameter entities, +as described in the well-formedness and validity constraints below. +For fuller information, see +.

+ +Document Type Definition + +doctypedecl +'<!DOCTYPE' S +Name (S +ExternalID)? +S? ('[' +(markupdecl +| PEReference +| S)* +']' +S?)? '>' + + +markupdecl +elementdecl +| AttlistDecl +| EntityDecl +| NotationDecl +| PI +| Comment + + + + + + + + +

The markup declarations may be made up in whole or in part of +the replacement text of +parameter entities. +The productions later in this specification for +individual nonterminals (elementdecl, +AttlistDecl, and so on) describe +the declarations after all the parameter entities have been +included.

+ + +Root Element Type +

+The Name in the document type declaration must +match the element type of the root element. +

+
+ + +Proper Declaration/PE Nesting +

Parameter-entity +replacement text must be properly nested +with markup declarations. +That is to say, if either the first character +or the last character of a markup +declaration (markupdecl above) +is contained in the replacement text for a +parameter-entity reference, +both must be contained in the same replacement text.

+
+ +PEs in Internal Subset +

In the internal DTD subset, +parameter-entity references +can occur only where markup declarations can occur, not +within markup declarations. (This does not apply to +references that occur in +external parameter entities or to the external subset.) +

+
+

+Like the internal subset, the external subset and +any external parameter entities referred to in the DTD +must consist of a series of complete markup declarations of the types +allowed by the non-terminal symbol +markupdecl, interspersed with white space +or parameter-entity references. +However, portions of the contents +of the +external subset or of external parameter entities may conditionally be ignored +by using +the conditional section +construct; this is not allowed in the internal subset. + + +External Subset + +extSubset +TextDecl? +extSubsetDecl +extSubsetDecl +( +markupdecl +| conditionalSect +| PEReference +| S +)* + + +

+

The external subset and external parameter entities also differ +from the internal subset in that in them, +parameter-entity references +are permitted within markup declarations, +not only between markup declarations.

+

An example of an XML document with a document type declaration: + + +Hello, world! +]]> +The system identifier +"hello.dtd" gives the URI of a DTD for the document.

+

The declarations can also be given locally, as in this +example: + + +]> +Hello, world! +]]> +If both the external and internal subsets are used, the +internal subset is considered to occur before the external subset. + +This has the effect that entity and attribute-list declarations in the +internal subset take precedence over those in the external subset. +

+
+ + +Standalone Document Declaration +

Markup declarations can affect the content of the document, +as passed from an XML processor +to an application; examples are attribute defaults and entity +declarations. +The standalone document declaration, +which may appear as a component of the XML declaration, signals +whether or not there are such declarations which appear external to +the document entity. + +Standalone Document Declaration + +SDDecl + +S +'standalone' Eq +(("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no') '"')) + + + +

+

+In a standalone document declaration, the value "yes" indicates +that there +are no markup declarations external to the document +entity (either in the DTD external subset, or in an +external parameter entity referenced from the internal subset) +which affect the information passed from the XML processor to +the application. +The value "no" indicates that there are or may be such +external markup declarations. +Note that the standalone document declaration only +denotes the presence of external declarations; the presence, in a +document, of +references to external entities, when those entities are +internally declared, +does not change its standalone status.

+

If there are no external markup declarations, the standalone document +declaration has no meaning. +If there are external markup declarations but there is no standalone +document declaration, the value "no" is assumed.

+

Any XML document for which standalone="no" holds can +be converted algorithmically to a standalone document, +which may be desirable for some network delivery applications.

+ +Standalone Document Declaration +

The standalone document declaration must have +the value "no" if any external markup declarations +contain declarations of:

+

attributes with default values, if +elements to which +these attributes apply appear in the document without +specifications of values for these attributes, or

+

entities (other than &magicents;), +if references to those +entities appear in the document, or

+
+

attributes with values subject to +normalization, where the +attribute appears in the document with a value which will +change as a result of normalization, or

+
+ +

element types with element content, +if white space occurs +directly within any instance of those types. +

+
+ +
+

An example XML declaration with a standalone document declaration:<?xml version="&XML.version;" standalone='yes'?>

+
+ +White Space Handling + +

In editing XML documents, it is often convenient to use "white space" +(spaces, tabs, and blank lines, denoted by the nonterminal +S in this specification) to +set apart the markup for greater readability. Such white space is typically +not intended for inclusion in the delivered version of the document. +On the other hand, "significant" white space that should be preserved in the +delivered version is common, for example in poetry and +source code.

+

An XML processor +must always pass all characters in a document that are not +markup through to the application. A +validating XML processor must also inform the application +which of these characters constitute white space appearing +in element content. +

+

A special attribute +named xml:space may be attached to an element +to signal an intention that in that element, +white space should be preserved by applications. +In valid documents, this attribute, like any other, must be +declared if it is used. +When declared, it must be given as an +enumerated type whose only +possible values are "default" and "preserve". +For example:]]>

+

The value "default" signals that applications' +default white-space processing modes are acceptable for this element; the +value "preserve" indicates the intent that applications preserve +all the white space. +This declared intent is considered to apply to all elements within the content +of the element where it is specified, unless overriden with another instance +of the xml:space attribute. +

+

The root element of any document +is considered to have signaled no intentions as regards application space +handling, unless it provides a value for +this attribute or the attribute is declared with a default value. +

+ +
+ +End-of-Line Handling +

XML parsed entities are often stored in +computer files which, for editing convenience, are organized into lines. +These lines are typically separated by some combination of the characters +carriage-return (#xD) and line-feed (#xA).

+

To simplify the tasks of applications, +wherever an external parsed entity or the literal entity value +of an internal parsed entity contains either the literal +two-character sequence "#xD#xA" or a standalone literal +#xD, an XML processor must +pass to the application the single character #xA. +(This behavior can +conveniently be produced by normalizing all +line breaks to #xA on input, before parsing.) +

+
+ +Language Identification +

In document processing, it is often useful to +identify the natural or formal language +in which the content is +written. +A special attribute named +xml:lang may be inserted in +documents to specify the +language used in the contents and attribute values +of any element in an XML document. +In valid documents, this attribute, like any other, must be +declared if it is used. +The values of the attribute are language identifiers as defined +by , "Tags for the Identification of Languages": + +Language Identification +LanguageID +Langcode +('-' Subcode)* +Langcode +ISO639Code | +IanaCode | +UserCode + +ISO639Code +([a-z] | [A-Z]) ([a-z] | [A-Z]) +IanaCode +('i' | 'I') '-' ([a-z] | [A-Z])+ +UserCode +('x' | 'X') '-' ([a-z] | [A-Z])+ +Subcode +([a-z] | [A-Z])+ + +The Langcode may be any of the following: + +

a two-letter language code as defined by +, "Codes +for the representation of names of languages"

+

a language identifier registered with the Internet +Assigned Numbers Authority ; these begin with the +prefix "i-" (or "I-")

+

a language identifier assigned by the user, or agreed on +between parties in private use; these must begin with the +prefix "x-" or "X-" in order to ensure that they do not conflict +with names later standardized or registered with IANA

+

+

There may be any number of Subcode segments; if +the first +subcode segment exists and the Subcode consists of two +letters, then it must be a country code from +, "Codes +for the representation of names of countries." +If the first +subcode consists of more than two letters, it must be +a subcode for the language in question registered with IANA, +unless the Langcode begins with the prefix +"x-" or +"X-".

+

It is customary to give the language code in lower case, and +the country code (if any) in upper case. +Note that these values, unlike other names in XML documents, +are case insensitive.

+

For example: +The quick brown fox jumps over the lazy dog.

+

What colour is it?

+

What color is it?

+ + Habe nun, ach! Philosophie, + Juristerei, und Medizin + und leider auch Theologie + durchaus studiert mit heißem Bemüh'n. + ]]>

+ +

The intent declared with xml:lang is considered to apply to +all attributes and content of the element where it is specified, +unless overridden with an instance of xml:lang +on another element within that content.

+ +

A simple declaration for xml:lang might take +the form +xml:lang NMTOKEN #IMPLIED +but specific default values may also be given, if appropriate. In a +collection of French poems for English students, with glosses and +notes in English, the xml:lang attribute might be declared this way: + + + ]]> +

+ +
+
+ + + +Logical Structures + +

Each XML document contains one or more +elements, the boundaries of which are +either delimited by start-tags +and end-tags, or, for empty elements, by an empty-element tag. Each element has a type, +identified by name, sometimes called its "generic +identifier" (GI), and may have a set of +attribute specifications. Each attribute specification +has a name and a value. +

+Element +element +EmptyElemTag +| STag content +ETag + + + + +

This specification does not constrain the semantics, use, or (beyond +syntax) names of the element types and attributes, except that names +beginning with a match to (('X'|'x')('M'|'m')('L'|'l')) +are reserved for standardization in this or future versions of this +specification. +

+ +Element Type Match +

+The Name in an element's end-tag must match +the element type in +the start-tag. +

+
+ +Element Valid +

An element is +valid if +there is a declaration matching +elementdecl where the +Name matches the element type, and +one of the following holds:

+ +

The declaration matches EMPTY and the element has no +content.

+

The declaration matches children and +the sequence of +child elements +belongs to the language generated by the regular expression in +the content model, with optional white space (characters +matching the nonterminal S) between each pair +of child elements.

+

The declaration matches Mixed and +the content consists of character +data and child elements +whose types match names in the content model.

+

The declaration matches ANY, and the types +of any child elements have +been declared.

+
+
+ + +Start-Tags, End-Tags, and Empty-Element Tags + +

The beginning of every +non-empty XML element is marked by a start-tag. + +Start-tag + +STag +'<' Name +(S Attribute)* +S? '>' + + +Attribute +Name Eq +AttValue + + + + + +The Name in +the start- and end-tags gives the +element's type. + +The Name-AttValue pairs are +referred to as +the attribute specifications of the element, +with the +Name in each pair +referred to as the attribute name and +the content of the +AttValue (the text between the +' or " delimiters) +as the attribute value. +

+ +Unique Att Spec +

+No attribute name may appear more than once in the same start-tag +or empty-element tag. +

+
+ +Attribute Value Type +

+The attribute must have been declared; the value must be of the type +declared for it. +(For attribute types, see .) +

+
+ +No External Entity References +

+Attribute values cannot contain direct or indirect entity references +to external entities. +

+
+ +No < in Attribute Values +

The replacement text of any entity +referred to directly or indirectly in an attribute +value (other than "&lt;") must not contain +a <. +

+

An example of a start-tag: +<termdef id="dt-dog" term="dog">

+

The end of every element +that begins with a start-tag must +be marked by an end-tag +containing a name that echoes the element's type as given in the +start-tag: + +End-tag + +ETag +'</' Name +S? '>' + + +

+

An example of an end-tag:</termdef>

+

The +text between the start-tag and +end-tag is called the element's +content: + +Content of Elements + +content +(element | CharData +| Reference | CDSect +| PI | Comment)* + + + +

+

If an element is empty, +it must be represented either by a start-tag immediately followed +by an end-tag or by an empty-element tag. +An +empty-element tag takes a special form: + +Tags for Empty Elements + +EmptyElemTag +'<' Name (S +Attribute)* S? +'/>' + + + + +

+

Empty-element tags may be used for any element which has no +content, whether or not it is declared using the keyword +EMPTY. +For interoperability, the empty-element +tag must be used, and can only be used, for elements which are +declared EMPTY.

+

Examples of empty elements: +<IMG align="left" + src="http://www.w3.org/Icons/WWW/w3c_home" /> +<br></br> +<br/>

+
+ + +Element Type Declarations + +

The element structure of an +XML document may, for +validation purposes, +be constrained +using element type and attribute-list declarations. +An element type declaration constrains the element's +content. +

+ +

Element type declarations often constrain which element types can +appear as children of the element. +At user option, an XML processor may issue a warning +when a declaration mentions an element type for which no declaration +is provided, but this is not an error.

+

An element +type declaration takes the form: + +Element Type Declaration + +elementdecl +'<!ELEMENT' S +Name +S +contentspec +S? '>' + +contentspec +'EMPTY' +| 'ANY' +| Mixed +| children + + + + +where the Name gives the element type +being declared. +

+ + +Unique Element Type Declaration +

+No element type may be declared more than once. +

+
+ +

Examples of element type declarations: +<!ELEMENT br EMPTY> +<!ELEMENT p (#PCDATA|emph)* > +<!ELEMENT %name.para; %content.para; > +<!ELEMENT container ANY>

+ + +Element Content + +

An element type has +element content when elements of that +type must contain only child +elements (no character data), optionally separated by +white space (characters matching the nonterminal +S). + +In this case, the +constraint includes a content model, a simple grammar governing +the allowed types of the child +elements and the order in which they are allowed to appear. +The grammar is built on +content particles (cps), which consist of names, +choice lists of content particles, or +sequence lists of content particles: + +Element-content Models + +children +(choice +| seq) +('?' | '*' | '+')? +cp +(Name +| choice +| seq) +('?' | '*' | '+')? +choice +'(' S? cp +( S? '|' S? cp )* +S? ')' + +seq +'(' S? cp +( S? ',' S? cp )* +S? ')' + + + + +where each Name is the type of an element which may +appear as a child. +Any content +particle in a choice list may appear in the element content at the location where +the choice list appears in the grammar; +content particles occurring in a sequence list must each +appear in the element content in the +order given in the list. +The optional character following a name or list governs +whether the element or the content particles in the list may occur one +or more (+), zero or more (*), or zero or +one times (?). +The absence of such an operator means that the element or content particle +must appear exactly once. +This syntax +and meaning are identical to those used in the productions in this +specification.

+

+The content of an element matches a content model if and only if it is +possible to trace out a path through the content model, obeying the +sequence, choice, and repetition operators and matching each element in +the content against an element type in the content model. For compatibility, it is an error +if an element in the document can +match more than one occurrence of an element type in the content model. +For more information, see . + + +

+ +Proper Group/PE Nesting +

Parameter-entity +replacement text must be properly nested +with parenthetized groups. +That is to say, if either of the opening or closing parentheses +in a choice, seq, or +Mixed construct +is contained in the replacement text for a +parameter entity, +both must be contained in the same replacement text.

+

For interoperability, +if a parameter-entity reference appears in a +choice, seq, or +Mixed construct, its replacement text +should not be empty, and +neither the first nor last non-blank +character of the replacement text should be a connector +(| or ,). +

+
+

Examples of element-content models: +<!ELEMENT spec (front, body, back?)> +<!ELEMENT div1 (head, (p | list | note)*, div2*)> +<!ELEMENT dictionary-body (%div.mix; | %dict.mix;)*>

+
+ + +Mixed Content + +

An element +type has +mixed content when elements of that type may contain +character data, optionally interspersed with +child elements. +In this case, the types of the child elements +may be constrained, but not their order or their number of occurrences: + +Mixed-content Declaration + +Mixed +'(' S? +'#PCDATA' +(S? +'|' +S? +Name)* +S? +')*' +| '(' S? '#PCDATA' S? ')' + + + + + + +where the Names give the types of elements +that may appear as children. +

+ +No Duplicate Types +

The same name must not appear more than once in a single mixed-content +declaration. +

+

Examples of mixed content declarations: +<!ELEMENT p (#PCDATA|a|ul|b|i|em)*> +<!ELEMENT p (#PCDATA | %font; | %phrase; | %special; | %form;)* > +<!ELEMENT b (#PCDATA)>

+
+
+ + +Attribute-List Declarations + +

Attributes are used to associate +name-value pairs with elements. +Attribute specifications may appear only within start-tags +and empty-element tags; +thus, the productions used to +recognize them appear in . +Attribute-list +declarations may be used: + +

To define the set of attributes pertaining to a given +element type.

+

To establish type constraints for these +attributes.

+

To provide default values +for attributes.

+ +

+

+Attribute-list declarations specify the name, data type, and default +value (if any) of each attribute associated with a given element type: + +Attribute-list Declaration +AttlistDecl +'<!ATTLIST' S +Name +AttDef* +S? '>' + +AttDef +S Name +S AttType +S DefaultDecl + + +The Name in the +AttlistDecl rule is the type of an element. At +user option, an XML processor may issue a warning if attributes are +declared for an element type not itself declared, but this is not an +error. The Name in the +AttDef rule is +the name of the attribute.

+

+When more than one AttlistDecl is provided for a +given element type, the contents of all those provided are merged. When +more than one definition is provided for the same attribute of a +given element type, the first declaration is binding and later +declarations are ignored. +For interoperability, writers of DTDs +may choose to provide at most one attribute-list declaration +for a given element type, at most one attribute definition +for a given attribute name, and at least one attribute definition +in each attribute-list declaration. +For interoperability, an XML processor may at user option +issue a warning when more than one attribute-list declaration is +provided for a given element type, or more than one attribute definition +is provided +for a given attribute, but this is not an error. +

+ + +Attribute Types + +

XML attribute types are of three kinds: a string type, a +set of tokenized types, and enumerated types. The string type may take +any literal string as a value; the tokenized types have varying lexical +and semantic constraints, as noted: + +Attribute Types + +AttType +StringType +| TokenizedType +| EnumeratedType + + +StringType +'CDATA' + +TokenizedType +'ID' + + + +| 'IDREF' + +| 'IDREFS' + +| 'ENTITY' + +| 'ENTITIES' + +| 'NMTOKEN' + +| 'NMTOKENS' + + + +

+ +ID +

+Values of type ID must match the +Name production. +A name must not appear more than once in +an XML document as a value of this type; i.e., ID values must uniquely +identify the elements which bear them. +

+
+ +One ID per Element Type +

No element type may have more than one ID attribute specified.

+
+ +ID Attribute Default +

An ID attribute must have a declared default of #IMPLIED or +#REQUIRED.

+
+ +IDREF +

+Values of type IDREF must match +the Name production, and +values of type IDREFS must match +Names; +each Name must match the value of an ID attribute on +some element in the XML document; i.e. IDREF values must +match the value of some ID attribute. +

+
+ +Entity Name +

+Values of type ENTITY +must match the Name production, +values of type ENTITIES must match +Names; +each Name must +match the +name of an unparsed entity declared in the +DTD. +

+
+ +Name Token +

+Values of type NMTOKEN must match the +Nmtoken production; +values of type NMTOKENS must +match Nmtokens. +

+
+ +

Enumerated attributes can take one +of a list of values provided in the declaration. There are two +kinds of enumerated types: + +Enumerated Attribute Types +EnumeratedType +NotationType +| Enumeration + +NotationType +'NOTATION' +S +'(' +S? +Name +(S? '|' S? +Name)* +S? ')' + + +Enumeration +'(' S? +Nmtoken +(S? '|' +S? +Nmtoken)* +S? +')' + + +A NOTATION attribute identifies a +notation, declared in the +DTD with associated system and/or public identifiers, to +be used in interpreting the element to which the attribute +is attached. +

+ + +Notation Attributes +

+Values of this type must match +one of the notation names included in +the declaration; all notation names in the declaration must +be declared. +

+
+ +Enumeration +

+Values of this type +must match one of the Nmtoken tokens in the +declaration. +

+
+

For interoperability, the same +Nmtoken should not occur more than once in the +enumerated attribute types of a single element type. +

+
+ + +Attribute Defaults + +

An attribute declaration provides +information on whether +the attribute's presence is required, and if not, how an XML processor should +react if a declared attribute is absent in a document. + +Attribute Defaults + +DefaultDecl +'#REQUIRED' +| '#IMPLIED' +| (('#FIXED' S)? AttValue) + + + + + + + + +

+

In an attribute declaration, #REQUIRED means that the +attribute must always be provided, #IMPLIED that no default +value is provided. + +If the +declaration +is neither #REQUIRED nor #IMPLIED, then the +AttValue value contains the declared +default value; the #FIXED keyword states that +the attribute must always have the default value. +If a default value +is declared, when an XML processor encounters an omitted attribute, it +is to behave as though the attribute were present with +the declared default value.

+ +Required Attribute +

If the default declaration is the keyword #REQUIRED, then +the attribute must be specified for +all elements of the type in the attribute-list declaration. +

+ +Attribute Default Legal +

+The declared +default value must meet the lexical constraints of the declared attribute type. +

+
+ +Fixed Attribute Default +

If an attribute has a default value declared with the +#FIXED keyword, instances of that attribute must +match the default value. +

+ +

Examples of attribute-list declarations: +<!ATTLIST termdef + id ID #REQUIRED + name CDATA #IMPLIED> +<!ATTLIST list + type (bullets|ordered|glossary) "ordered"> +<!ATTLIST form + method CDATA #FIXED "POST">

+
+ +Attribute-Value Normalization +

Before the value of an attribute is passed to the application +or checked for validity, the +XML processor must normalize it as follows: + +

a character reference is processed by appending the referenced +character to the attribute value

+

an entity reference is processed by recursively processing the +replacement text of the entity

+

a whitespace character (#x20, #xD, #xA, #x9) is processed by +appending #x20 to the normalized value, except that only a single #x20 +is appended for a "#xD#xA" sequence that is part of an external +parsed entity or the literal entity value of an internal parsed +entity

+

other characters are processed by appending them to the normalized +value

+
+

+

If the declared value is not CDATA, then the XML processor must +further process the normalized attribute value by discarding any +leading and trailing space (#x20) characters, and by replacing +sequences of space (#x20) characters by a single space (#x20) +character.

+

+All attributes for which no declaration has been read should be treated +by a non-validating parser as if declared +CDATA. +

+
+
+ +Conditional Sections +

+Conditional sections are portions of the +document type declaration external subset +which are +included in, or excluded from, the logical structure of the DTD based on +the keyword which governs them. + +Conditional Section + +conditionalSect +includeSect +| ignoreSect + + +includeSect +'<![' S? 'INCLUDE' S? '[' + +extSubsetDecl +']]>' + + +ignoreSect +'<![' S? 'IGNORE' S? '[' +ignoreSectContents* +']]>' + + +ignoreSectContents +Ignore +('<![' ignoreSectContents ']]>' +Ignore)* +Ignore +Char* - +(Char* ('<![' | ']]>') +Char*) + + + + +

+

Like the internal and external DTD subsets, a conditional section +may contain one or more complete declarations, +comments, processing instructions, +or nested conditional sections, intermingled with white space. +

+

If the keyword of the +conditional section is INCLUDE, then the contents of the conditional +section are part of the DTD. +If the keyword of the conditional +section is IGNORE, then the contents of the conditional section are +not logically part of the DTD. +Note that for reliable parsing, the contents of even ignored +conditional sections must be read in order to +detect nested conditional sections and ensure that the end of the +outermost (ignored) conditional section is properly detected. +If a conditional section with a +keyword of INCLUDE occurs within a larger conditional +section with a keyword of IGNORE, both the outer and the +inner conditional sections are ignored.

+

If the keyword of the conditional section is a +parameter-entity reference, the parameter entity must be replaced by its +content before the processor decides whether to +include or ignore the conditional section.

+

An example: +<!ENTITY % draft 'INCLUDE' > +<!ENTITY % final 'IGNORE' > + +<![%draft;[ +<!ELEMENT book (comments*, title, body, supplements?)> +]]> +<![%final;[ +<!ELEMENT book (title, body, supplements?)> +]]> + +

+
+ + + + +
+ + + +Physical Structures + +

An XML document may consist +of one or many storage units. These are called +entities; they all have content and are all +(except for the document entity, see below, and +the external DTD subset) +identified by name. + +Each XML document has one entity +called the document entity, which serves +as the starting point for the XML +processor and may contain the whole document.

+

Entities may be either parsed or unparsed. +A parsed entity's +contents are referred to as its +replacement text; +this text is considered an +integral part of the document.

+ +

An +unparsed entity +is a resource whose contents may or may not be +text, and if text, may not be XML. +Each unparsed entity +has an associated notation, identified by name. +Beyond a requirement +that an XML processor make the identifiers for the entity and +notation available to the application, +XML places no constraints on the contents of unparsed entities. +

+

+Parsed entities are invoked by name using entity references; +unparsed entities by name, given in the value of ENTITY +or ENTITIES +attributes.

+

General entities +are entities for use within the document content. +In this specification, general entities are sometimes referred +to with the unqualified term entity when this leads +to no ambiguity. +Parameter entities +are parsed entities for use within the DTD. +These two types of entities use different forms of reference and +are recognized in different contexts. +Furthermore, they occupy different namespaces; a parameter entity and +a general entity with the same name are two distinct entities. +

+ + +Character and Entity References +

+A character reference refers to a specific character in the +ISO/IEC 10646 character set, for example one not directly accessible from +available input devices. + +Character Reference +CharRef +'&#' [0-9]+ ';' +| '&hcro;' [0-9a-fA-F]+ ';' + + + + +Legal Character +

Characters referred to using character references must +match the production for +Char.

+ +If the character reference begins with "&#x", the digits and +letters up to the terminating ; provide a hexadecimal +representation of the character's code point in ISO/IEC 10646. +If it begins just with "&#", the digits up to the terminating +; provide a decimal representation of the character's +code point. + +

+

An entity +reference refers to the content of a named entity. +References to +parsed general entities +use ampersand (&) and semicolon (;) as +delimiters. + +Parameter-entity references use percent-sign (%) and +semicolon +(;) as delimiters. +

+ +Entity Reference +Reference +EntityRef +| CharRef +EntityRef +'&' Name ';' + + + + + +PEReference +'%' Name ';' + + + + + + + +Entity Declared +

In a document without any DTD, a document with only an internal +DTD subset which contains no parameter entity references, or a document with +"standalone='yes'", +the Name given in the entity reference must +match that in an +entity declaration, except that +well-formed documents need not declare +any of the following entities: &magicents;. +The declaration of a parameter entity must precede any reference to it. +Similarly, the declaration of a general entity must precede any +reference to it which appears in a default value in an attribute-list +declaration.

+

Note that if entities are declared in the external subset or in +external parameter entities, a non-validating processor is +not obligated to read +and process their declarations; for such documents, the rule that +an entity must be declared is a well-formedness constraint only +if standalone='yes'.

+
+ +Entity Declared +

In a document with an external subset or external parameter +entities with "standalone='no'", +the Name given in the entity reference must match that in an +entity declaration. +For interoperability, valid documents should declare the entities +&magicents;, in the form +specified in . +The declaration of a parameter entity must precede any reference to it. +Similarly, the declaration of a general entity must precede any +reference to it which appears in a default value in an attribute-list +declaration.

+
+ + +Parsed Entity +

+An entity reference must not contain the name of an unparsed entity. Unparsed entities may be referred +to only in attribute values declared to +be of type ENTITY or ENTITIES. +

+
+ +No Recursion +

+A parsed entity must not contain a recursive reference to itself, +either directly or indirectly. +

+
+ +In DTD +

+Parameter-entity references may only appear in the +DTD. +

+
+

Examples of character and entity references: +Type <key>less-than</key> (&hcro;3C;) to save options. +This document was prepared on &docdate; and +is classified &security-level;.

+

Example of a parameter-entity reference: + + + +%ISOLat2;]]>

+
+ + +Entity Declarations + +

+Entities are declared thus: + +Entity Declaration + +EntityDecl +GEDecl | PEDecl + + +GEDecl +'<!ENTITY' S Name +S EntityDef +S? '>' + +PEDecl +'<!ENTITY' S '%' S +Name S +PEDef S? '>' + + +EntityDef +EntityValue +| (ExternalID +NDataDecl?) + + + +PEDef +EntityValue +| ExternalID + + +The Name identifies the entity in an +entity reference or, in the case of an +unparsed entity, in the value of an ENTITY or ENTITIES +attribute. +If the same entity is declared more than once, the first declaration +encountered is binding; at user option, an XML processor may issue a +warning if entities are declared multiple times. +

+ + +Internal Entities + +

If +the entity definition is an +EntityValue, +the defined entity is called an internal entity. +There is no separate physical +storage object, and the content of the entity is given in the +declaration. +Note that some processing of entity and character references in the +literal entity value may be required to +produce the correct replacement +text: see . +

+

An internal entity is a parsed +entity.

+

Example of an internal entity declaration: +<!ENTITY Pub-Status "This is a pre-release of the + specification.">

+
+ + +External Entities + +

If the entity is not +internal, it is an external +entity, declared as follows: + +External Entity Declaration + +ExternalID +'SYSTEM' S +SystemLiteral +| 'PUBLIC' S +PubidLiteral +S +SystemLiteral + + +NDataDecl +S 'NDATA' S +Name + + +If the NDataDecl is present, this is a +general unparsed +entity; otherwise it is a parsed entity.

+ +Notation Declared +

+The Name must match the declared name of a +notation. +

+
+

The +SystemLiteral +is called the entity's system identifier. It is a URI, +which may be used to retrieve the entity. +Note that the hash mark (#) and fragment identifier +frequently used with URIs are not, formally, part of the URI itself; +an XML processor may signal an error if a fragment identifier is +given as part of a system identifier. +Unless otherwise provided by information outside the scope of this +specification (e.g. a special XML element type defined by a particular +DTD, or a processing instruction defined by a particular application +specification), relative URIs are relative to the location of the +resource within which the entity declaration occurs. +A URI might thus be relative to the +document entity, to the entity +containing the external DTD subset, +or to some other external parameter entity. +

+

An XML processor should handle a non-ASCII character in a URI by +representing the character in UTF-8 as one or more bytes, and then +escaping these bytes with the URI escaping mechanism (i.e., by +converting each byte to %HH, where HH is the hexadecimal notation of the +byte value).

+

+In addition to a system identifier, an external identifier may +include a public identifier. +An XML processor attempting to retrieve the entity's content may use the public +identifier to try to generate an alternative URI. If the processor +is unable to do so, it must use the URI specified in the system +literal. Before a match is attempted, all strings +of white space in the public identifier must be normalized to single space characters (#x20), +and leading and trailing white space must be removed.

+

Examples of external entity declarations: +<!ENTITY open-hatch + SYSTEM "http://www.textuality.com/boilerplate/OpenHatch.xml"> +<!ENTITY open-hatch + PUBLIC "-//Textuality//TEXT Standard open-hatch boilerplate//EN" + "http://www.textuality.com/boilerplate/OpenHatch.xml"> +<!ENTITY hatch-pic + SYSTEM "../grafix/OpenHatch.gif" + NDATA gif >

+
+ +
+ + +Parsed Entities + +The Text Declaration +

External parsed entities may each begin with a text +declaration. + +Text Declaration + +TextDecl +&xmlpio; +VersionInfo? +EncodingDecl +S? &pic; + + + +

+

The text declaration must be provided literally, not +by reference to a parsed entity. +No text declaration may appear at any position other than the beginning of +an external parsed entity.

+
+ +Well-Formed Parsed Entities +

The document entity is well-formed if it matches the production labeled +document. +An external general +parsed entity is well-formed if it matches the production labeled +extParsedEnt. +An external parameter +entity is well-formed if it matches the production labeled +extPE. + +Well-Formed External Parsed Entity +extParsedEnt +TextDecl? +content + +extPE +TextDecl? +extSubsetDecl + + +An internal general parsed entity is well-formed if its replacement text +matches the production labeled +content. +All internal parameter entities are well-formed by definition. +

+

A consequence of well-formedness in entities is that the logical +and physical structures in an XML document are properly nested; no +start-tag, +end-tag, +empty-element tag, +element, +comment, +processing instruction, +character +reference, or +entity reference +can begin in one entity and end in another.

+
+ +Character Encoding in Entities + +

Each external parsed entity in an XML document may use a different +encoding for its characters. All XML processors must be able to read +entities in either UTF-8 or UTF-16. + +

+

Entities encoded in UTF-16 must +begin with the Byte Order Mark described by ISO/IEC 10646 Annex E and +Unicode Appendix B (the ZERO WIDTH NO-BREAK SPACE character, #xFEFF). +This is an encoding signature, not part of either the markup or the +character data of the XML document. +XML processors must be able to use this character to +differentiate between UTF-8 and UTF-16 encoded documents.

+

Although an XML processor is required to read only entities in +the UTF-8 and UTF-16 encodings, it is recognized that other encodings are +used around the world, and it may be desired for XML processors +to read entities that use them. +Parsed entities which are stored in an encoding other than +UTF-8 or UTF-16 must begin with a text +declaration containing an encoding declaration: + +Encoding Declaration +EncodingDecl +S +'encoding' Eq +('"' EncName '"' | +"'" EncName "'" ) + + +EncName +[A-Za-z] ([A-Za-z0-9._] | '-')* +Encoding name contains only Latin characters + + +In the document entity, the encoding +declaration is part of the XML declaration. +The EncName is the name of the encoding used. +

+ +

In an encoding declaration, the values +"UTF-8", +"UTF-16", +"ISO-10646-UCS-2", and +"ISO-10646-UCS-4" should be +used for the various encodings and transformations of Unicode / +ISO/IEC 10646, the values +"ISO-8859-1", +"ISO-8859-2", ... +"ISO-8859-9" should be used for the parts of ISO 8859, and +the values +"ISO-2022-JP", +"Shift_JIS", and +"EUC-JP" +should be used for the various encoded forms of JIS X-0208-1997. XML +processors may recognize other encodings; it is recommended that +character encodings registered (as charsets) +with the Internet Assigned Numbers +Authority , other than those just listed, should be +referred to +using their registered names. +Note that these registered names are defined to be +case-insensitive, so processors wishing to match against them +should do so in a case-insensitive +way.

+

In the absence of information provided by an external +transport protocol (e.g. HTTP or MIME), +it is an error for an entity including +an encoding declaration to be presented to the XML processor +in an encoding other than that named in the declaration, +for an encoding declaration to occur other than at the beginning +of an external entity, or for +an entity which begins with neither a Byte Order Mark nor an encoding +declaration to use an encoding other than UTF-8. +Note that since ASCII +is a subset of UTF-8, ordinary ASCII entities do not strictly need +an encoding declaration.

+ +

It is a fatal error when an XML processor +encounters an entity with an encoding that it is unable to process.

+

Examples of encoding declarations: +<?xml encoding='UTF-8'?> +<?xml encoding='EUC-JP'?>

+
+
+ +XML Processor Treatment of Entities and References +

The table below summarizes the contexts in which character references, +entity references, and invocations of unparsed entities might appear and the +required behavior of an XML processor in +each case. +The labels in the leftmost column describe the recognition context: + + +

as a reference +anywhere after the start-tag and +before the end-tag of an element; corresponds +to the nonterminal content.

+ + + +

as a reference within either the value of an attribute in a +start-tag, or a default +value in an attribute declaration; +corresponds to the nonterminal +AttValue.

+ + +

as a Name, not a reference, appearing either as +the value of an +attribute which has been declared as type ENTITY, or as one of +the space-separated tokens in the value of an attribute which has been +declared as type ENTITIES.

+
+ +

as a reference +within a parameter or internal entity's +literal entity value in +the entity's declaration; corresponds to the nonterminal +EntityValue.

+ +

as a reference within either the internal or external subsets of the +DTD, but outside +of an EntityValue or +AttValue.

+
+

+ + + +Entity Type +Character + + +Parameter +Internal +General +External Parsed +General +Unparsed + + + +Reference +in Content +Not recognized +Included +Included if validating +Forbidden +Included + + +Reference +in Attribute Value +Not recognized +Included in literal +Forbidden +Forbidden +Included + + +Occurs as +Attribute Value +Not recognized +Forbidden +Forbidden +Notify +Not recognized + + +Reference +in EntityValue +Included in literal +Bypassed +Bypassed +Forbidden +Included + + +Reference +in DTD +Included as PE +Forbidden +Forbidden +Forbidden +Forbidden + + + + +Not Recognized +

Outside the DTD, the % character has no +special significance; thus, what would be parameter entity references in the +DTD are not recognized as markup in content. +Similarly, the names of unparsed entities are not recognized except +when they appear in the value of an appropriately declared attribute. +

+
+ +Included +

An entity is +included when its +replacement text is retrieved +and processed, in place of the reference itself, +as though it were part of the document at the location the +reference was recognized. +The replacement text may contain both +character data +and (except for parameter entities) markup, +which must be recognized in +the usual way, except that the replacement text of entities used to escape +markup delimiters (the entities &magicents;) is always treated as +data. (The string "AT&amp;T;" expands to +"AT&T;" and the remaining ampersand is not recognized +as an entity-reference delimiter.) +A character reference is included when the indicated +character is processed in place of the reference itself. +

+
+ +Included If Validating +

When an XML processor recognizes a reference to a parsed entity, in order +to validate +the document, the processor must +include its +replacement text. +If the entity is external, and the processor is not +attempting to validate the XML document, the +processor may, but need not, +include the entity's replacement text. +If a non-validating parser does not include the replacement text, +it must inform the application that it recognized, but did not +read, the entity.

+

This rule is based on the recognition that the automatic inclusion +provided by the SGML and XML entity mechanism, primarily designed +to support modularity in authoring, is not necessarily +appropriate for other applications, in particular document browsing. +Browsers, for example, when encountering an external parsed entity reference, +might choose to provide a visual indication of the entity's +presence and retrieve it for display only on demand. +

+
+ +Forbidden +

The following are forbidden, and constitute +fatal errors: + +

the appearance of a reference to an +unparsed entity. +

+

the appearance of any character or general-entity reference in the +DTD except within an EntityValue or +AttValue.

+

a reference to an external entity in an attribute value.

+
+ +

+
+ +Included in Literal +

When an entity reference appears in an +attribute value, or a parameter entity reference appears in a literal entity +value, its replacement text is +processed in place of the reference itself as though it +were part of the document at the location the reference was recognized, +except that a single or double quote character in the replacement text +is always treated as a normal data character and will not terminate the +literal. +For example, this is well-formed: + +]]> +while this is not: +<!ENTITY EndAttr "27'" > +<element attribute='a-&EndAttr;> +

+ +Notify +

When the name of an unparsed +entity appears as a token in the +value of an attribute of declared type ENTITY or ENTITIES, +a validating processor must inform the +application of the system +and public (if any) +identifiers for both the entity and its associated +notation.

+
+ +Bypassed +

When a general entity reference appears in the +EntityValue in an entity declaration, +it is bypassed and left as is.

+
+ +Included as PE +

Just as with external parsed entities, parameter entities +need only be included if +validating. +When a parameter-entity reference is recognized in the DTD +and included, its +replacement +text is enlarged by the attachment of one leading and one following +space (#x20) character; the intent is to constrain the replacement +text of parameter +entities to contain an integral number of grammatical tokens in the DTD. +

+
+ +
+ +Construction of Internal Entity Replacement Text +

In discussing the treatment +of internal entities, it is +useful to distinguish two forms of the entity's value. +The literal +entity value is the quoted string actually +present in the entity declaration, corresponding to the +non-terminal EntityValue. +The replacement +text is the content of the entity, after +replacement of character references and parameter-entity +references. +

+ +

The literal entity value +as given in an internal entity declaration +(EntityValue) may contain character, +parameter-entity, and general-entity references. +Such references must be contained entirely within the +literal entity value. +The actual replacement text that is +included as described above +must contain the replacement text of any +parameter entities referred to, and must contain the character +referred to, in place of any character references in the +literal entity value; however, +general-entity references must be left as-is, unexpanded. +For example, given the following declarations: + + + +]]> +then the replacement text for the entity "book" is: +La Peste: Albert Camus, +© 1947 Éditions Gallimard. &rights; +The general-entity reference "&rights;" would be expanded +should the reference "&book;" appear in the document's +content or an attribute value.

+

These simple rules may have complex interactions; for a detailed +discussion of a difficult example, see +. +

+ +
+ +Predefined Entities +

Entity and character +references can both be used to escape the left angle bracket, +ampersand, and other delimiters. A set of general entities +(&magicents;) is specified for this purpose. +Numeric character references may also be used; they are +expanded immediately when recognized and must be treated as +character data, so the numeric character references +"&#60;" and "&#38;" may be used to +escape < and & when they occur +in character data.

+

All XML processors must recognize these entities whether they +are declared or not. +For interoperability, +valid XML documents should declare these +entities, like any others, before using them. +If the entities in question are declared, they must be declared +as internal entities whose replacement text is the single +character being escaped or a character reference to +that character, as shown below. + + + + + +]]> +Note that the < and & characters +in the declarations of "lt" and "amp" +are doubly escaped to meet the requirement that entity replacement +be well-formed. +

+
+ + +Notation Declarations + +

Notations identify by +name the format of unparsed +entities, the +format of elements which bear a notation attribute, +or the application to which +a processing instruction is +addressed.

+

+Notation declarations +provide a name for the notation, for use in +entity and attribute-list declarations and in attribute specifications, +and an external identifier for the notation which may allow an XML +processor or its client application to locate a helper application +capable of processing data in the given notation. + +Notation Declarations +NotationDecl +'<!NOTATION' S Name +S +(ExternalID | +PublicID) +S? '>' +PublicID +'PUBLIC' S +PubidLiteral + + +

+

XML processors must provide applications with the name and external +identifier(s) of any notation declared and referred to in an attribute +value, attribute definition, or entity declaration. They may +additionally resolve the external identifier into the +system identifier, +file name, or other information needed to allow the +application to call a processor for data in the notation described. (It +is not an error, however, for XML documents to declare and refer to +notations for which notation-specific applications are not available on +the system where the XML processor or application is running.)

+
+ + + +Document Entity + +

The document +entity serves as the root of the entity +tree and a starting-point for an XML +processor. +This specification does +not specify how the document entity is to be located by an XML +processor; unlike other entities, the document entity has no name and might +well appear on a processor input stream +without any identification at all.

+
+ + +
+ + + +Conformance + + +Validating and Non-Validating Processors +

Conforming XML processors fall into two +classes: validating and non-validating.

+

Validating and non-validating processors alike must report +violations of this specification's well-formedness constraints +in the content of the +document entity and any +other parsed entities that +they read.

+

+Validating processors must report +violations of the constraints expressed by the declarations in the +DTD, and +failures to fulfill the validity constraints given +in this specification. + +To accomplish this, validating XML processors must read and process the entire +DTD and all external parsed entities referenced in the document. +

+

Non-validating processors are required to check only the +document entity, including +the entire internal DTD subset, for well-formedness. + +While they are not required to check the document for validity, +they are required to +process all the declarations they read in the +internal DTD subset and in any parameter entity that they +read, up to the first reference +to a parameter entity that they do not read; that is to +say, they must +use the information in those declarations to +normalize attribute values, +include the replacement text of +internal entities, and supply +default attribute values. + +They must not process +entity declarations or +attribute-list declarations +encountered after a reference to a parameter entity that is not +read, since the entity may have contained overriding declarations. +

+
+ +Using XML Processors +

The behavior of a validating XML processor is highly predictable; it +must read every piece of a document and report all well-formedness and +validity violations. +Less is required of a non-validating processor; it need not read any +part of the document other than the document entity. +This has two effects that may be important to users of XML processors: + +

Certain well-formedness errors, specifically those that require +reading external entities, may not be detected by a non-validating processor. +Examples include the constraints entitled +Entity Declared, +Parsed Entity, and +No Recursion, as well +as some of the cases described as +forbidden in +.

+

The information passed from the processor to the application may +vary, depending on whether the processor reads +parameter and external entities. +For example, a non-validating processor may not +normalize attribute values, +include the replacement text of +internal entities, or supply +default attribute values, +where doing so depends on having read declarations in +external or parameter entities.

+ +

+

For maximum reliability in interoperating between different XML +processors, applications which use non-validating processors should not +rely on any behaviors not required of such processors. +Applications which require facilities such as the use of default +attributes or internal entities which are declared in external +entities should use validating XML processors.

+
+
+ + +Notation + +

The formal grammar of XML is given in this specification using a simple +Extended Backus-Naur Form (EBNF) notation. Each rule in the grammar defines +one symbol, in the form +symbol ::= expression

+

Symbols are written with an initial capital letter if they are +defined by a regular expression, or with an initial lower case letter +otherwise. +Literal strings are quoted. + +

+ +

Within the expression on the right-hand side of a rule, the following +expressions are used to match strings of one or more characters: + + + +

where N is a hexadecimal integer, the +expression matches the character in ISO/IEC 10646 whose canonical +(UCS-4) +code value, when interpreted as an unsigned binary number, has +the value indicated. The number of leading zeros in the +#xN form is insignificant; the number of leading +zeros in the corresponding code value +is governed by the character +encoding in use and is not significant for XML.

+ + + +

matches any character +with a value in the range(s) indicated (inclusive).

+
+ + +

matches any character +with a value outside the +range indicated.

+
+ + +

matches any character +with a value not among the characters given.

+
+ + +

matches a literal string matching +that given inside the double quotes.

+
+ + +

matches a literal string matching +that given inside the single quotes.

+
+ +These symbols may be combined to match more complex patterns as follows, +where A and B represent simple expressions: + + + +

expression is treated as a unit +and may be combined as described in this list.

+
+ + +

matches A or nothing; optional A.

+
+ + +

matches A followed by B.

+
+ + +

matches A or B but not both.

+
+ + +

matches any string that matches A but does not match +B. +

+
+ + +

matches one or more occurrences of A.

+
+ + +

matches zero or more occurrences of A.

+
+ +
+Other notations used in the productions are: + + + +

comment.

+
+ + +

well-formedness constraint; this identifies by name a +constraint on +well-formed documents +associated with a production.

+
+ + +

validity constraint; this identifies by name a constraint on +valid documents associated with +a production.

+
+
+

+ + + + + + + + + +References + +Normative References + + + +(Internet Assigned Numbers Authority) Official Names for +Character Sets, +ed. Keld Simonsen et al. +See ftp://ftp.isi.edu/in-notes/iana/assignments/character-sets. + + + +IETF (Internet Engineering Task Force). +RFC 1766: Tags for the Identification of Languages, +ed. H. Alvestrand. +1995. + + + +(International Organization for Standardization). +ISO 639:1988 (E). +Code for the representation of names of languages. +[Geneva]: International Organization for +Standardization, 1988. + + +(International Organization for Standardization). +ISO 3166-1:1997 (E). +Codes for the representation of names of countries and their subdivisions +— Part 1: Country codes +[Geneva]: International Organization for +Standardization, 1997. + +ISO +(International Organization for Standardization). +ISO/IEC 10646-1993 (E). Information technology — Universal +Multiple-Octet Coded Character Set (UCS) — Part 1: +Architecture and Basic Multilingual Plane. +[Geneva]: International Organization for +Standardization, 1993 (plus amendments AM 1 through AM 7). + + +The Unicode Consortium. +The Unicode Standard, Version 2.0. +Reading, Mass.: Addison-Wesley Developers Press, 1996. + + + + + +Other References + + + +Aho, Alfred V., +Ravi Sethi, and Jeffrey D. Ullman. +Compilers: Principles, Techniques, and Tools. +Reading: Addison-Wesley, 1986, rpt. corr. 1988. + + +Berners-Lee, T., R. Fielding, and L. Masinter. +Uniform Resource Identifiers (URI): Generic Syntax and +Semantics. +1997. +(Work in progress; see updates to RFC1738.) + +Brüggemann-Klein, Anne. +Regular Expressions into Finite Automata. +Extended abstract in I. Simon, Hrsg., LATIN 1992, +S. 97-98. Springer-Verlag, Berlin 1992. +Full Version in Theoretical Computer Science 120: 197-213, 1993. + + + +Brüggemann-Klein, Anne, +and Derick Wood. +Deterministic Regular Languages. +Universität Freiburg, Institut für Informatik, +Bericht 38, Oktober 1991. + + +James Clark. +Comparison of SGML and XML. See +http://www.w3.org/TR/NOTE-sgml-xml-971215. + + +IETF (Internet Engineering Task Force). +RFC 1738: Uniform Resource Locators (URL), +ed. T. Berners-Lee, L. Masinter, M. McCahill. +1994. + + + +IETF (Internet Engineering Task Force). +RFC 1808: Relative Uniform Resource Locators, +ed. R. Fielding. +1995. + + + +IETF (Internet Engineering Task Force). +RFC 2141: URN Syntax, +ed. R. Moats. +1997. + + +ISO +(International Organization for Standardization). +ISO 8879:1986(E). Information processing — Text and Office +Systems — Standard Generalized Markup Language (SGML). First +edition — 1986-10-15. [Geneva]: International Organization for +Standardization, 1986. + + + +ISO +(International Organization for Standardization). +ISO/IEC 10744-1992 (E). Information technology — +Hypermedia/Time-based Structuring Language (HyTime). + +[Geneva]: International Organization for +Standardization, 1992. +Extended Facilities Annexe. +[Geneva]: International Organization for +Standardization, 1996. + + + + + + + + +Character Classes +

Following the characteristics defined in the Unicode standard, +characters are classed as base characters (among others, these +contain the alphabetic characters of the Latin alphabet, without +diacritics), ideographic characters, and combining characters (among +others, this class contains most diacritics); these classes combine +to form the class of letters. Digits and extenders are +also distinguished. + +Characters + +Letter +BaseChar +| Ideographic +BaseChar +[#x0041-#x005A] +| [#x0061-#x007A] +| [#x00C0-#x00D6] +| [#x00D8-#x00F6] +| [#x00F8-#x00FF] +| [#x0100-#x0131] +| [#x0134-#x013E] +| [#x0141-#x0148] +| [#x014A-#x017E] +| [#x0180-#x01C3] +| [#x01CD-#x01F0] +| [#x01F4-#x01F5] +| [#x01FA-#x0217] +| [#x0250-#x02A8] +| [#x02BB-#x02C1] +| #x0386 +| [#x0388-#x038A] +| #x038C +| [#x038E-#x03A1] +| [#x03A3-#x03CE] +| [#x03D0-#x03D6] +| #x03DA +| #x03DC +| #x03DE +| #x03E0 +| [#x03E2-#x03F3] +| [#x0401-#x040C] +| [#x040E-#x044F] +| [#x0451-#x045C] +| [#x045E-#x0481] +| [#x0490-#x04C4] +| [#x04C7-#x04C8] +| [#x04CB-#x04CC] +| [#x04D0-#x04EB] +| [#x04EE-#x04F5] +| [#x04F8-#x04F9] +| [#x0531-#x0556] +| #x0559 +| [#x0561-#x0586] +| [#x05D0-#x05EA] +| [#x05F0-#x05F2] +| [#x0621-#x063A] +| [#x0641-#x064A] +| [#x0671-#x06B7] +| [#x06BA-#x06BE] +| [#x06C0-#x06CE] +| [#x06D0-#x06D3] +| #x06D5 +| [#x06E5-#x06E6] +| [#x0905-#x0939] +| #x093D +| [#x0958-#x0961] +| [#x0985-#x098C] +| [#x098F-#x0990] +| [#x0993-#x09A8] +| [#x09AA-#x09B0] +| #x09B2 +| [#x09B6-#x09B9] +| [#x09DC-#x09DD] +| [#x09DF-#x09E1] +| [#x09F0-#x09F1] +| [#x0A05-#x0A0A] +| [#x0A0F-#x0A10] +| [#x0A13-#x0A28] +| [#x0A2A-#x0A30] +| [#x0A32-#x0A33] +| [#x0A35-#x0A36] +| [#x0A38-#x0A39] +| [#x0A59-#x0A5C] +| #x0A5E +| [#x0A72-#x0A74] +| [#x0A85-#x0A8B] +| #x0A8D +| [#x0A8F-#x0A91] +| [#x0A93-#x0AA8] +| [#x0AAA-#x0AB0] +| [#x0AB2-#x0AB3] +| [#x0AB5-#x0AB9] +| #x0ABD +| #x0AE0 +| [#x0B05-#x0B0C] +| [#x0B0F-#x0B10] +| [#x0B13-#x0B28] +| [#x0B2A-#x0B30] +| [#x0B32-#x0B33] +| [#x0B36-#x0B39] +| #x0B3D +| [#x0B5C-#x0B5D] +| [#x0B5F-#x0B61] +| [#x0B85-#x0B8A] +| [#x0B8E-#x0B90] +| [#x0B92-#x0B95] +| [#x0B99-#x0B9A] +| #x0B9C +| [#x0B9E-#x0B9F] +| [#x0BA3-#x0BA4] +| [#x0BA8-#x0BAA] +| [#x0BAE-#x0BB5] +| [#x0BB7-#x0BB9] +| [#x0C05-#x0C0C] +| [#x0C0E-#x0C10] +| [#x0C12-#x0C28] +| [#x0C2A-#x0C33] +| [#x0C35-#x0C39] +| [#x0C60-#x0C61] +| [#x0C85-#x0C8C] +| [#x0C8E-#x0C90] +| [#x0C92-#x0CA8] +| [#x0CAA-#x0CB3] +| [#x0CB5-#x0CB9] +| #x0CDE +| [#x0CE0-#x0CE1] +| [#x0D05-#x0D0C] +| [#x0D0E-#x0D10] +| [#x0D12-#x0D28] +| [#x0D2A-#x0D39] +| [#x0D60-#x0D61] +| [#x0E01-#x0E2E] +| #x0E30 +| [#x0E32-#x0E33] +| [#x0E40-#x0E45] +| [#x0E81-#x0E82] +| #x0E84 +| [#x0E87-#x0E88] +| #x0E8A +| #x0E8D +| [#x0E94-#x0E97] +| [#x0E99-#x0E9F] +| [#x0EA1-#x0EA3] +| #x0EA5 +| #x0EA7 +| [#x0EAA-#x0EAB] +| [#x0EAD-#x0EAE] +| #x0EB0 +| [#x0EB2-#x0EB3] +| #x0EBD +| [#x0EC0-#x0EC4] +| [#x0F40-#x0F47] +| [#x0F49-#x0F69] +| [#x10A0-#x10C5] +| [#x10D0-#x10F6] +| #x1100 +| [#x1102-#x1103] +| [#x1105-#x1107] +| #x1109 +| [#x110B-#x110C] +| [#x110E-#x1112] +| #x113C +| #x113E +| #x1140 +| #x114C +| #x114E +| #x1150 +| [#x1154-#x1155] +| #x1159 +| [#x115F-#x1161] +| #x1163 +| #x1165 +| #x1167 +| #x1169 +| [#x116D-#x116E] +| [#x1172-#x1173] +| #x1175 +| #x119E +| #x11A8 +| #x11AB +| [#x11AE-#x11AF] +| [#x11B7-#x11B8] +| #x11BA +| [#x11BC-#x11C2] +| #x11EB +| #x11F0 +| #x11F9 +| [#x1E00-#x1E9B] +| [#x1EA0-#x1EF9] +| [#x1F00-#x1F15] +| [#x1F18-#x1F1D] +| [#x1F20-#x1F45] +| [#x1F48-#x1F4D] +| [#x1F50-#x1F57] +| #x1F59 +| #x1F5B +| #x1F5D +| [#x1F5F-#x1F7D] +| [#x1F80-#x1FB4] +| [#x1FB6-#x1FBC] +| #x1FBE +| [#x1FC2-#x1FC4] +| [#x1FC6-#x1FCC] +| [#x1FD0-#x1FD3] +| [#x1FD6-#x1FDB] +| [#x1FE0-#x1FEC] +| [#x1FF2-#x1FF4] +| [#x1FF6-#x1FFC] +| #x2126 +| [#x212A-#x212B] +| #x212E +| [#x2180-#x2182] +| [#x3041-#x3094] +| [#x30A1-#x30FA] +| [#x3105-#x312C] +| [#xAC00-#xD7A3] + +Ideographic +[#x4E00-#x9FA5] +| #x3007 +| [#x3021-#x3029] + +CombiningChar +[#x0300-#x0345] +| [#x0360-#x0361] +| [#x0483-#x0486] +| [#x0591-#x05A1] +| [#x05A3-#x05B9] +| [#x05BB-#x05BD] +| #x05BF +| [#x05C1-#x05C2] +| #x05C4 +| [#x064B-#x0652] +| #x0670 +| [#x06D6-#x06DC] +| [#x06DD-#x06DF] +| [#x06E0-#x06E4] +| [#x06E7-#x06E8] +| [#x06EA-#x06ED] +| [#x0901-#x0903] +| #x093C +| [#x093E-#x094C] +| #x094D +| [#x0951-#x0954] +| [#x0962-#x0963] +| [#x0981-#x0983] +| #x09BC +| #x09BE +| #x09BF +| [#x09C0-#x09C4] +| [#x09C7-#x09C8] +| [#x09CB-#x09CD] +| #x09D7 +| [#x09E2-#x09E3] +| #x0A02 +| #x0A3C +| #x0A3E +| #x0A3F +| [#x0A40-#x0A42] +| [#x0A47-#x0A48] +| [#x0A4B-#x0A4D] +| [#x0A70-#x0A71] +| [#x0A81-#x0A83] +| #x0ABC +| [#x0ABE-#x0AC5] +| [#x0AC7-#x0AC9] +| [#x0ACB-#x0ACD] +| [#x0B01-#x0B03] +| #x0B3C +| [#x0B3E-#x0B43] +| [#x0B47-#x0B48] +| [#x0B4B-#x0B4D] +| [#x0B56-#x0B57] +| [#x0B82-#x0B83] +| [#x0BBE-#x0BC2] +| [#x0BC6-#x0BC8] +| [#x0BCA-#x0BCD] +| #x0BD7 +| [#x0C01-#x0C03] +| [#x0C3E-#x0C44] +| [#x0C46-#x0C48] +| [#x0C4A-#x0C4D] +| [#x0C55-#x0C56] +| [#x0C82-#x0C83] +| [#x0CBE-#x0CC4] +| [#x0CC6-#x0CC8] +| [#x0CCA-#x0CCD] +| [#x0CD5-#x0CD6] +| [#x0D02-#x0D03] +| [#x0D3E-#x0D43] +| [#x0D46-#x0D48] +| [#x0D4A-#x0D4D] +| #x0D57 +| #x0E31 +| [#x0E34-#x0E3A] +| [#x0E47-#x0E4E] +| #x0EB1 +| [#x0EB4-#x0EB9] +| [#x0EBB-#x0EBC] +| [#x0EC8-#x0ECD] +| [#x0F18-#x0F19] +| #x0F35 +| #x0F37 +| #x0F39 +| #x0F3E +| #x0F3F +| [#x0F71-#x0F84] +| [#x0F86-#x0F8B] +| [#x0F90-#x0F95] +| #x0F97 +| [#x0F99-#x0FAD] +| [#x0FB1-#x0FB7] +| #x0FB9 +| [#x20D0-#x20DC] +| #x20E1 +| [#x302A-#x302F] +| #x3099 +| #x309A + +Digit +[#x0030-#x0039] +| [#x0660-#x0669] +| [#x06F0-#x06F9] +| [#x0966-#x096F] +| [#x09E6-#x09EF] +| [#x0A66-#x0A6F] +| [#x0AE6-#x0AEF] +| [#x0B66-#x0B6F] +| [#x0BE7-#x0BEF] +| [#x0C66-#x0C6F] +| [#x0CE6-#x0CEF] +| [#x0D66-#x0D6F] +| [#x0E50-#x0E59] +| [#x0ED0-#x0ED9] +| [#x0F20-#x0F29] + +Extender +#x00B7 +| #x02D0 +| #x02D1 +| #x0387 +| #x0640 +| #x0E46 +| #x0EC6 +| #x3005 +| [#x3031-#x3035] +| [#x309D-#x309E] +| [#x30FC-#x30FE] + + + + +

+

The character classes defined here can be derived from the +Unicode character database as follows: + + +

Name start characters must have one of the categories Ll, Lu, +Lo, Lt, Nl.

+ + +

Name characters other than Name-start characters +must have one of the categories Mc, Me, Mn, Lm, or Nd.

+
+ +

Characters in the compatibility area (i.e. with character code +greater than #xF900 and less than #xFFFE) are not allowed in XML +names.

+
+ +

Characters which have a font or compatibility decomposition (i.e. those +with a "compatibility formatting tag" in field 5 of the database -- +marked by field 5 beginning with a "<") are not allowed.

+
+ +

The following characters are treated as name-start characters +rather than name characters, because the property file classifies +them as Alphabetic: [#x02BB-#x02C1], #x0559, #x06E5, #x06E6.

+
+ +

Characters #x20DD-#x20E0 are excluded (in accordance with +Unicode, section 5.14).

+
+ +

Character #x00B7 is classified as an extender, because the +property list so identifies it.

+
+ +

Character #x0387 is added as a name character, because #x00B7 +is its canonical equivalent.

+
+ +

Characters ':' and '_' are allowed as name-start characters.

+
+ +

Characters '-' and '.' are allowed as name characters.

+
+ +

+
+ +XML and SGML + +

XML is designed to be a subset of SGML, in that every +valid XML document should also be a +conformant SGML document. +For a detailed comparison of the additional restrictions that XML places on +documents beyond those of SGML, see . +

+
+ +Expansion of Entity and Character References +

This appendix contains some examples illustrating the +sequence of entity- and character-reference recognition and +expansion, as specified in .

+

+If the DTD contains the declaration +An ampersand (&#38;) may be escaped +numerically (&#38;#38;) or with a general entity +(&amp;).

" > +]]> +then the XML processor will recognize the character references +when it parses the entity declaration, and resolve them before +storing the following string as the +value of the entity "example": +An ampersand (&) may be escaped +numerically (&#38;) or with a general entity +(&amp;).

+]]>
+A reference in the document to "&example;" +will cause the text to be reparsed, at which time the +start- and end-tags of the "p" element will be recognized +and the three references will be recognized and expanded, +resulting in a "p" element with the following content +(all data, no delimiters or markup): + +

+

A more complex example will illustrate the rules and their +effects fully. In the following example, the line numbers are +solely for reference. + +2 +4 +5 ' > +6 %xx; +7 ]> +8 This sample shows a &tricky; method. +]]> +This produces the following: + +

in line 4, the reference to character 37 is expanded immediately, +and the parameter entity "xx" is stored in the symbol +table with the value "%zz;". Since the replacement text +is not rescanned, the reference to parameter entity "zz" +is not recognized. (And it would be an error if it were, since +"zz" is not yet declared.)

+

in line 5, the character reference "&#60;" is +expanded immediately and the parameter entity "zz" is +stored with the replacement text +"<!ENTITY tricky "error-prone" >", +which is a well-formed entity declaration.

+

in line 6, the reference to "xx" is recognized, +and the replacement text of "xx" (namely +"%zz;") is parsed. The reference to "zz" +is recognized in its turn, and its replacement text +("<!ENTITY tricky "error-prone" >") is parsed. +The general entity "tricky" has now been +declared, with the replacement text "error-prone".

+

+in line 8, the reference to the general entity "tricky" is +recognized, and it is expanded, so the full content of the +"test" element is the self-describing (and ungrammatical) string +This sample shows a error-prone method. +

+ +

+
+ +Deterministic Content Models +

For compatibility, it is +required +that content models in element type declarations be deterministic. +

+ +

SGML +requires deterministic content models (it calls them +"unambiguous"); XML processors built using SGML systems may +flag non-deterministic content models as errors.

+

For example, the content model ((b, c) | (b, d)) is +non-deterministic, because given an initial b the parser +cannot know which b in the model is being matched without +looking ahead to see which element follows the b. +In this case, the two references to +b can be collapsed +into a single reference, making the model read +(b, (c | d)). An initial b now clearly +matches only a single name in the content model. The parser doesn't +need to look ahead to see what follows; either c or +d would be accepted.

+

More formally: a finite state automaton may be constructed from the +content model using the standard algorithms, e.g. algorithm 3.5 +in section 3.9 +of Aho, Sethi, and Ullman . +In many such algorithms, a follow set is constructed for each +position in the regular expression (i.e., each leaf +node in the +syntax tree for the regular expression); +if any position has a follow set in which +more than one following position is +labeled with the same element type name, +then the content model is in error +and may be reported as an error. +

+

Algorithms exist which allow many but not all non-deterministic +content models to be reduced automatically to equivalent deterministic +models; see Brüggemann-Klein 1991 .

+
+ +Autodetection of Character Encodings +

The XML encoding declaration functions as an internal label on each +entity, indicating which character encoding is in use. Before an XML +processor can read the internal label, however, it apparently has to +know what character encoding is in use—which is what the internal label +is trying to indicate. In the general case, this is a hopeless +situation. It is not entirely hopeless in XML, however, because XML +limits the general case in two ways: each implementation is assumed +to support only a finite set of character encodings, and the XML +encoding declaration is restricted in position and content in order to +make it feasible to autodetect the character encoding in use in each +entity in normal cases. Also, in many cases other sources of information +are available in addition to the XML data stream itself. +Two cases may be distinguished, +depending on whether the XML entity is presented to the +processor without, or with, any accompanying +(external) information. We consider the first case first. +

+

+Because each XML entity not in UTF-8 or UTF-16 format must +begin with an XML encoding declaration, in which the first characters +must be '<?xml', any conforming processor can detect, +after two to four octets of input, which of the following cases apply. +In reading this list, it may help to know that in UCS-4, '<' is +"#x0000003C" and '?' is "#x0000003F", and the Byte +Order Mark required of UTF-16 data streams is "#xFEFF".

+

+ + +

00 00 00 3C: UCS-4, big-endian machine (1234 order)

+ + +

3C 00 00 00: UCS-4, little-endian machine (4321 order)

+
+ +

00 00 3C 00: UCS-4, unusual octet order (2143)

+
+ +

00 3C 00 00: UCS-4, unusual octet order (3412)

+
+ +

FE FF: UTF-16, big-endian

+
+ +

FF FE: UTF-16, little-endian

+
+ +

00 3C 00 3F: UTF-16, big-endian, no Byte Order Mark +(and thus, strictly speaking, in error)

+
+ +

3C 00 3F 00: UTF-16, little-endian, no Byte Order Mark +(and thus, strictly speaking, in error)

+
+ +

3C 3F 78 6D: UTF-8, ISO 646, ASCII, some part of ISO 8859, +Shift-JIS, EUC, or any other 7-bit, 8-bit, or mixed-width encoding +which ensures that the characters of ASCII have their normal positions, +width, +and values; the actual encoding declaration must be read to +detect which of these applies, but since all of these encodings +use the same bit patterns for the ASCII characters, the encoding +declaration itself may be read reliably +

+
+ +

4C 6F A7 94: EBCDIC (in some flavor; the full +encoding declaration must be read to tell which code page is in +use)

+
+ +

other: UTF-8 without an encoding declaration, or else +the data stream is corrupt, fragmentary, or enclosed in +a wrapper of some kind

+
+ +

+

+This level of autodetection is enough to read the XML encoding +declaration and parse the character-encoding identifier, which is +still necessary to distinguish the individual members of each family +of encodings (e.g. to tell UTF-8 from 8859, and the parts of 8859 +from each other, or to distinguish the specific EBCDIC code page in +use, and so on). +

+

+Because the contents of the encoding declaration are restricted to +ASCII characters, a processor can reliably read the entire encoding +declaration as soon as it has detected which family of encodings is in +use. Since in practice, all widely used character encodings fall into +one of the categories above, the XML encoding declaration allows +reasonably reliable in-band labeling of character encodings, even when +external sources of information at the operating-system or +transport-protocol level are unreliable. +

+

+Once the processor has detected the character encoding in use, it can +act appropriately, whether by invoking a separate input routine for +each case, or by calling the proper conversion function on each +character of input. +

+

+Like any self-labeling system, the XML encoding declaration will not +work if any software changes the entity's character set or encoding +without updating the encoding declaration. Implementors of +character-encoding routines should be careful to ensure the accuracy +of the internal and external information used to label the entity. +

+

The second possible case occurs when the XML entity is accompanied +by encoding information, as in some file systems and some network +protocols. +When multiple sources of information are available, + +their relative +priority and the preferred method of handling conflict should be +specified as part of the higher-level protocol used to deliver XML. +Rules for the relative priority of the internal label and the +MIME-type label in an external header, for example, should be part of the +RFC document defining the text/xml and application/xml MIME types. In +the interests of interoperability, however, the following rules +are recommended. + +

If an XML entity is in a file, the Byte-Order Mark +and encoding-declaration PI are used (if present) to determine the +character encoding. All other heuristics and sources of information +are solely for error recovery. +

+

If an XML entity is delivered with a +MIME type of text/xml, then the charset parameter +on the MIME type determines the +character encoding method; all other heuristics and sources of +information are solely for error recovery. +

+

If an XML entity is delivered +with a +MIME type of application/xml, then the Byte-Order Mark and +encoding-declaration PI are used (if present) to determine the +character encoding. All other heuristics and sources of +information are solely for error recovery. +

+ +These rules apply only in the absence of protocol-level documentation; +in particular, when the MIME types text/xml and application/xml are +defined, the recommendations of the relevant RFC will supersede +these rules. +

+ +
+ + +W3C XML Working Group + +

This specification was prepared and approved for publication by the +W3C XML Working Group (WG). WG approval of this specification does +not necessarily imply that all WG members voted for its approval. +The current and former members of the XML WG are:

+ + +Jon Bosak, SunChair +James ClarkTechnical Lead +Tim Bray, Textuality and NetscapeXML Co-editor +Jean Paoli, MicrosoftXML Co-editor +C. M. Sperberg-McQueen, U. of Ill.XML +Co-editor +Dan Connolly, W3CW3C Liaison +Paula Angerstein, Texcel +Steve DeRose, INSO +Dave Hollander, HP +Eliot Kimber, ISOGEN +Eve Maler, ArborText +Tom Magliery, NCSA +Murray Maloney, Muzmo and Grif +Makoto Murata, Fuji Xerox Information Systems +Joel Nava, Adobe +Conleth O'Connell, Vignette +Peter Sharpe, SoftQuad +John Tigue, DataChannel + + +
+
+ + diff --git a/test/valid/dia.xml b/test/valid/dia.xml new file mode 100644 index 00000000..d8192e45 --- /dev/null +++ b/test/valid/dia.xml @@ -0,0 +1,160 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/valid/dtds/spec.dtd b/test/valid/dtds/spec.dtd new file mode 100755 index 00000000..0fdfb863 --- /dev/null +++ b/test/valid/dtds/spec.dtd @@ -0,0 +1,972 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/valid/dtds/xmlspec.dtd b/test/valid/dtds/xmlspec.dtd new file mode 100644 index 00000000..55cfba6d --- /dev/null +++ b/test/valid/dtds/xmlspec.dtd @@ -0,0 +1,1102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/valid/xlink.xml b/test/valid/xlink.xml new file mode 100644 index 00000000..19194aaa --- /dev/null +++ b/test/valid/xlink.xml @@ -0,0 +1,529 @@ + + + +]> + + + + + + + +
+ XML Linking Language (XLink) + Version 1.0 + WD-xlink-19990527 + World Wide Web Consortium Working Draft + 29May1999 + +

This draft is for public discussion.

+
+ http://www.w3.org/XML/Group/1999/05/WD-xlink-current + + + http://www.w3.org/XML/Group/1999/05/WD-xlink-19990527 + http://www.w3.org/XML/Group/1999/05/WD-xlink-19990505 + http://www.w3.org/TR/1998/WD-xlink-19980303 + http://www.w3.org/TR/WD-xml-link-970630 + + + + + + Steve DeRose + Inso Corp. and Brown University + Steven_DeRose@Brown.edu + + + David Orchard + IBM Corp. + dorchard@ca.ibm.com + + + Ben Trafford + Invited Expert + bent@exemplary.net + + + + + +

This is a W3C Working Draft for review by W3C members and other interested parties. It is a draft document and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use W3C Working Drafts as reference material or to cite them as other than "work in progress". A list of current W3C working drafts can be found at http://www.w3.org/TR.

+

Note: Since working drafts are subject to frequent change, you are advised to reference the above URI, rather than the URIs for working drafts themselves. Some of the work remaining is described in .

+

This work is part of the W3C XML Activity (for current status, see http://www.w3.org/XML/Activity ). For information about the XPointer language which is expected to be used with XLink, see http://www.w3.org/TR/WD-xptr. +

+

See http://www.w3.org/TR/NOTE-xlink-principles for additional background on the design principles informing XLink.

+

Also see http://www.w3.org/TR/NOTE-xlink-req/ for the XLink requirements that this document attempts to satisfy.

+
+ + + +

This specification defines constructs that may be inserted into XML DTDs, schemas and document instances to describe links between objects. It uses XML syntax to create structures that can describe the simple unidirectional hyperlinks of today's HTML as well as more sophisticated links.

+
+ + +

Burlington, Seekonk, et al.: World-Wide Web Consortium, XML Working Group, 1998.

+
+ + +

Created in electronic form.

+
+ + + English + Extended Backus-Naur Form (formal grammar) + + + + + 1997-01-15 : Skeleton draft by TB + 1997-01-24 : Fleshed out by sjd + 1997-04-08 : Substantive draft + 1997-06-30 : Public draft + 1997-08-01 : Public draft + 1997-08-05 : Prose/organization work by sjd + 1997-10-14: Conformance and design principles; a bit of cleanup by elm + 1997-11-07: Update for editorial issues per issues doc, by sjd. + 1997-12-01: Update for editorial issues per issues doc in preparation for F2F meeting, by sjd. + 1998-01-13: Editorial cleanup, addition of new design principles, by elm. + 1998-02-27: Splitting out of XLink and XPointer, by elm. + 1998-03-03: Moved most of the XPointer locator stuff here. elm + 1999-04-24: Editorial rewrites to represent new ideas on XLink, especially the inclusion of arcs. bent + 1999-05-05: Prose/organization work by dorchard. Moved much of the semantics section around, from: locators, link semantics, remote resource semantics, local resource semantics; to: resource semantics, locators, behavior semantics, link semantics, arc semantics + 1999-05-12: Prose/organization work. Re-organized some of the sections, removed XML constructs from the document, added descriptive prose, edited document text for clarity. Rewrote the link recognition section. bent + 1999-05-17: Further prose work. Added non-normative examples. Clarified arcs. bent + 1999-05-23: Edited for grammar and clarity. bent + 1999-05-27: Final once-over before sending to group. Fixed sjd's email address. bent + + +
+ + + + Introduction +

This specification defines constructs that may be inserted into XML DTDs, schemas, and document instances to describe links between objects. A link, as the term is used here, is an explicit relationship between two or more data objects or portions of data objects. This specification is concerned with the syntax used to assert link existence and describe link characteristics. Implicit (unasserted) relationships, for example that of one word to the next or that of a word in a text to its entry in an on-line dictionary are obviously important, but outside its scope.

+

Links are asserted by elements contained in XML document instances. The simplest case is very like an HTML A link, and has these characteristics: + +

The link is expressed at one of its ends (similar to the A element in some document)

+

Users can only initiate travel from that end to the other

+

The link's effect on windows, frames, go-back lists, stylesheets in use, and so on is mainly determined by browsers, not by the link itself. For example, traveral of A links normally replaces the current view, perhaps with a user option to open a new window.

+

The link goes to only one destination (although a server may have great freedom in finding or dynamically creating that destination).

+ +

+

While this set of characteristics is already very powerful and obviously has proven itself highly useful and effective, each of these assumptions also limits the range of hypertext functionality. The linking model defined here provides ways to create links that go beyond each of these specific characteristics, thus providing features previously available mostly in dedicated hypermedia systems. +

+ + + Origin and Goals +

Following is a summary of the design principles governing XLink: + +

XLink must be straightforwardly usable over the Internet.

+

XLink must be usable by a wide variety of link usage domains and classes of linking application software.

+

XLink must support HTML 4.0 linking constructs.

+

The XLink expression language must be XML.

+

The XLink design must be formal, concise, and illustrative.

+

XLinks must be human-readable and human-writable.

+

XLinks may reside within or outside the documents in which the + participating resources reside.

+

XLink must represent the abstract structure and significance of links.

+

XLink must be feasible to implement.

+

XLink must be informed by knowledge of established hypermedia systems and standards.

+ +

+
+ + + + Relationship to Existing Standards +

Three standards have been especially influential: + +

HTML: Defines several SGML element types that represent links.

+

HyTime: Defines inline and out-of-line link structures and some semantic features, including traversal control and presentation of objects. +

+

Text Encoding Initiative Guidelines (TEI P3): Provides structures for creating links, aggregate objects, and link collections out of them.

+ +

+

Many other linking systems have also informed this design, especially Dexter, FRESS, MicroCosm, and InterMedia.

+
+ + + Terminology +

The following basic terms apply in this document. + + + +

A symbolic representation of traversal behavior in links, especially the direction, context and timing of traversal.

+ + + +

A representation of the relevant structure specified by the tags and attributes in an XML document, based on "groves" as defined in the ISO DSSSL standard.

+
+ + +

Abstractly, a link which serves as one of its own resources. Concretely, a link where the content of the linking element serves as a participating resource. + HTML A, HyTime clink, and TEI XREF + are all inline links.

+
+ + +

An explicit relationship between two or more data objects or portions of data objects.

+
+ + +

An element that asserts the existence and describes the characteristics of a link.

+
+ + +

The content of an inlinelinking element. Note that the content of the linking element could be explicitly pointed to by means of a regular locator in the same linking element, in which case the resource is considered remote, not local.

+
+ + +

Data, provided as part of a link, which identifies a + resource.

+
+ + +

A link whose traversal can be initiated from more than one of its participating resources. Note that being able to "go back" after following a one-directional link does not make the link multidirectional.

+
+ + +

A link whose content does not serve as one of the link's participating resources . Such links presuppose a notion like extended link groups, which instruct application software where to look for links. Out-of-line links are generally required for supporting multidirectional traversal and for allowing read-only resources to have outgoing links.

+
+ +

In the context of link behavior, a parsed link is any link whose content is transcluded into the document where the link originated. The use of the term "parsed" directly refers to the concept in XML of a + parsed entity.

+
+ + +

A resource that belongs to a link. All resources are potential contributors to a link; participating resources are the actual contributors to a particular link.

+
+ + +

Any participating resource of a link that is pointed to with a locator.

+
+ + +

In the abstract sense, an addressable unit of information or service that is participating in a link. Examples include files, images, documents, programs, and query results. Concretely, anything reachable by the use of a locator in some linking element. Note that this term and its definition are taken from the basic specifications governing the World Wide Web. +

+
+ + +

A portion of a resource, pointed to as the precise destination of a link. As one example, a link might specify that an entire document be retrieved and displayed, but that some specific part(s) of it is the specific linked data, to be treated in an application-appropriate manner such as indication by highlighting, scrolling, etc.

+
+ + +

The action of using a link; that is, of accessing a resource. Traversal may be initiated by a user action (for example, clicking on the displayed content of a linking element) or occur under program control.

+
+ +

+
+ + + Notation +

The formal grammar for locators is given using a simple Extended Backus-Naur Form (EBNF) location, as described in the XML specification.

+ +
+
+ + + Locator Syntax +

The locator for a resource is typically provided by means of a Uniform Resource Identifier, or URI. XPointers can be used in conjunction with the URI structure, as fragment identifiers, to specify a more precise sub-resource.

+ +

A locator generally contains a URI, as described in IETF RFCs and . As these RFCs state, the URI may include a trailing query (marked by a leading "?"), and be followed by a "#" and a fragment identifier, with the query interpreted by the host providing the indicated resource, and the interpretation of the fragment identifier dependent on the data type of the indicated resource.

+ +

In order to locate XML documents and portions of documents, a locator value may contain either a URI or a fragment identifier, or both. Any fragment identifier for pointing into XML must be an XPointer.

+

Special syntax may be used to request the use of particular processing models in accessing the locator's resource. This is designed to reflect the realities of network operation, where it may or may not be desirable to exercise fine control over the distribution of work between local and remote processors. + + Locator + + Locator + URI + | Connector (XPointer | Name) + | URI Connector (XPointer | Name) + + + Connector'#' | '|' + + + URIURIchar* + + +

+

In this discussion, the term designated resource refers to the resource which an entire locator serves to locate. The following rules apply: + + +

The URI, if provided, locates a resource called the containing resource.

+ + +

If the URI is not provided, the containing resource is considered to be the document in which the linking element is contained. +

+ +

If an XPointer is provided, the designated resource is a sub-resource + of the containing resource; otherwise the designated resource is the + containing resource.

+
+ + +

If the Connector is followed directly by a Name, the Name is shorthand for the XPointer"id(Name)"; that is, the sub-resource is the element in the containing resource that has an XML ID attribute whose value matches the Name. This shorthand is to encourage use of the robust id addressing mode.

+
+ + +

If the connector is "#", this signals an intent that the containing resource is to be fetched as a whole from the host that provides it, and that the XPointer processing to extract the sub-resource + is to be performed on the client, that is to say on the same system where the linking element is recognized and processed.

+
+ +

If the connector is "|", no intent is signaled as to what processing model is to be used to go about accessing the designated resource.

+
+ +

+

Note that the definition of a URI includes an optional query component.

+

In the case where the URI contains a query (to be interpreted by the server), information providers and authors of server software are urged to use queries as follows: + + Query + + Query'XML-XPTR=' ( XPointer | Name) + + +

+ +
+ + + Link Recognition +

The existence of a link is asserted by a linking element. Linking elements must be recognized reliably by application software in order to provide appropriate display and behavior. There are several ways link recognition could be accomplished: for example, reserving element type names, reserving attributes names, leaving the matter of recognition entirely up to stylesheets and application software, or using the XLink namespace to specify element names and attribute names that would be recognized by namespace and XLink-aware processors. Using element and attribute names within the XLink namespace provides a balance between giving users control of their own markup language design and keeping the identification of linking elements simple and unambiguous.

+

The two approaches to identifying linking elements are relatively simple to implement. For example, here's how the HTML A element would be declared using attributes within the XLink namespace, and then how an element within the XLink namespace might do the same: + <A xlink:type="simple" xlink:href="http://www.w3.org/TR/wd-xlink/" +xlink:title="The Xlink Working Draft">The XLink Working Draft.</A> + <xlink:simple href="http://www.w3.org/TR/wd-xlink/" +title="The XLink Working Draft">The XLink Working Draft</xlink:simple> + Any arbitrary element can be made into an XLink by using the xlink:type attribute. And, of course, the explicit XLink elements may be used, as well. This document will go on to describe the linking attributes that are associated with linking elements. It may be assumed by the reader that these attributes would require the xlink namespace prefix if they existed within an arbitrary element, or that they may be used directly if they exist within an explicit Xlink element.

+ +
+ + + + Linking Attributes +

XLink has several attributes associated with the variety of links it may represent. These attributes define four main concepts: locators, arcs, behaviors, and semantics. Locators define where the actual resource is located. Arcs define the traversal of links. Where does the link come from? Where does it go to? All this information can be stored in the arc attributes. Behaviors define how the link is activated, and what the application should do with the resource being linked to. Semantics define useful information that the application may use, and enables the link for such specalized targets as constricted devices and accessibility software.

+ + + Locator Attributes +

The only locator attribute at this time is href. This attribute must contain either a string in the form of a URI that defines the remote resource being linked to, a string containing a fragment identifier that links to a local resource, or a string containing a URI with a fragment identifier concacenated onto it.

+
+ + + Arc Attributes +

Arcs contain two attributes, from and to. The from attribute may contain a string containing the content of a role attribute from the resource being linked from. The purpose of the from attribute is to define where this link is being actuated from.

+

The to attribute may contain a string containing the content of a role attribute from the resource being linked to. The purpose of the to attribute is to define where this link traverses to.

+

The application may use this information in a number of ways, especially in a complex hypertext system, but it is mainly useful in providing context for application behavior.

+ +
+ + + Behavior Attributes +

There are two attributes associated with behavior: show and actuate. The show attribute defines how the remote resource is to be revealed to the user. It has three options: new, parsed, and replace. The new option indicates that the remote resource should be shown in a new window (or other device context) without replacing the previous content. The parsed option, relating directly to the XML concept of a parsed entity, indicates that the content should be integrated into the document from which the link was actuated. The replace option is the one most commonly seen on the World Wide Web, where the document being linked from is entirely replaced by the object being linked to.

+

The actuate attribute defines how the link is initiated. It has two options: user and auto. The user option indicates that the link must be initiated by some sort of human-initiated selection, such as clicking on an HTML anchor. The auto option indicates that the link is automatically initiated when the application deems that the user has reached the link. It then follows the behavior set out in the show option.

+ +
+ + + Semantic Attributes +

There are two attributes associated with semantics, role and title. The role attribute is a generic string used to describe the function of the link's content. For example, a poem might have a link with a role="stanza". The role is also used as an identifier for the from and to attributes of arcs.

+

The title attribute is designed to provide human-readable text describing the link. It is very useful for those who have text-based applications, whether that be due to a constricted device that cannot display the link's content, or if it's being read by an application to a visually-impaired user, or if it's being used to create a table of links. The title attribute contains a simple, descriptive string.

+
+
+ + + Linking Elements +

There are several kinds of linking elements in XLink: simple links, locators, arcs, and extended links. These elements may be instantiated via element declarations from the XLink namespace, or they may be instantiated via attribute declarations from the XLink namespace. Both kinds of instantiation are described in the definition of each linking element.

+

The simple link is used to declare a link that approximates the functionality of the HTML A element. It has, however, a few added features to increase its value, including the potential declaration of semantics and behavior. The locator elements are used to define the resource being linked to. Some links may contain multiple locators, representing a choice of potential links to be traversed. The arcs are used to define the traversal semantics of the link. Finally, an extended linking element differs from a simple link in that it can connect any number of resources, not just one local resource (optionally) and one remote resource, and in that extended links are more often out-of-line than simple links.

+ + + Simple Links + +

The following are two examples of linking elements, each showing all the possible attributes that can be associated with a simple link. Here is the explicit XLink simple linking element. + <!ELEMENT xlink:simple ANY> +<!ATTLIST xlink:slink + href CDATA #REQUIRED + role CDATA #IMPLIED + title CDATA #IMPLIED + show (new|parsed|replace) "replace" + actuate (user|auto) "user" +> + And here is how to make an arbitrary element into a simple link. + <!ELEMENT xlink:simple ANY> +<!ATTLIST foo + xlink:type (simple|extended|locator|arc) #FIXED "simple" + xlink:href CDATA #REQUIRED + xlink:role CDATA #IMPLIED + xlink:title CDATA #IMPLIED + xlink:show (new|parsed|replace) "replace" + xlink:actuate (user|auto) "user" +> + Here is how the first example might look in a document: +<xlink:simple href="http://www.w3.org/TR/wd-xlink" role="working draft" + title="The XLink Working Draft" show="replace" actuate="user"> +The XLink Working Draft.</xlink:simple> +<foo xlink:href="http://www.w3.org/TR/wd-xlink" xlink:role="working draft" + xlink:title="The XLink Working Draft" xlink:show="new" xlink:actuate="user"> +The XLink Working Draft.</foo> + Alternately, a simple link could be as terse as this: +<foo xlink:href="#stanza1">The First Stanza.</foo> +

+

+ There are no constraints on the contents of a simple linking element. In + the sample declaration above, it is given a content model of ANY + to illustrate that any content model or declared content is acceptable. In + a valid document, every element that is significant to XLink must still conform + to the constraints expressed in its governing DTD.

+

Note that it is meaningful to have an out-of-line simple link, although + such links are uncommon. They are called "one-ended" and are typically used + to associate discrete semantic properties with locations. The properties might + be expressed by attributes on the link, the link's element type name, or in + some other way, and are not considered full-fledged resources of the link. + Most out-of-line links are extended links, as these have a far wider range + of uses.

+
+ + +Extended Links +

An extended link differs from a simple link in that it can connect any number of resources, not just one local resource (optionally) and one remote resource, and in that extended links are more often out-of-line than simple links.

+

These additional capabilities of extended links are required for: + + +

Enabling outgoing links in documents that cannot be modified to add an inline link

+ + +

Creating links to and from resources in formats with no native support for embedded links (such as most multimedia formats)

+
+ +

Applying and filtering sets of relevant links on demand

+
+

Enabling other advanced hypermedia capabilities

+ +

+

Application software might be expected to provide traversal among all of a link's participating resources (subject to semantic constraints outside the scope of this specification) and to signal the fact that a given resource or sub-resource participates in one or more links when it is displayed (even though there is no markup at exactly that point to signal it).

+

A linking element for an extended link contains a series of child elements that serve as locators and arcs. Because an extended link can have more than one remote resource, it separates out linking itself from the mechanisms used to locate each resource (whereas a simple link combines the two).

+

The xlink:type attribute value for an extended link must be extended, if the link is being instantiated on an arbitrary element. Note that extended links introduce variants of the show and actuate behavior attributes. These attributes, the showdefault and actuatedefault define the same behavior as their counterparts. However, in this case, they are considered to define the default behavior for all the linking elements that they contain.

+

However, when a linking element within an extended link has a show or actuate attribute of its own, that attribute overrides the defaults set on the extended linking element.

+

The extended linking element itself retains those attributes relevant to the link as a whole, and to its local resource if any. Following are two sample declaration for an extended link. The first is an example of the explicit XLink extended link: + +<!ELEMENT xlink:extended ((xlink:arc | xlink:locator)*)> +<!ATTLIST xlink:extended + role CDATA #IMPLIED + title CDATA #IMPLIED + showdefault (new|parsed|replace) #IMPLIED + actuatedefault (user|auto) #IMPLIED > + + The second is an example of an arbitrary element being used an extended link: + +<!ELEMENT foo ((xlink:arc | xlink:locator)*)> +<!ATTLIST foo + xlink:type (simple|extended|locator|arc) #FIXED "extended" + xlink:role CDATA #IMPLIED + xlink:title CDATA #IMPLIED + xlink:showdefault (new|parsed|replace) #IMPLIED + xlink:actuatedefault (user|auto) #IMPLIED > + + The following two examples demonstrate how each of the above might appear within a document instance. Note that the content of these examples would be other elements. For brevity's sake, they've been left blank. The first example shows how the link might appear, using an explicit XLink extended link: + +<xlink:extended role="address book" title="Ben's Address Book" showdefault="replace" actuatedefault="user"> ... </xlink:extended> + + And the second shows how the link might appear, using an arbitrary element: + +<foo xlink:type="extended" xlink:role="address book" xlink:title="Ben's Address Book" xlink:showdefault="replace" xlink:actuatedefault="user"> ... </foo> +

+ +
+ + + Arc Elements +

An arc is contained within an extended link for the purpose of defining traversal behavior. More than one arc may be associated with a link. Otherwise, arc elements function exactly as the arc attributes might lead on to expect.

+ +
+ +
+ +Conformance +

An element conforms to XLink if: +

The element has an xml:link attribute whose value is +one of the attribute values prescribed by this specification, and

+

the element and all of its attributes and content adhere to the +syntactic +requirements imposed by the chosen xml:link attribute value, +as prescribed in this specification.

+

+

Note that conformance is assessed at the level of individual elements, +rather than whole XML documents, because XLink and non-XLink linking mechanisms +may be used side by side in any one document.

+

An application conforms to XLink if it interprets XLink-conforming elements +according to all required semantics prescribed by this specification and, +for any optional semantics it chooses to support, supports them in the way +prescribed.

+
+ + +Unfinished Work + +Structured Titles +

The simple title mechanism described in this draft is insufficient to cope +with internationalization or the use of multimedia in link titles. A future +version will provide a mechanism for the use of structured link titles.

+
+
+ +References + +Eve Maler and Steve DeRose, editors. +XML Pointer Language (XPointer) V1.0. ArborText, Inso, and Brown +University. Burlington, Seekonk, et al.: World Wide Web Consortium, 1998. +(See http://www.w3.org/TR/WD-xptr + .) +ISO (International Organization for +Standardization). ISO/IEC 10744-1992 (E). Information technology +- Hypermedia/Time-based Structuring Language (HyTime). [Geneva]: +International Organization for Standardization, 1992. Extended +Facilities +Annex. [Geneva]: International Organization for Standardization, +1996. (See http://www.ornl.go +v/sgml/wg8/hytime/html/is10744r.html ). +IETF (Internet Engineering Task +Force). +RFC 1738: Uniform Resource Locators. 1991. (See +http://www.w3.org/Addressing/rfc1738.txt). +IETF (Internet Engineering Task +Force). +RFC 1808: Relative Uniform Resource Locators. 1995. (See http://www.w3.org/Addressing/rfc +1808.txt ). +C. M. Sperberg-McQueen and Lou Burnard, editors. + +Guidelines for Electronic Text Encoding and Interchange. Association +for Computers and the Humanities (ACH), Association for Computational +Linguistics +(ACL), and Association for Literary and Linguistic Computing (ALLC). Chicago, +Oxford: Text Encoding Initiative, 1994. +]Steven J. DeRose and David G. Durand. 1995. "The +TEI Hypertext Guidelines." In Computing and the Humanities +29(3). +Reprinted in Text Encoding Initiative: Background and +Context, +ed. Nancy Ide and Jean ronis , ISBN 0-7923-3704-2. + +
+ diff --git a/test/warning/ent8 b/test/warning/ent8 new file mode 100644 index 00000000..62409390 --- /dev/null +++ b/test/warning/ent8 @@ -0,0 +1,3 @@ + + + &unknown; but Okay diff --git a/testSAX.c b/testSAX.c index c64bc3cd..2b2e89bc 100644 --- a/testSAX.c +++ b/testSAX.c @@ -61,6 +61,7 @@ xmlSAXHandler emptySAXHandlerStruct = { NULL, /* xmlParserWarning */ NULL, /* xmlParserError */ NULL, /* xmlParserError */ + NULL, /* getParameterEntity */ }; xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct; @@ -156,7 +157,10 @@ internalSubsetDebug(xmlParserCtxtPtr ctxt, const CHAR *name, name, ExternalID, SystemID); if ((ExternalID != NULL) || (SystemID != NULL)) { - externalSubset = xmlSAXParseDTD(debugSAXHandler, ExternalID, SystemID); + externalSubset = xmlParseDTD(ExternalID, SystemID); + if (externalSubset != NULL) { + xmlFreeDtd(externalSubset); + } } } @@ -209,6 +213,22 @@ getEntityDebug(xmlParserCtxtPtr ctxt, const CHAR *name) return(NULL); } +/** + * getParameterEntityDebug: + * @ctxt: An XML parser context + * @name: The entity name + * + * Get a parameter entity by name + * + * Returns the xmlParserInputPtr + */ +xmlEntityPtr +getParameterEntityDebug(xmlParserCtxtPtr ctxt, const CHAR *name) +{ + fprintf(stdout, "SAX.getParameterEntity(%s)\n", name); + return(NULL); +} + /** * entityDeclDebug: @@ -541,6 +561,7 @@ xmlSAXHandler debugSAXHandlerStruct = { warningDebug, errorDebug, fatalErrorDebug, + getParameterEntityDebug, }; xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct; diff --git a/testXPath.c b/testXPath.c index 1342ffbf..27e17ab7 100644 --- a/testXPath.c +++ b/testXPath.c @@ -81,7 +81,12 @@ void xmlXPAthDebugDumpNodeSet(FILE *output, xmlNodeSetPtr cur) { fprintf(output, "Set contains %d nodes:\n", cur->nodeNr); for (i = 0;i < cur->nodeNr;i++) { fprintf(output, "%d", i + 1); - xmlDebugDumpOneNode(output, cur->nodeTab[i], 2); + if (cur->nodeTab[i] == NULL) + fprintf(output, " NULL\n"); + else if (cur->nodeTab[i]->type == XML_DOCUMENT_NODE) + fprintf(output, " /\n"); + else + xmlDebugDumpOneNode(output, cur->nodeTab[i], 2); } } diff --git a/tester.c b/tester.c index af7722e9..89d1ff67 100644 --- a/tester.c +++ b/tester.c @@ -35,6 +35,10 @@ static int copy = 0; static int recovery = 0; static int noent = 0; static int noout = 0; +static int valid = 0; +static int repeat = 0; + +extern int xmlDoValidityCheckingDefaultValue; /* * Note: there is a couple of errors introduced on purpose. @@ -178,7 +182,7 @@ void parseAndPrintBuffer(CHAR *buf) { } int main(int argc, char **argv) { - int i; + int i, count; int files = 0; for (i = 1; i < argc ; i++) { @@ -195,11 +199,22 @@ int main(int argc, char **argv) { else if ((!strcmp(argv[i], "-noout")) || (!strcmp(argv[i], "--noout"))) noout++; + else if ((!strcmp(argv[i], "-valid")) || + (!strcmp(argv[i], "--valid"))) + valid++; + else if ((!strcmp(argv[i], "-repeat")) || + (!strcmp(argv[i], "--repeat"))) + repeat++; } if (noent != 0) xmlSubstituteEntitiesDefault(1); + if (valid != 0) xmlDoValidityCheckingDefaultValue = 1; for (i = 1; i < argc ; i++) { if (argv[i][0] != '-') { - parseAndPrintFile(argv[i]); + if (repeat) { + for (count = 0;count < 100 * repeat;count++) + parseAndPrintFile(argv[i]); + } else + parseAndPrintFile(argv[i]); files ++; } } @@ -212,6 +227,7 @@ int main(int argc, char **argv) { printf("\t--recover : output what is parsable on broken XmL documents\n"); printf("\t--noent : substitute entity references by their value\n"); printf("\t--noout : don't output the result\n"); + printf("\t--repeat : parse the file 100 times, for timing or profiling\n"); } return(0); diff --git a/tree.c b/tree.c index 86fd4ff7..7c61ea54 100644 --- a/tree.c +++ b/tree.c @@ -1126,6 +1126,46 @@ xmlNewComment(const CHAR *content) { return(cur); } +/** + * xmlNewCDataBlock: + * @doc: the document + * @content: the CData block content content + * @len: the length of the block + * + * Creation of a new node containing a CData block. + * Returns a pointer to the new node object. + */ +xmlNodePtr +xmlNewCDataBlock(xmlDocPtr doc, const CHAR *content, int len) { + xmlNodePtr cur; + + /* + * Allocate a new node and fill the fields. + */ + cur = (xmlNodePtr) malloc(sizeof(xmlNode)); + if (cur == NULL) { + fprintf(stderr, "xmlNewCDataBlock : malloc failed\n"); + return(NULL); + } + + cur->type = XML_CDATA_SECTION_NODE; + cur->doc = NULL; + cur->parent = NULL; + cur->prev = NULL; + cur->next = NULL; + cur->childs = NULL; + cur->last = NULL; + cur->properties = NULL; + cur->name = xmlStrdup(xmlStringText); + cur->ns = NULL; + cur->nsDef = NULL; + if ((content != NULL) && (len > 0)) { + cur->content = xmlStrndup(content, len); + } else + cur->content = NULL; + return(cur); +} + /** * xmlNewDocComment: * @doc: the document @@ -1725,7 +1765,6 @@ xmlNodeGetContent(xmlNodePtr cur) { return(xmlNodeListGetString(cur->doc, cur->childs, 1)); break; case XML_ATTRIBUTE_NODE: - case XML_CDATA_SECTION_NODE: case XML_ENTITY_REF_NODE: case XML_ENTITY_NODE: case XML_PI_NODE: @@ -1734,6 +1773,7 @@ xmlNodeGetContent(xmlNodePtr cur) { case XML_DOCUMENT_TYPE_NODE: case XML_NOTATION_NODE: return(NULL); + case XML_CDATA_SECTION_NODE: case XML_TEXT_NODE: if (cur->content != NULL) return(xmlStrdup(cur->content)); @@ -2637,6 +2677,13 @@ xmlNodeDump(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, int level) { xmlBufferWriteChar(buf, ";"); return; } + if (cur->type == XML_CDATA_SECTION_NODE) { + xmlBufferWriteChar(buf, "content != NULL) + xmlBufferWriteCHAR(buf, cur->content); + xmlBufferWriteChar(buf, "]]>"); + return; + } if (xmlIndentTreeOutput) for (i = 0;i < level;i++) xmlBufferWriteChar(buf, " "); @@ -2747,10 +2794,9 @@ xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size) { return; } xmlDocContentDump(buf, cur); - *mem = buf->content; + *mem = xmlStrndup(buf->content, buf->use); *size = buf->use; - memset(buf, -1, sizeof(xmlBuffer)); - free(buf); + xmlBufferFree(buf); } /** diff --git a/tree.h b/tree.h index fddabb7e..a627d921 100644 --- a/tree.h +++ b/tree.h @@ -97,6 +97,7 @@ typedef xmlEnumeration *xmlEnumerationPtr; typedef struct xmlAttribute { const CHAR *elem; /* Element holding the attribute */ const CHAR *name; /* Attribute name */ + struct xmlAttribute *next; /* list of attributes of an element */ xmlAttributeType type; /* The type */ xmlAttributeDefault def; /* the default */ const CHAR *defaultValue;/* or the default value */ @@ -138,9 +139,10 @@ typedef enum { } xmlElementTypeVal; typedef struct xmlElement { - const CHAR *name; /* Element name */ - xmlElementTypeVal type; /* The type */ + const CHAR *name; /* Element name */ + xmlElementTypeVal type; /* The type */ xmlElementContentPtr content; /* the allowed element content */ + xmlAttributePtr attributes; /* List of the declared attributes */ } xmlElement; typedef xmlElement *xmlElementPtr; @@ -188,7 +190,7 @@ typedef struct xmlAttr { #endif xmlElementType type; /* XML_ATTRIBUTE_NODE, must be third ! */ struct xmlNode *node; /* attr->node link */ - struct xmlAttr *next; /* parent->childs link */ + struct xmlAttr *next; /* attribute list link */ const CHAR *name; /* the name of the property */ struct xmlNode *val; /* the value of the property */ } xmlAttr; @@ -310,6 +312,7 @@ xmlNodePtr xmlNewDocTextLen(xmlDocPtr doc, const CHAR *content, int len); xmlNodePtr xmlNewTextLen(const CHAR *content, int len); xmlNodePtr xmlNewDocComment(xmlDocPtr doc, const CHAR *content); xmlNodePtr xmlNewComment(const CHAR *content); +xmlNodePtr xmlNewCDataBlock(xmlDocPtr doc, const CHAR *content, int len); xmlNodePtr xmlNewReference(xmlDocPtr doc, const CHAR *name); xmlNodePtr xmlCopyNode(xmlNodePtr node, int recursive); xmlNodePtr xmlCopyNodeList(xmlNodePtr node); diff --git a/valid.c b/valid.c index 87af873a..b23824f3 100644 --- a/valid.c +++ b/valid.c @@ -12,6 +12,20 @@ #include #include "valid.h" #include "parser.h" +#include "parserInternals.h" + +#define VERROR \ + if ((ctxt != NULL) && (ctxt->error != NULL)) ctxt->error + +#define VWARNING \ + if ((ctxt != NULL) && (ctxt->warning != NULL)) ctxt->warning + +#define CHECK_DTD \ + if (doc == NULL) return(0); \ + else if (doc->intSubset == NULL) return(0) + +xmlElementPtr xmlGetDtdElementDesc(xmlDtdPtr dtd, const CHAR *name); +xmlAttributePtr xmlScanAttributeDecl(xmlDtdPtr dtd, const CHAR *elem); /**************************************************************** * * @@ -169,6 +183,68 @@ xmlDumpElementContent(xmlBufferPtr buf, xmlElementContentPtr content, int glob) } } +/** + * xmlSprintfElementContent: + * @buf: an output buffer + * @content: An element table + * @glob: 1 if one must print the englobing parenthesis, 0 otherwise + * + * This will dump the content of the element content definition + * Intended just for the debug routine + */ +void +xmlSprintfElementContent(char *buf, xmlElementContentPtr content, int glob) { + if (content == NULL) return; + if (glob) strcat(buf, "("); + switch (content->type) { + case XML_ELEMENT_CONTENT_PCDATA: + strcat(buf, "#PCDATA"); + break; + case XML_ELEMENT_CONTENT_ELEMENT: + strcat(buf, content->name); + break; + case XML_ELEMENT_CONTENT_SEQ: + if ((content->c1->type == XML_ELEMENT_CONTENT_OR) || + (content->c1->type == XML_ELEMENT_CONTENT_SEQ)) + xmlSprintfElementContent(buf, content->c1, 1); + else + xmlSprintfElementContent(buf, content->c1, 0); + strcat(buf, " , "); + if (content->c2->type == XML_ELEMENT_CONTENT_OR) + xmlSprintfElementContent(buf, content->c2, 1); + else + xmlSprintfElementContent(buf, content->c2, 0); + break; + case XML_ELEMENT_CONTENT_OR: + if ((content->c1->type == XML_ELEMENT_CONTENT_OR) || + (content->c1->type == XML_ELEMENT_CONTENT_SEQ)) + xmlSprintfElementContent(buf, content->c1, 1); + else + xmlSprintfElementContent(buf, content->c1, 0); + strcat(buf, " | "); + if (content->c2->type == XML_ELEMENT_CONTENT_SEQ) + xmlSprintfElementContent(buf, content->c2, 1); + else + xmlSprintfElementContent(buf, content->c2, 0); + break; + } + if (glob) + strcat(buf, ")"); + switch (content->ocur) { + case XML_ELEMENT_CONTENT_ONCE: + break; + case XML_ELEMENT_CONTENT_OPT: + strcat(buf, "?"); + break; + case XML_ELEMENT_CONTENT_MULT: + strcat(buf, "*"); + break; + case XML_ELEMENT_CONTENT_PLUS: + strcat(buf, "+"); + break; + } +} + /**************************************************************** * * * Registration of DTD declarations * @@ -195,8 +271,8 @@ xmlCreateElementTable(void) { } ret->max_elements = XML_MIN_ELEMENT_TABLE; ret->nb_elements = 0; - ret->table = (xmlElementPtr ) - malloc(ret->max_elements * sizeof(xmlElement)); + ret->table = (xmlElementPtr *) + malloc(ret->max_elements * sizeof(xmlElementPtr)); if (ret == NULL) { fprintf(stderr, "xmlCreateElementTable : malloc(%ld) failed\n", ret->max_elements * (long)sizeof(xmlElement)); @@ -219,8 +295,8 @@ xmlCreateElementTable(void) { * Returns NULL if not, othervise the entity */ xmlElementPtr -xmlAddElementDecl(xmlDtdPtr dtd, const CHAR *name, int type, - xmlElementContentPtr content) { +xmlAddElementDecl(xmlValidCtxtPtr ctxt, xmlDtdPtr dtd, const CHAR *name, + int type, xmlElementContentPtr content) { xmlElementPtr ret, cur; xmlElementTablePtr table; int i; @@ -283,13 +359,12 @@ xmlAddElementDecl(xmlDtdPtr dtd, const CHAR *name, int type, * Search the DTD for previous declarations of the ELEMENT */ for (i = 0;i < table->nb_elements;i++) { - cur = &table->table[i]; + cur = table->table[i]; if (!xmlStrcmp(cur->name, name)) { /* * The element is already defined in this Dtd. */ - fprintf(stderr, - "xmlAddElementDecl: %s already defined\n", name); + VERROR(ctxt->userData, "Redefinition of element %s\n", name); return(NULL); } } @@ -302,14 +377,19 @@ xmlAddElementDecl(xmlDtdPtr dtd, const CHAR *name, int type, * need more elements. */ table->max_elements *= 2; - table->table = (xmlElementPtr) - realloc(table->table, table->max_elements * sizeof(xmlElement)); - if (table->table) { + table->table = (xmlElementPtr *) + realloc(table->table, table->max_elements * sizeof(xmlElementPtr)); + if (table->table == NULL) { fprintf(stderr, "xmlAddElementDecl: out of memory\n"); return(NULL); } } - ret = &table->table[table->nb_elements]; + ret = (xmlElementPtr) malloc(sizeof(xmlElement)); + if (ret == NULL) { + fprintf(stderr, "xmlAddElementDecl: out of memory\n"); + return(NULL); + } + table->table[table->nb_elements] = ret; /* * fill the structure. @@ -317,6 +397,7 @@ xmlAddElementDecl(xmlDtdPtr dtd, const CHAR *name, int type, ret->type = type; ret->name = xmlStrdup(name); ret->content = xmlCopyElementContent(content); + ret->attributes = xmlScanAttributeDecl(dtd, name); table->nb_elements++; return(ret); @@ -335,6 +416,7 @@ xmlFreeElement(xmlElementPtr elem) { if (elem->name != NULL) free((CHAR *) elem->name); memset(elem, -1, sizeof(xmlElement)); + free(elem); } /** @@ -350,7 +432,7 @@ xmlFreeElementTable(xmlElementTablePtr table) { if (table == NULL) return; for (i = 0;i < table->nb_elements;i++) { - xmlFreeElement(&table->table[i]); + xmlFreeElement(table->table[i]); } free(table->table); free(table); @@ -375,8 +457,8 @@ xmlCopyElementTable(xmlElementTablePtr table) { fprintf(stderr, "xmlCopyElementTable: out of memory !\n"); return(NULL); } - ret->table = (xmlElementPtr) malloc(table->max_elements * - sizeof(xmlElement)); + ret->table = (xmlElementPtr *) malloc(table->max_elements * + sizeof(xmlElementPtr)); if (ret->table == NULL) { fprintf(stderr, "xmlCopyElementTable: out of memory !\n"); free(ret); @@ -385,14 +467,22 @@ xmlCopyElementTable(xmlElementTablePtr table) { ret->max_elements = table->max_elements; ret->nb_elements = table->nb_elements; for (i = 0;i < ret->nb_elements;i++) { - cur = &ret->table[i]; - ent = &table->table[i]; + cur = (xmlElementPtr) malloc(sizeof(xmlElement)); + if (cur == NULL) { + fprintf(stderr, "xmlCopyElementTable: out of memory !\n"); + free(ret); + free(ret->table); + return(NULL); + } + ret->table[i] = cur; + ent = table->table[i]; cur->type = ent->type; if (ent->name != NULL) cur->name = xmlStrdup(ent->name); else cur->name = NULL; cur->content = xmlCopyElementContent(ent->content); + cur->attributes = NULL; } return(ret); } @@ -412,7 +502,7 @@ xmlDumpElementTable(xmlBufferPtr buf, xmlElementTablePtr table) { if (table == NULL) return; for (i = 0;i < table->nb_elements;i++) { - cur = &table->table[i]; + cur = table->table[i]; switch (cur->type) { case XML_ELEMENT_TYPE_EMPTY: xmlBufferWriteChar(buf, "name); + if (cur->next == NULL) + xmlBufferWriteChar(buf, ")"); + else { + xmlBufferWriteChar(buf, " | "); + xmlDumpEnumeration(buf, cur->next); + } +} + /** * xmlCreateAttributeTable: * @@ -534,20 +644,89 @@ xmlCreateAttributeTable(void) { } ret->max_attributes = XML_MIN_ATTRIBUTE_TABLE; ret->nb_attributes = 0; - ret->table = (xmlAttributePtr ) - malloc(ret->max_attributes * sizeof(xmlAttribute)); + ret->table = (xmlAttributePtr *) + malloc(ret->max_attributes * sizeof(xmlAttributePtr)); if (ret == NULL) { fprintf(stderr, "xmlCreateAttributeTable : malloc(%ld) failed\n", - ret->max_attributes * (long)sizeof(xmlAttribute)); + ret->max_attributes * (long)sizeof(xmlAttributePtr)); free(ret); return(NULL); } return(ret); } +/** + * xmlScanAttributeDecl: + * @dtd: pointer to the DTD + * @elem: the element name + * + * When inserting a new element scan the DtD for existing attributes + * for taht element and initialize the Attribute chain + * + * Returns the pointer to the first attribute decl in the chain, + * possibly NULL. + */ +xmlAttributePtr +xmlScanAttributeDecl(xmlDtdPtr dtd, const CHAR *elem) { + xmlAttributePtr ret = NULL; + xmlAttributeTablePtr table; + int i; + + if (dtd == NULL) { + fprintf(stderr, "xmlScanAttributeDecl: dtd == NULL\n"); + return(NULL); + } + if (elem == NULL) { + fprintf(stderr, "xmlScanAttributeDecl: elem == NULL\n"); + return(NULL); + } + table = dtd->attributes; + if (table == NULL) + return(NULL); + + for (i = 0;i < table->nb_attributes;i++) { + if (!xmlStrcmp(table->table[i]->elem, elem)) { + table->table[i]->next = ret; + ret = table->table[i]; + } + } + return(ret); +} + +/** + * xmlScanIDAttributeDecl: + * @ctxt: the validation context + * @elem: the element name + * + * Veryfy that the element don't have too many ID attributes + * declared. + * + * Returns the number of ID attributes found. + */ +int +xmlScanIDAttributeDecl(xmlValidCtxtPtr ctxt, xmlElementPtr elem) { + xmlAttributePtr cur; + int ret = 0; + + if (elem == NULL) return(0); + cur = elem->attributes; + while (cur != NULL) { + if (cur->type == XML_ATTRIBUTE_ID) { + ret ++; + if (ret > 1) + VERROR(ctxt->userData, + "Element %s has too may ID attributes defined : %s\n", + elem->name, cur->name); + } + cur = cur->next; + } + return(ret); +} + /** * xmlAddAttributeDecl: + * @ctxt: the validation context * @dtd: pointer to the DTD * @elem: the element name * @name: the attribute name @@ -561,11 +740,12 @@ xmlCreateAttributeTable(void) { * Returns NULL if not, othervise the entity */ xmlAttributePtr -xmlAddAttributeDecl(xmlDtdPtr dtd, const CHAR *elem, const CHAR *name, - int type, int def, const CHAR *defaultValue, - xmlEnumerationPtr tree) { +xmlAddAttributeDecl(xmlValidCtxtPtr ctxt, xmlDtdPtr dtd, const CHAR *elem, + const CHAR *name, int type, int def, + const CHAR *defaultValue, xmlEnumerationPtr tree) { xmlAttributePtr ret, cur; xmlAttributeTablePtr table; + xmlElementPtr elemDef; int i; if (dtd == NULL) { @@ -623,7 +803,7 @@ xmlAddAttributeDecl(xmlDtdPtr dtd, const CHAR *elem, const CHAR *name, * Search the DTD for previous declarations of the ATTLIST */ for (i = 0;i < table->nb_attributes;i++) { - cur = &table->table[i]; + cur = table->table[i]; if ((!xmlStrcmp(cur->name, name)) && (!xmlStrcmp(cur->elem, elem))) { /* * The attribute is already defined in this Dtd. @@ -641,14 +821,20 @@ xmlAddAttributeDecl(xmlDtdPtr dtd, const CHAR *elem, const CHAR *name, * need more attributes. */ table->max_attributes *= 2; - table->table = (xmlAttributePtr) - realloc(table->table, table->max_attributes * sizeof(xmlAttribute)); - if (table->table) { + table->table = (xmlAttributePtr *) + realloc(table->table, table->max_attributes * + sizeof(xmlAttributePtr)); + if (table->table == NULL) { fprintf(stderr, "xmlAddAttributeDecl: out of memory\n"); return(NULL); } } - ret = &table->table[table->nb_attributes]; + ret = (xmlAttributePtr) malloc(sizeof(xmlAttribute)); + if (ret == NULL) { + fprintf(stderr, "xmlAddAttributeDecl: out of memory\n"); + return(NULL); + } + table->table[table->nb_attributes] = ret; /* * fill the structure. @@ -662,6 +848,16 @@ xmlAddAttributeDecl(xmlDtdPtr dtd, const CHAR *elem, const CHAR *name, ret->defaultValue = xmlStrdup(defaultValue); else ret->defaultValue = NULL; + elemDef = xmlGetDtdElementDesc(dtd, elem); + if (elemDef != NULL) { + if ((type == XML_ATTRIBUTE_ID) && + (xmlScanIDAttributeDecl(NULL, elemDef) != 0)) + VERROR(ctxt->userData, + "Element %s has too may ID attributes defined : %s\n", + elem, name); + ret->next = elemDef->attributes; + elemDef->attributes = ret; + } table->nb_attributes++; return(ret); @@ -685,6 +881,7 @@ xmlFreeAttribute(xmlAttributePtr attr) { if (attr->defaultValue != NULL) free((CHAR *) attr->defaultValue); memset(attr, -1, sizeof(xmlAttribute)); + free(attr); } /** @@ -700,7 +897,7 @@ xmlFreeAttributeTable(xmlAttributeTablePtr table) { if (table == NULL) return; for (i = 0;i < table->nb_attributes;i++) { - xmlFreeAttribute(&table->table[i]); + xmlFreeAttribute(table->table[i]); } free(table->table); free(table); @@ -725,8 +922,8 @@ xmlCopyAttributeTable(xmlAttributeTablePtr table) { fprintf(stderr, "xmlCopyAttributeTable: out of memory !\n"); return(NULL); } - ret->table = (xmlAttributePtr) malloc(table->max_attributes * - sizeof(xmlAttribute)); + ret->table = (xmlAttributePtr *) malloc(table->max_attributes * + sizeof(xmlAttributePtr)); if (ret->table == NULL) { fprintf(stderr, "xmlCopyAttributeTable: out of memory !\n"); free(ret); @@ -735,8 +932,15 @@ xmlCopyAttributeTable(xmlAttributeTablePtr table) { ret->max_attributes = table->max_attributes; ret->nb_attributes = table->nb_attributes; for (i = 0;i < ret->nb_attributes;i++) { - cur = &ret->table[i]; - attr = &table->table[i]; + attr = table->table[i]; + cur = (xmlAttributePtr) malloc(sizeof(xmlAttribute)); + if (cur == NULL) { + fprintf(stderr, "xmlCopyAttributeTable: out of memory !\n"); + free(ret); + free(ret->table); + return(NULL); + } + ret->table[i] = cur; cur->type = attr->type; cur->def = attr->def; cur->tree = xmlCopyEnumeration(attr->tree); @@ -752,6 +956,7 @@ xmlCopyAttributeTable(xmlAttributeTablePtr table) { cur->defaultValue = xmlStrdup(attr->defaultValue); else cur->defaultValue = NULL; + /* NEED to rebuild the next chain !!!!!! */ } return(ret); } @@ -771,7 +976,7 @@ xmlDumpAttributeTable(xmlBufferPtr buf, xmlAttributeTablePtr table) { if (table == NULL) return; for (i = 0;i < table->nb_attributes;i++) { - cur = &table->table[i]; + cur = table->table[i]; xmlBufferWriteChar(buf, "elem); xmlBufferWriteChar(buf, " "); @@ -802,10 +1007,12 @@ xmlDumpAttributeTable(xmlBufferPtr buf, xmlAttributeTablePtr table) { xmlBufferWriteChar(buf, " NMTOKENS"); break; case XML_ATTRIBUTE_ENUMERATION: - xmlBufferWriteChar(buf, " (pbm)"); + xmlBufferWriteChar(buf, " ("); + xmlDumpEnumeration(buf, cur->tree); break; case XML_ATTRIBUTE_NOTATION: - xmlBufferWriteChar(buf, " NOTATION (pbm)"); + xmlBufferWriteChar(buf, " NOTATION ("); + xmlDumpEnumeration(buf, cur->tree); break; default: fprintf(stderr, @@ -820,20 +1027,19 @@ xmlDumpAttributeTable(xmlBufferPtr buf, xmlAttributeTablePtr table) { break; case XML_ATTRIBUTE_IMPLIED: xmlBufferWriteChar(buf, " #IMPLIED"); - if (cur->defaultValue != NULL) { - xmlBufferWriteChar(buf, " "); - xmlBufferWriteQuotedString(buf, cur->defaultValue); - } break; case XML_ATTRIBUTE_FIXED: - xmlBufferWriteChar(buf, " #FIXED "); - xmlBufferWriteQuotedString(buf, cur->defaultValue); + xmlBufferWriteChar(buf, " #FIXED"); break; default: fprintf(stderr, "xmlDumpAttributeTable: internal: unknown default %d\n", cur->def); } + if (cur->defaultValue != NULL) { + xmlBufferWriteChar(buf, " "); + xmlBufferWriteQuotedString(buf, cur->defaultValue); + } xmlBufferWriteChar(buf, ">\n"); } } @@ -864,8 +1070,8 @@ xmlCreateNotationTable(void) { } ret->max_notations = XML_MIN_NOTATION_TABLE; ret->nb_notations = 0; - ret->table = (xmlNotationPtr ) - malloc(ret->max_notations * sizeof(xmlNotation)); + ret->table = (xmlNotationPtr *) + malloc(ret->max_notations * sizeof(xmlNotationPtr)); if (ret == NULL) { fprintf(stderr, "xmlCreateNotationTable : malloc(%ld) failed\n", ret->max_notations * (long)sizeof(xmlNotation)); @@ -879,6 +1085,7 @@ xmlCreateNotationTable(void) { /** * xmlAddNotationDecl: * @dtd: pointer to the DTD + * @ctxt: the validation context * @name: the entity name * @PublicID: the public identifier or NULL * @SystemID: the system identifier or NULL @@ -888,8 +1095,8 @@ xmlCreateNotationTable(void) { * Returns NULL if not, othervise the entity */ xmlNotationPtr -xmlAddNotationDecl(xmlDtdPtr dtd, const CHAR *name, const CHAR *PublicID, - const CHAR *SystemID) { +xmlAddNotationDecl(xmlValidCtxtPtr ctxt, xmlDtdPtr dtd, const CHAR *name, + const CHAR *PublicID, const CHAR *SystemID) { xmlNotationPtr ret, cur; xmlNotationTablePtr table; int i; @@ -922,7 +1129,7 @@ xmlAddNotationDecl(xmlDtdPtr dtd, const CHAR *name, const CHAR *PublicID, * Search the DTD for previous declarations of the ATTLIST */ for (i = 0;i < table->nb_notations;i++) { - cur = &table->table[i]; + cur = table->table[i]; if (!xmlStrcmp(cur->name, name)) { /* * The notation is already defined in this Dtd. @@ -940,14 +1147,20 @@ xmlAddNotationDecl(xmlDtdPtr dtd, const CHAR *name, const CHAR *PublicID, * need more notations. */ table->max_notations *= 2; - table->table = (xmlNotationPtr) - realloc(table->table, table->max_notations * sizeof(xmlNotation)); - if (table->table) { + table->table = (xmlNotationPtr *) + realloc(table->table, table->max_notations * + sizeof(xmlNotationPtr)); + if (table->table == NULL) { fprintf(stderr, "xmlAddNotationDecl: out of memory\n"); return(NULL); } } - ret = &table->table[table->nb_notations]; + ret = (xmlNotationPtr) malloc(sizeof(xmlNotation)); + if (ret == NULL) { + fprintf(stderr, "xmlAddNotationDecl: out of memory\n"); + return(NULL); + } + table->table[table->nb_notations] = ret; /* * fill the structure. @@ -982,6 +1195,7 @@ xmlFreeNotation(xmlNotationPtr nota) { if (nota->SystemID != NULL) free((CHAR *) nota->SystemID); memset(nota, -1, sizeof(xmlNotation)); + free(nota); } /** @@ -997,7 +1211,7 @@ xmlFreeNotationTable(xmlNotationTablePtr table) { if (table == NULL) return; for (i = 0;i < table->nb_notations;i++) { - xmlFreeNotation(&table->table[i]); + xmlFreeNotation(table->table[i]); } free(table->table); free(table); @@ -1022,8 +1236,8 @@ xmlCopyNotationTable(xmlNotationTablePtr table) { fprintf(stderr, "xmlCopyNotationTable: out of memory !\n"); return(NULL); } - ret->table = (xmlNotationPtr) malloc(table->max_notations * - sizeof(xmlNotation)); + ret->table = (xmlNotationPtr *) malloc(table->max_notations * + sizeof(xmlNotationPtr)); if (ret->table == NULL) { fprintf(stderr, "xmlCopyNotationTable: out of memory !\n"); free(ret); @@ -1032,8 +1246,15 @@ xmlCopyNotationTable(xmlNotationTablePtr table) { ret->max_notations = table->max_notations; ret->nb_notations = table->nb_notations; for (i = 0;i < ret->nb_notations;i++) { - cur = &ret->table[i]; - nota = &table->table[i]; + cur = (xmlNotationPtr) malloc(sizeof(xmlNotation)); + if (cur == NULL) { + fprintf(stderr, "xmlCopyNotationTable: out of memory !\n"); + free(ret); + free(ret->table); + return(NULL); + } + ret->table[i] = cur; + nota = table->table[i]; if (nota->name != NULL) cur->name = xmlStrdup(nota->name); else @@ -1065,7 +1286,7 @@ xmlDumpNotationTable(xmlBufferPtr buf, xmlNotationTablePtr table) { if (table == NULL) return; for (i = 0;i < table->nb_notations;i++) { - cur = &table->table[i]; + cur = table->table[i]; xmlBufferWriteChar(buf, "name); if (cur->PublicID != NULL) { @@ -1082,3 +1303,1070 @@ xmlDumpNotationTable(xmlBufferPtr buf, xmlNotationTablePtr table) { xmlBufferWriteChar(buf, " >\n"); } } + +/************************************************************************ + * * + * Routines for validity checking * + * * + ************************************************************************/ + +/** + * xmlGetDtdElementDesc: + * @dtd: a pointer to the DtD to search + * @name: the element name + * + * Search the Dtd for the description of this element + * + * returns the xmlElementPtr if found or NULL + */ + +xmlElementPtr +xmlGetDtdElementDesc(xmlDtdPtr dtd, const CHAR *name) { + xmlElementTablePtr table; + xmlElementPtr cur; + int i; + + if (dtd == NULL) return(NULL); + if (dtd->elements == NULL) return(NULL); + table = dtd->elements; + + for (i = 0;i < table->nb_elements;i++) { + cur = table->table[i]; + if (!xmlStrcmp(cur->name, name)) + return(cur); + } + return(NULL); +} + +/** + * xmlGetDtdAttrDesc: + * @dtd: a pointer to the DtD to search + * @elem: the element name + * @name: the attribute name + * + * Search the Dtd for the description of this attribute on + * this element. + * + * returns the xmlAttributePtr if found or NULL + */ + +xmlAttributePtr +xmlGetDtdAttrDesc(xmlDtdPtr dtd, const CHAR *elem, const CHAR *name) { + xmlAttributeTablePtr table; + xmlAttributePtr cur; + int i; + + if (dtd == NULL) return(NULL); + if (dtd->attributes == NULL) return(NULL); + table = dtd->attributes; + + for (i = 0;i < table->nb_attributes;i++) { + cur = table->table[i]; + if ((!xmlStrcmp(cur->name, name)) && + (!xmlStrcmp(cur->elem, elem))) + return(cur); + } + return(NULL); +} + +/** + * xmlGetDtdNotationDesc: + * @dtd: a pointer to the DtD to search + * @name: the notation name + * + * Search the Dtd for the description of this notation + * + * returns the xmlNotationPtr if found or NULL + */ + +xmlNotationPtr +xmlGetDtdNotationDesc(xmlDtdPtr dtd, const CHAR *name) { + xmlNotationTablePtr table; + xmlNotationPtr cur; + int i; + + if (dtd == NULL) return(NULL); + if (dtd->notations == NULL) return(NULL); + table = dtd->notations; + + for (i = 0;i < table->nb_notations;i++) { + cur = table->table[i]; + if (!xmlStrcmp(cur->name, name)) + return(cur); + } + return(NULL); +} + +/** + * xmlIsMixedElement + * @doc: the document + * @name: the element name + * + * Search in the DtDs whether an element accept Mixed content (or ANY) + * basically if it is supposed to accept text childs + * + * returns 0 if no, 1 if yes, and -1 if no element description is available + */ + +int +xmlIsMixedElement(xmlDocPtr doc, const CHAR *name) { + xmlElementPtr elemDecl; + + if ((doc == NULL) || (doc->intSubset == NULL)) return(-1); + + elemDecl = xmlGetDtdElementDesc(doc->intSubset, name); + if ((elemDecl == NULL) && (doc->extSubset != NULL)) + elemDecl = xmlGetDtdElementDesc(doc->extSubset, name); + if (elemDecl == NULL) return(-1); + switch (elemDecl->type) { + case XML_ELEMENT_TYPE_ELEMENT: + return(0); + case XML_ELEMENT_TYPE_EMPTY: + /* + * return 1 for EMPTY since we want VC error to pop up + * on for example + */ + case XML_ELEMENT_TYPE_ANY: + case XML_ELEMENT_TYPE_MIXED: + return(1); + } + return(1); +} + +/** + * xmlValidateNameValue: + * @value: an Name value + * + * Validate that the given value match Name production + * + * returns 1 if valid or 0 otherwise + */ + +int +xmlValidateNameValue(const CHAR *value) { + const CHAR *cur; + + if (value == NULL) return(0); + cur = value; + + if (!IS_LETTER(*cur) && (*cur != '_') && + (*cur != ':')) { + return(0); + } + + while ((IS_LETTER(*cur)) || (IS_DIGIT(*cur)) || + (*cur == '.') || (*cur == '-') || + (*cur == '_') || (*cur == ':') || + (IS_COMBINING(*cur)) || + (IS_EXTENDER(*cur))) + cur++; + + if (*cur != 0) return(0); + + return(1); +} + +/** + * xmlValidateNamesValue: + * @value: an Names value + * + * Validate that the given value match Names production + * + * returns 1 if valid or 0 otherwise + */ + +int +xmlValidateNamesValue(const CHAR *value) { + const CHAR *cur; + + if (value == NULL) return(0); + cur = value; + + if (!IS_LETTER(*cur) && (*cur != '_') && + (*cur != ':')) { + return(0); + } + + while ((IS_LETTER(*cur)) || (IS_DIGIT(*cur)) || + (*cur == '.') || (*cur == '-') || + (*cur == '_') || (*cur == ':') || + (IS_COMBINING(*cur)) || + (IS_EXTENDER(*cur))) + cur++; + + while (IS_BLANK(*cur)) { + while (IS_BLANK(*cur)) cur++; + + if (!IS_LETTER(*cur) && (*cur != '_') && + (*cur != ':')) { + return(0); + } + + while ((IS_LETTER(*cur)) || (IS_DIGIT(*cur)) || + (*cur == '.') || (*cur == '-') || + (*cur == '_') || (*cur == ':') || + (IS_COMBINING(*cur)) || + (IS_EXTENDER(*cur))) + cur++; + } + + if (*cur != 0) return(0); + + return(1); +} + +/** + * xmlValidateNmtokenValue: + * @value: an Mntoken value + * + * Validate that the given value match Nmtoken production + * + * [ VC: Name Token ] + * + * returns 1 if valid or 0 otherwise + */ + +int +xmlValidateNmtokenValue(const CHAR *value) { + const CHAR *cur; + + if (value == NULL) return(0); + cur = value; + + if (!IS_LETTER(*cur) && !IS_DIGIT(*cur) && + (*cur != '.') && (*cur != '-') && + (*cur != '_') && (*cur != ':') && + (!IS_COMBINING(*cur)) && + (!IS_EXTENDER(*cur))) + return(0); + + while ((IS_LETTER(*cur)) || (IS_DIGIT(*cur)) || + (*cur == '.') || (*cur == '-') || + (*cur == '_') || (*cur == ':') || + (IS_COMBINING(*cur)) || + (IS_EXTENDER(*cur))) + cur++; + + if (*cur != 0) return(0); + + return(1); + return(1); +} + +/** + * xmlValidateNmtokensValue: + * @value: an Mntokens value + * + * Validate that the given value match Nmtokens production + * + * [ VC: Name Token ] + * + * returns 1 if valid or 0 otherwise + */ + +int +xmlValidateNmtokensValue(const CHAR *value) { + const CHAR *cur; + + if (value == NULL) return(0); + cur = value; + + if (!IS_LETTER(*cur) && !IS_DIGIT(*cur) && + (*cur != '.') && (*cur != '-') && + (*cur != '_') && (*cur != ':') && + (!IS_COMBINING(*cur)) && + (!IS_EXTENDER(*cur))) + return(0); + + while ((IS_LETTER(*cur)) || (IS_DIGIT(*cur)) || + (*cur == '.') || (*cur == '-') || + (*cur == '_') || (*cur == ':') || + (IS_COMBINING(*cur)) || + (IS_EXTENDER(*cur))) + cur++; + + while (IS_BLANK(*cur)) { + while (IS_BLANK(*cur)) cur++; + + if (!IS_LETTER(*cur) && !IS_DIGIT(*cur) && + (*cur != '.') && (*cur != '-') && + (*cur != '_') && (*cur != ':') && + (!IS_COMBINING(*cur)) && + (!IS_EXTENDER(*cur))) + return(0); + + while ((IS_LETTER(*cur)) || (IS_DIGIT(*cur)) || + (*cur == '.') || (*cur == '-') || + (*cur == '_') || (*cur == ':') || + (IS_COMBINING(*cur)) || + (IS_EXTENDER(*cur))) + cur++; + } + + if (*cur != 0) return(0); + + return(1); +} + +/** + * xmlValidateNotationDecl: + * @doc: a document instance + * @nota: a notation definition + * + * Try to validate a single notation definition + * basically it does the following checks as described by the + * XML-1.0 recommendation: + * - it seems that no validity constraing exist on notation declarations + * But this function get called anyway ... + * + * returns 1 if valid or 0 otherwise + */ + +int +xmlValidateNotationDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc, + xmlNotationPtr nota) { + int ret = 1; + + return(ret); +} + +/** + * xmlValidateAttributeValue: + * @type: an attribute type + * @value: an attribute value + * + * Validate that the given attribute value match the proper production + * + * [ VC: ID ] + * Values of type ID must match the Name production.... + * + * [ VC: IDREF ] + * Values of type IDREF must match the Name production, and values + * of type IDREFS must match Names ... + * + * [ VC: Entity Name ] + * Values of type ENTITY must match the Name production, values + * of type ENTITIES must match Names ... + * + * [ VC: Name Token ] + * Values of type NMTOKEN must match the Nmtoken production; values + * of type NMTOKENS must match Nmtokens. + * + * returns 1 if valid or 0 otherwise + */ + +int +xmlValidateAttributeValue(xmlAttributeType type, const CHAR *value) { + switch (type) { + case XML_ATTRIBUTE_IDREFS: + case XML_ATTRIBUTE_ENTITIES: + return(xmlValidateNamesValue(value)); + case XML_ATTRIBUTE_IDREF: + case XML_ATTRIBUTE_ID: + case XML_ATTRIBUTE_ENTITY: + case XML_ATTRIBUTE_NOTATION: + return(xmlValidateNameValue(value)); + case XML_ATTRIBUTE_NMTOKENS: + case XML_ATTRIBUTE_ENUMERATION: + return(xmlValidateNmtokensValue(value)); + case XML_ATTRIBUTE_NMTOKEN: + return(xmlValidateNmtokenValue(value)); + case XML_ATTRIBUTE_CDATA: + break; + } + return(1); +} + +/** + * xmlValidateAttributeDecl: + * @doc: a document instance + * @attr: an attribute definition + * + * Try to validate a single attribute definition + * basically it does the following checks as described by the + * XML-1.0 recommendation: + * - [ VC: Attribute Default Legal ] + * - [ VC: Enumeration ] + * - [ VC: ID Attribute Default ] + * + * The ID/IDREF uniqueness and matching are done separately + * + * returns 1 if valid or 0 otherwise + */ + +int +xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc, + xmlAttributePtr attr) { + int ret = 1; + int val; + CHECK_DTD; + if(attr == NULL) return(1); + + /* Attribute Default Legal */ + /* Enumeration */ + if (attr->defaultValue != NULL) { + val = xmlValidateAttributeValue(attr->type, attr->defaultValue); + if (val == 0) { + VERROR(ctxt->userData, + "Syntax of default value for attribute %s on %s is not valid\n", + attr->name, attr->elem); + } + ret &= val; + } + + /* ID Attribute Default */ + if ((attr->type == XML_ATTRIBUTE_ID)&& + (attr->def != XML_ATTRIBUTE_IMPLIED) && + (attr->def != XML_ATTRIBUTE_REQUIRED)) { + VERROR(ctxt->userData, + "ID attribute %s on %s is not valid must be #IMPLIED or #REQUIRED\n", + attr->name, attr->elem); + ret = 0; + } + + /* max ID per element */ + if ((attr->type == XML_ATTRIBUTE_ID) && (doc->extSubset != NULL)) { + int nbId = 0; + + /* the trick is taht we parse DtD as their own internal subset */ + xmlElementPtr elem = xmlGetDtdElementDesc(doc->extSubset, + attr->elem); + if (elem != NULL) { + nbId = xmlScanIDAttributeDecl(NULL, elem); + } + if (nbId >= 1) + VERROR(ctxt->userData, + "Element %s has ID attribute defined in the external subset : %s\n", + attr->elem, attr->name); + } + + return(ret); +} + +/** + * xmlValidateElementDecl: + * @ctxt: the validation context + * @doc: a document instance + * @elem: an element definition + * + * Try to validate a single element definition + * basically it does the following checks as described by the + * XML-1.0 recommendation: + * - [ VC: One ID per Element Type ] + * - [ VC: No Duplicate Types ] + * - [ VC: Unique Element Type Declaration ] + * + * returns 1 if valid or 0 otherwise + */ + +int +xmlValidateElementDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc, + xmlElementPtr elem) { + int ret = 1; + xmlElementPtr tst; + + CHECK_DTD; + + if (elem == NULL) return(1); + + /* No Duplicate Types */ + if (elem->type == XML_ELEMENT_TYPE_MIXED) { + xmlElementContentPtr cur, next; + const CHAR *name; + + cur = elem->content; + while (cur != NULL) { + if (cur->type != XML_ELEMENT_CONTENT_OR) break; + if (cur->c1 == NULL) break; + if (cur->c1->type == XML_ELEMENT_CONTENT_ELEMENT) { + name = cur->c1->name; + next = cur->c2; + while (next != NULL) { + if (next->type == XML_ELEMENT_CONTENT_ELEMENT) { + if (!xmlStrcmp(next->name, name)) { + VERROR(ctxt->userData, + "Definition of %s has duplicate references of %s\n", + elem->name, name); + ret = 0; + } + break; + } + if (next->c1 == NULL) break; + if (next->c1->type != XML_ELEMENT_CONTENT_ELEMENT) break; + if (!xmlStrcmp(next->c1->name, name)) { + VERROR(ctxt->userData, + "Definition of %s has duplicate references of %s\n", + elem->name, name); + ret = 0; + } + next = next->c2; + } + } + cur = cur->c2; + } + } + + /* VC: Unique Element Type Declaration */ + tst = xmlGetDtdElementDesc(doc->intSubset, elem->name); + if ((tst != NULL ) && (tst != elem)) { + VERROR(ctxt->userData, "Redefinition of element %s\n", + elem->name); + ret = 0; + } + tst = xmlGetDtdElementDesc(doc->extSubset, elem->name); + if ((tst != NULL ) && (tst != elem)) { + VERROR(ctxt->userData, "Redefinition of element %s\n", + elem->name); + ret = 0; + } + + /* One ID per Element Type */ + if (xmlScanIDAttributeDecl(ctxt, elem) > 1) { + ret = 0; + } + return(ret); +} + +/** + * xmlValidateOneAttribute: + * @ctxt: the validation context + * @doc: a document instance + * @elem: an element instance + * @attr: an attribute instance + * + * Try to validate a single attribute for an element + * basically it * does the following checks as described by the + * XML-1.0 recommendation: + * - [ VC: Attribute Value Type ] + * - [ VC: Fixed Attribute Default ] + * - [ VC: Entity Name ] + * - [ VC: Name Token ] + * - [ VC: ID ] + * - [ VC: IDREF ] + * - [ VC: Entity Name ] + * - [ VC: Notation Attributes ] + * + * The ID/IDREF uniqueness and matching are done separately + * + * returns 1 if valid or 0 otherwise + */ + +int +xmlValidateOneAttribute(xmlValidCtxtPtr ctxt, xmlDocPtr doc, + xmlNodePtr elem, xmlAttrPtr attr, const CHAR *value) { + xmlElementPtr elemDecl; + xmlAttributePtr attrDecl; + int val; + int ret = 1; + + CHECK_DTD; + if ((elem == NULL) || (elem->name == NULL)) return(0); + if ((attr == NULL) || (attr->name == NULL)) return(0); + + attrDecl = xmlGetDtdAttrDesc(doc->intSubset, elem->name, attr->name); + if ((attrDecl == NULL) && (doc->extSubset != NULL)) + attrDecl = xmlGetDtdAttrDesc(doc->extSubset, elem->name, attr->name); + + + /* Validity Constraint: Attribute Value Type */ + if (attrDecl == NULL) { + VERROR(ctxt->userData, + "No declaration for attribute %s on element %s\n", + attr->name, elem->name); + return(0); + } + val = xmlValidateAttributeValue(attrDecl->type, value); + if (val == 0) { + VERROR(ctxt->userData, + "Syntax of value for attribute %s on %s is not valid\n", + attr->name, elem->name); + ret = 0; + } + + /* Validity Constraint: Notation Attributes */ + if (attrDecl->type == XML_ATTRIBUTE_NOTATION) { + xmlEnumerationPtr tree = attrDecl->tree; + xmlNotationPtr nota; + + /* First check that the given NOTATION was declared */ + nota = xmlGetDtdNotationDesc(doc->intSubset, value); + if (nota == NULL) + nota = xmlGetDtdNotationDesc(doc->extSubset, value); + + if (nota == NULL) { + VERROR(ctxt->userData, + "Value \"%s\" for attribute %s on %s is not a declared Notation\n", + value, attr->name, elem->name); + ret = 0; + } + + /* Second, verify that it's among the list */ + while (tree != NULL) { + if (!xmlStrcmp(tree->name, value)) break; + tree = tree->next; + } + if (tree == NULL) { + VERROR(ctxt->userData, + "Value \"%s\" for attribute %s on %s is among the enumerated notations\n", + value, attr->name, elem->name); + ret = 0; + } + } + + /* Validity Constraint: Enumeration */ + if (attrDecl->type == XML_ATTRIBUTE_ENUMERATION) { + xmlEnumerationPtr tree = attrDecl->tree; + while (tree != NULL) { + if (!xmlStrcmp(tree->name, value)) break; + tree = tree->next; + } + if (tree == NULL) { + VERROR(ctxt->userData, + "Value \"%s\" for attribute %s on %s is among the enumerated set\n", + value, attr->name, elem->name); + ret = 0; + } + } + + /* Fixed Attribute Default */ + if ((attrDecl->def == XML_ATTRIBUTE_FIXED) && + (xmlStrcmp(attrDecl->defaultValue, value))) { + VERROR(ctxt->userData, + "Value for attribute %s on %s must be \"%s\"\n", + attr->name, elem->name, attrDecl->defaultValue); + ret = 0; + } + + elemDecl = xmlGetDtdElementDesc(doc->intSubset, elem->name); + if ((elemDecl == NULL) && (doc->extSubset != NULL)) + elemDecl = xmlGetDtdElementDesc(doc->extSubset, elem->name); + if (elemDecl == NULL) { + /* the error has or will be reported soon in xmlValidateOneElement */ + return(0); + } + return(ret); +} + +int xmlValidateElementTypeElement(xmlValidCtxtPtr ctxt, xmlNodePtr *child, + xmlElementContentPtr cont); + +/** + * xmlValidateElementTypeExpr: + * @ctxt: the validation context + * @child: pointer to the child list + * @cont: pointer to the content declaration + * + * Try to validate the content of an element of type element + * but don't handle the occurence factor + * + * returns 1 if valid or 0 and -1 if PCDATA stuff is found, + * also update child value in-situ. + */ + +int +xmlValidateElementTypeExpr(xmlValidCtxtPtr ctxt, xmlNodePtr *child, + xmlElementContentPtr cont) { + xmlNodePtr cur; + int ret = 1; + + if (cont == NULL) return(-1); + while (*child != NULL) { + if ((*child)->type == XML_PI_NODE) { + *child = (*child)->next; + continue; + } + if ((*child)->type == XML_COMMENT_NODE) { + *child = (*child)->next; + continue; + } + else if ((*child)->type != XML_ELEMENT_NODE) { + return(-1); + } + break; + } + switch (cont->type) { + case XML_ELEMENT_CONTENT_PCDATA: + /* Internal error !!! */ + fprintf(stderr, "Internal: MIXED struct bad\n"); + return(-1); + case XML_ELEMENT_CONTENT_ELEMENT: + if (*child == NULL) return(0); + ret = (!xmlStrcmp((*child)->name, cont->name)); + if (ret == 1) + *child = (*child)->next; + return(ret); + case XML_ELEMENT_CONTENT_OR: + cur = *child; + ret = xmlValidateElementTypeElement(ctxt, child, cont->c1); + if (ret == -1) return(-1); + if (ret == 1) { + return(1); + } + /* rollback and retry the other path */ + *child = cur; + ret = xmlValidateElementTypeElement(ctxt, child, cont->c2); + if (ret == -1) return(-1); + if (ret == 0) { + *child = cur; + return(0); + } + return(1); + case XML_ELEMENT_CONTENT_SEQ: + cur = *child; + ret = xmlValidateElementTypeElement(ctxt, child, cont->c1); + if (ret == -1) return(-1); + if (ret == 0) { + *child = cur; + return(0); + } + ret = xmlValidateElementTypeElement(ctxt, child, cont->c2); + if (ret == -1) return(-1); + if (ret == 0) { + *child = cur; + return(0); + } + return(1); + } + return(ret); +} + +/** + * xmlValidateElementTypeElement: + * @ctxt: the validation context + * @child: pointer to the child list + * @cont: pointer to the content declaration + * + * Try to validate the content of an element of type element + * yeah, Yet Another Regexp Implementation, and recursive + * + * returns 1 if valid or 0 and -1 if PCDATA stuff is found, + * also update child and content values in-situ. + */ + +int +xmlValidateElementTypeElement(xmlValidCtxtPtr ctxt, xmlNodePtr *child, + xmlElementContentPtr cont) { + xmlNodePtr cur; + int ret = 1; + + if (cont == NULL) return(-1); + while (*child != NULL) { + if ((*child)->type == XML_PI_NODE) { + *child = (*child)->next; + continue; + } + if ((*child)->type == XML_COMMENT_NODE) { + *child = (*child)->next; + continue; + } + else if ((*child)->type != XML_ELEMENT_NODE) { + return(-1); + } + break; + } + cur = *child; + ret = xmlValidateElementTypeExpr(ctxt, child, cont); + if (ret == -1) return(-1); + switch (cont->ocur) { + case XML_ELEMENT_CONTENT_ONCE: + if (ret == 1) { + return(1); + } + *child = cur; + return(0); + case XML_ELEMENT_CONTENT_OPT: + if (ret == 0) { + *child = cur; + return(1); + } + break; + case XML_ELEMENT_CONTENT_MULT: + if (ret == 0) { + *child = cur; + break; + } + /* no break on purpose */ + case XML_ELEMENT_CONTENT_PLUS: + if (ret == 0) { + *child = cur; + return(0); + } + do { + cur = *child; + ret = xmlValidateElementTypeExpr(ctxt, child, cont); + } while (ret == 1); + if (ret == -1) return(-1); + *child = cur; + break; + } + while (*child != NULL) { + if ((*child)->type == XML_PI_NODE) { + *child = (*child)->next; + continue; + } + if ((*child)->type == XML_COMMENT_NODE) { + *child = (*child)->next; + continue; + } + else if ((*child)->type != XML_ELEMENT_NODE) { + return(-1); + } + break; + } + return(1); +} + +/** + * xmlSprintfElementChilds: + * @buf: an output buffer + * @content: An element + * @glob: 1 if one must print the englobing parenthesis, 0 otherwise + * + * This will dump the list of childs to the buffer + * Intended just for the debug routine + */ +void +xmlSprintfElementChilds(char *buf, xmlNodePtr node, int glob) { + xmlNodePtr cur; + + if (node == NULL) return; + if (glob) strcat(buf, "("); + cur = node->childs; + while (cur != NULL) { + switch (cur->type) { + case XML_ELEMENT_NODE: + strcat(buf, cur->name); + if (cur->next != NULL) + strcat(buf, " "); + break; + case XML_TEXT_NODE: + case XML_CDATA_SECTION_NODE: + case XML_ENTITY_REF_NODE: + strcat(buf, "CDATA"); + if (cur->next != NULL) + strcat(buf, " "); + break; + case XML_ATTRIBUTE_NODE: + case XML_DOCUMENT_NODE: + case XML_DOCUMENT_TYPE_NODE: + case XML_DOCUMENT_FRAG_NODE: + case XML_NOTATION_NODE: + strcat(buf, "???"); + if (cur->next != NULL) + strcat(buf, " "); + break; + case XML_ENTITY_NODE: + case XML_PI_NODE: + case XML_COMMENT_NODE: + break; + } + cur = cur->next; + } + if (glob) strcat(buf, ")"); +} + + +/** + * xmlValidateOneElement: + * @ctxt: the validation context + * @doc: a document instance + * @elem: an element instance + * + * Try to validate a single element and it's attributes, + * basically it does the following checks as described by the + * XML-1.0 recommendation: + * - [ VC: Element Valid ] + * - [ VC: Required Attribute ] + * Then call xmlValidateOneAttribute() for each attribute present. + * + * The ID/IDREF checkings are done separately + * + * returns 1 if valid or 0 otherwise + */ + +int +xmlValidateOneElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc, + xmlNodePtr elem) { + xmlElementPtr elemDecl; + xmlElementContentPtr cont; + xmlNodePtr child; + int ret = 1; + const CHAR *name; + + CHECK_DTD; + + if ((elem == NULL) || (elem->name == NULL)) return(0); + + elemDecl = xmlGetDtdElementDesc(doc->intSubset, elem->name); + if ((elemDecl == NULL) && (doc->extSubset != NULL)) + elemDecl = xmlGetDtdElementDesc(doc->extSubset, elem->name); + if (elemDecl == NULL) { + VERROR(ctxt->userData, "No declaration for element %s\n", + elem->name); + return(0); + } + + /* Check taht the element content matches the definition */ + switch (elemDecl->type) { + case XML_ELEMENT_TYPE_EMPTY: + if (elem->childs != NULL) { + VERROR(ctxt->userData, + "Element %s was declared EMPTY this one has content\n", + elem->name); + ret = 0; + } + break; + case XML_ELEMENT_TYPE_ANY: + /* I don't think anything is required then */ + break; + case XML_ELEMENT_TYPE_MIXED: + /* Hum, this start to get messy */ + child = elem->childs; + while (child != NULL) { + if (child->type == XML_ELEMENT_NODE) { + name = child->name; + cont = elemDecl->content; + while (cont != NULL) { + if (cont->type == XML_ELEMENT_CONTENT_ELEMENT) { + if (!xmlStrcmp(cont->name, name)) break; + } else if ((cont->type == XML_ELEMENT_CONTENT_OR) && + (cont->c1 != NULL) && + (cont->c1->type == XML_ELEMENT_CONTENT_ELEMENT)) { + if (!xmlStrcmp(cont->c1->name, name)) break; + } else if ((cont->type != XML_ELEMENT_CONTENT_OR) || + (cont->c1 == NULL) || + (cont->c1->type != XML_ELEMENT_CONTENT_PCDATA)) { + /* Internal error !!! */ + fprintf(stderr, "Internal: MIXED struct bad\n"); + break; + } + cont = cont->c2; + } + if (cont == NULL) { + VERROR(ctxt->userData, + "Element %s is not declared in %s list of possible childs\n", + name, elem->name); + ret = 0; + } + } + child = child->next; + } + break; + case XML_ELEMENT_TYPE_ELEMENT: + child = elem->childs; + cont = elemDecl->content; + ret = xmlValidateElementTypeElement(ctxt, &child, cont); + if ((ret == 0) || (child != NULL)) { + char expr[1000]; + char list[2000]; + + expr[0] = 0; + xmlSprintfElementContent(expr, cont, 1); + list[0] = 0; + xmlSprintfElementChilds(list, elem, 1); + + VERROR(ctxt->userData, + "Element %s content doesn't follow the Dtd\nExpecting %s, got %s\n", + elem->name, expr, list); + ret = 0; + } + break; + } + + return(ret); +} + +/** + * xmlValidateRoot: + * @ctxt: the validation context + * @doc: a document instance + * + * Try to validate a the root element + * basically it does the following check as described by the + * XML-1.0 recommendation: + * - [ VC: Root Element Type ] + * it doesn't try to recurse or apply other check to the element + * + * returns 1 if valid or 0 otherwise + */ + +int +xmlValidateRoot(xmlValidCtxtPtr ctxt, xmlDocPtr doc) { + if (doc == NULL) return(0); + + if ((doc->intSubset == NULL) || + (doc->intSubset->name == NULL)) { + VERROR(ctxt->userData, "Not valid: no DtD found\n"); + return(0); + } + if ((doc->root == NULL) || (doc->root->name == NULL)) { + VERROR(ctxt->userData, "Not valid: no root element\n"); + return(0); + } + if (xmlStrcmp(doc->intSubset->name, doc->root->name)) { + VERROR(ctxt->userData, + "Not valid: root and DtD name do not match %s and %s\n", + doc->root->name, doc->intSubset->name); + return(0); + } + return(1); +} + + +/** + * xmlValidateElement: + * @ctxt: the validation context + * @doc: a document instance + * @elem: an element instance + * + * Try to validate the subtree under an element + * + * returns 1 if valid or 0 otherwise + */ + +int +xmlValidateElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc, xmlNodePtr elem) { + CHECK_DTD; + + return(1); +} + +/** + * xmlValidateDtd: + * @ctxt: the validation context + * @doc: a document instance + * @dtd: a dtd instance + * + * Try to validate the dtd instance + * + * basically it does check all the definitions in the DtD. + * + * returns 1 if valid or 0 otherwise + */ + +int +xmlValidateDtd(xmlValidCtxtPtr ctxt, xmlDocPtr doc, xmlDtdPtr dtd) { + return(1); +} + +/** + * xmlValidateDocument: + * @ctxt: the validation context + * @doc: a document instance + * + * Try to validate the document instance + * + * basically it does the all the checks described by the + * i.e. validates the internal and external subset (if present) + * and validate the document tree. + * + * returns 1 if valid or 0 otherwise + */ + +int +xmlValidateDocument(xmlValidCtxtPtr ctxt, xmlDocPtr doc) { + if (!xmlValidateRoot(ctxt, doc)) return(0); + + return(1); +} + diff --git a/valid.h b/valid.h index 084d97fa..7d58459e 100644 --- a/valid.h +++ b/valid.h @@ -11,6 +11,22 @@ #define __XML_VALID_H__ #include "tree.h" +/** + * an xmlValidCtxt is used for error reporting when validating + */ + +typedef void (*xmlValidityErrorFunc) (void *ctx, const char *msg, ...); +typedef void (*xmlValidityWarningFunc) (void *ctx, const char *msg, ...); + +typedef struct xmlValidCtxt { + void *userData; /* user specific data block */ + xmlValidityErrorFunc error; /* the callback in case of errors */ + xmlValidityWarningFunc warning; /* the callback in case of warning */ +} xmlValidCtxt, *xmlValidCtxtPtr; + +extern void xmlParserValidityError(void *ctx, const char *msg, ...); +extern void xmlParserValidityWarning(void *ctx, const char *msg, ...); + /* * ALl notation declarations are stored in a table * there is one table per DTD @@ -21,7 +37,7 @@ typedef struct xmlNotationTable { int nb_notations; /* number of notations stored */ int max_notations; /* maximum number of notations */ - xmlNotationPtr table; /* the table of attributes */ + xmlNotationPtr *table; /* the table of attributes */ } xmlNotationTable; typedef xmlNotationTable *xmlNotationTablePtr; @@ -35,7 +51,7 @@ typedef xmlNotationTable *xmlNotationTablePtr; typedef struct xmlElementTable { int nb_elements; /* number of elements stored */ int max_elements; /* maximum number of elements */ - xmlElementPtr table; /* the table of elements */ + xmlElementPtr *table; /* the table of elements */ } xmlElementTable; typedef xmlElementTable *xmlElementTablePtr; @@ -49,13 +65,13 @@ typedef xmlElementTable *xmlElementTablePtr; typedef struct xmlAttributeTable { int nb_attributes; /* number of attributes stored */ int max_attributes; /* maximum number of attributes */ - xmlAttributePtr table; /* the table of attributes */ + xmlAttributePtr *table; /* the table of attributes */ } xmlAttributeTable; typedef xmlAttributeTable *xmlAttributeTablePtr; /* Notation */ -xmlNotationPtr xmlAddNotationDecl(xmlDtdPtr dtd, const CHAR *name, - const CHAR *PublicID, const CHAR *SystemID); +xmlNotationPtr xmlAddNotationDecl(xmlValidCtxtPtr ctxt, xmlDtdPtr dtd, + const CHAR *name, const CHAR *PublicID, const CHAR *SystemID); xmlNotationTablePtr xmlCopyNotationTable(xmlNotationTablePtr table); void xmlFreeNotationTable(xmlNotationTablePtr table); void xmlDumpNotationTable(xmlBufferPtr buf, xmlNotationTablePtr table); @@ -66,8 +82,8 @@ xmlElementContentPtr xmlCopyElementContent(xmlElementContentPtr content); void xmlFreeElementContent(xmlElementContentPtr cur); /* Element */ -xmlElementPtr xmlAddElementDecl(xmlDtdPtr dtd, const CHAR *name, int type, - xmlElementContentPtr content); +xmlElementPtr xmlAddElementDecl(xmlValidCtxtPtr ctxt, xmlDtdPtr dtd, + const CHAR *name, int type, xmlElementContentPtr content); xmlElementTablePtr xmlCopyElementTable(xmlElementTablePtr table); void xmlFreeElementTable(xmlElementTablePtr table); void xmlDumpElementTable(xmlBufferPtr buf, xmlElementTablePtr table); @@ -78,11 +94,32 @@ void xmlFreeEnumeration(xmlEnumerationPtr cur); xmlEnumerationPtr xmlCopyEnumeration(xmlEnumerationPtr cur); /* Attribute */ -xmlAttributePtr xmlAddAttributeDecl(xmlDtdPtr dtd, const CHAR *elem, - const CHAR *name, int type, int def, +xmlAttributePtr xmlAddAttributeDecl(xmlValidCtxtPtr ctxt, xmlDtdPtr dtd, + const CHAR *elem, const CHAR *name, int type, int def, const CHAR *defaultValue, xmlEnumerationPtr tree); xmlAttributeTablePtr xmlCopyAttributeTable(xmlAttributeTablePtr table); void xmlFreeAttributeTable(xmlAttributeTablePtr table); void xmlDumpAttributeTable(xmlBufferPtr buf, xmlAttributeTablePtr table); +/** + * The public function calls related to validity checking + */ + +int xmlValidateRoot(xmlValidCtxtPtr ctxt, xmlDocPtr doc); +int xmlValidateElementDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc, + xmlElementPtr elem); +int xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc, + xmlAttributePtr attr); +int xmlValidateNotationDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc, + xmlNotationPtr nota); +int xmlValidateDtd(xmlValidCtxtPtr ctxt, xmlDocPtr doc, xmlDtdPtr dtd); + +int xmlValidateDocument(xmlValidCtxtPtr ctxt, xmlDocPtr doc); +int xmlValidateElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc, xmlNodePtr elem); +int xmlValidateOneElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc, + xmlNodePtr elem); +int xmlValidateOneAttribute(xmlValidCtxtPtr ctxt, xmlDocPtr doc, + xmlNodePtr elem, xmlAttrPtr attr, const CHAR *value); + +int xmlIsMixedElement(xmlDocPtr doc, const CHAR *name); #endif /* __XML_VALID_H__ */ diff --git a/xmlIO.c b/xmlIO.c index 7df18eb3..d25a07b0 100644 --- a/xmlIO.c +++ b/xmlIO.c @@ -6,6 +6,10 @@ * Daniel.Veillard@w3.org */ +/* + * TODO: plug-in a generic transfer library, like libwww if available + */ + #include "config.h" #include @@ -18,6 +22,7 @@ #ifdef HAVE_ZLIB_H #include #endif +#include #include "xmlIO.h" @@ -319,3 +324,43 @@ xmlParserInputBufferRead(xmlParserInputBufferPtr in, int len) { return(xmlParserInputBufferGrow(in, len)); } +/* + * xmlParserGetDirectory: + * @filename: the path to a file + * + * lookup the directory for that file + * + * Returns a new allocated string containing the directory, or NULL. + */ +char * +xmlParserGetDirectory(const char *filename) { + char *ret = NULL; + char dir[1024]; + char *cur; + char sep = '/'; + + if (filename == NULL) return(NULL); +#ifdef WIN32 + sep = '\\'; +#endif + + strncpy(dir, filename, 1023); + dir[1023] = 0; + cur = &dir[strlen(dir)]; + while (cur > dir) { + if (*cur == sep) break; + cur --; + } + if (*cur == sep) { + if (cur == dir) dir[1] = 0; + else *cur = 0; + ret = strdup(dir); + } else { + if (getcwd(dir, 1024) != NULL) { + dir[1023] = 0; + ret = strdup(dir); + } + } + return(ret); +} + diff --git a/xmlIO.h b/xmlIO.h index bdeecc3f..0e086d77 100644 --- a/xmlIO.h +++ b/xmlIO.h @@ -45,6 +45,7 @@ int xmlParserInputBufferRead(xmlParserInputBufferPtr in, int len); int xmlParserInputBufferGrow(xmlParserInputBufferPtr in, int len); void xmlFreeParserInputBuffer(xmlParserInputBufferPtr in); +char *xmlParserGetDirectory(const char *filename); #ifdef __cplusplus } diff --git a/xpath.c b/xpath.c index 33c13f04..172dd5c4 100644 --- a/xpath.c +++ b/xpath.c @@ -13,17 +13,25 @@ * Author: Daniel.Veillard@w3.org */ +#include #include +#ifdef HAVE_MATH_H #include +#endif +#ifdef HAVE_MATH_H +#include +#endif +#ifdef HAVE_IEEEFP_H +#include +#endif +#ifdef HAVE_NAN_H +#include +#endif #include #include "tree.h" #include "xpath.h" #include "parserInternals.h" -/* - * TODO: create a pseudo document element and affect it as the - * actual root. - */ /* * Setup stuff for floating point */ @@ -31,6 +39,70 @@ double xmlXPathNAN = 0; double xmlXPathPINF = 1; double xmlXPathMINF = -1; +#ifndef isinf +#ifndef HAVE_ISINF + +#if HAVE_FPCLASS + +int isinf(double d) { + fpclass_t type = fpclass(d); + switch (type) { + case FP_NINF: + return(-1); + case FP_PINF: + return(1); + default: + return(0); + } + return(0); +} + +#elif defined(HAVE_FP_CLASS) || defined(HAVE_FP_CLASS_D) + +#if HAVE_FP_CLASS_H +#include +#endif + +int isinf(double d) { +#if HAVE_FP_CLASS + int fpclass = fp_class(d); +#else + int fpclass = fp_class_d(d); +#endif + if (fpclass == FP_POS_INF) + return(1); + if (fpclass == FP_NEG_INF) + return(-1); + return(0); +} + +#elif defined(HAVE_CLASS) + +int isinf(double d) { + int fpclass = class(d); + if (fpclass == FP_PLUS_INF) + return(1); + if (fpclass == FP_MINUS_INF) + return(-1); + return(0); +} +#elif defined(finite) || defined(HAVE_FINITE) +int isinf(double x) { return !finite(x) && x==x; } +#endif /* ! HAVE_FPCLASS */ + +#endif /* ! HAVE_ISINF */ +#endif /* ! defined(isinf) */ + +#ifndef isnan +#ifndef HAVE_ISNAN + +#ifdef HAVE_ISNAND +#define isnan(f) isnand(f) +#endif /* HAVE_iSNAND */ + +#endif /* ! HAVE_iSNAN */ +#endif /* ! defined(isnan) */ + /** * xmlXPathInit: * @@ -87,7 +159,7 @@ extern int name##Push(xmlXPathParserContextPtr ctxt, type value) { \ ctxt->name##Tab = (void *) realloc(ctxt->name##Tab, \ ctxt->name##Max * sizeof(ctxt->name##Tab[0])); \ if (ctxt->name##Tab == NULL) { \ - fprintf(xmlXPathDebug, "realloc failed !\n"); \ + fprintf(xmlXPathDebug, "realloc failed !\n"); \ exit(1); \ } \ } \ @@ -458,7 +530,9 @@ xmlXPathDebugNodeSet(FILE *output, xmlNodeSetPtr obj) { fprintf(output, " NULL !\n"); return; } - if (obj->nodeTab[i]->name == NULL) + if (obj->nodeTab[i]->type == XML_DOCUMENT_NODE) + fprintf(output, " /"); + else if (obj->nodeTab[i]->name == NULL) fprintf(output, " noname!"); else fprintf(output, " %s", obj->nodeTab[i]->name); } @@ -866,8 +940,6 @@ xmlXPathEqualValues(xmlXPathObjectPtr arg1, xmlXPathObjectPtr arg2) { * xmlXPathCompareValues: * @inf: less than (1) or greater than (2) * @strict: is the comparison strict - * @arg1: first XPath object argument - * @arg2: second XPath object argument * * Implement the compare operation on XPath objects: * @arg1 < @arg2 (1, 1, ... @@ -875,11 +947,9 @@ xmlXPathEqualValues(xmlXPathObjectPtr arg1, xmlXPathObjectPtr arg2) { * @arg1 > @arg2 (0, 1, ... * @arg1 >= @arg2 (0, 0, ... * - * Returns 0 or 1 depending on the results of the test. */ int -xmlXPathCompareValues(int inf, int strict, xmlXPathObjectPtr arg1, - xmlXPathObjectPtr arg2) { +xmlXPathCompareValues(int inf, int strict) { TODO /* compare */ return(0); } @@ -1064,8 +1134,13 @@ xmlXPathNextSelf(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { */ xmlNodePtr xmlXPathNextChild(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { - if (cur == NULL) + if (cur == NULL) { + if (ctxt->context->node == (xmlNodePtr) ctxt->context->doc) + return(ctxt->context->doc->root); return(ctxt->context->node->childs); + } + if (ctxt->context->node->type == XML_DOCUMENT_NODE) + return(NULL); return(cur->next); } @@ -1080,8 +1155,11 @@ xmlXPathNextChild(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { */ xmlNodePtr xmlXPathNextDescendant(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { - if (cur == NULL) + if (cur == NULL) { + if (ctxt->context->node == (xmlNodePtr) ctxt->context->doc) + return(ctxt->context->doc->root); return(ctxt->context->node->childs); + } if (cur->childs != NULL) return(cur->childs); if (cur->next != NULL) return(cur->next); @@ -1114,6 +1192,8 @@ xmlXPathNextDescendantOrSelf(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { if (cur == NULL) return(ctxt->context->node); + if (cur == (xmlNodePtr) ctxt->context->doc) + return(ctxt->context->doc->root); if (cur->childs != NULL) return(cur->childs); if (cur->next != NULL) return(cur->next); @@ -1144,8 +1224,11 @@ xmlXPathNextParent(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { * the parent of an attribute or namespace node is the element * to which the attribute or namespace node is attached */ - if (cur == NULL) + if (cur == NULL) { + if (ctxt->context->node->parent == NULL) + return((xmlNodePtr) ctxt->context->doc); return(ctxt->context->node->parent); + } return(NULL); } @@ -1168,9 +1251,15 @@ xmlXPathNextAncestor(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { * the parent of an attribute or namespace node is the element * to which the attribute or namespace node is attached */ - if (cur == NULL) + if (cur == NULL) { + if (ctxt->context->node->parent == NULL) + return((xmlNodePtr) ctxt->context->doc); return(ctxt->context->node->parent); - if (cur == ctxt->context->doc->root) return(NULL); + } + if (cur == ctxt->context->doc->root) + return((xmlNodePtr) ctxt->context->doc); + if (cur == (xmlNodePtr) ctxt->context->doc) + return(NULL); return(cur->parent); } @@ -1194,7 +1283,10 @@ xmlXPathNextAncestorOrSelf(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { */ if (cur == NULL) return(ctxt->context->node); - if (cur == ctxt->context->doc->root) return(NULL); + if (cur == ctxt->context->doc->root) + return((xmlNodePtr) ctxt->context->doc); + if (cur == (xmlNodePtr) ctxt->context->doc) + return(NULL); return(cur->parent); } @@ -1209,6 +1301,8 @@ xmlXPathNextAncestorOrSelf(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { */ xmlNodePtr xmlXPathNextFollowingSibling(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { + if (cur == (xmlNodePtr) ctxt->context->doc) + return(NULL); if (cur == NULL) return(ctxt->context->node->next); return(cur->next); @@ -1226,6 +1320,8 @@ xmlXPathNextFollowingSibling(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { */ xmlNodePtr xmlXPathNextPrecedingSibling(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { + if (cur == (xmlNodePtr) ctxt->context->doc) + return(NULL); if (cur == NULL) return(ctxt->context->node->prev); return(cur->prev); @@ -1244,6 +1340,8 @@ xmlXPathNextPrecedingSibling(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { */ xmlNodePtr xmlXPathNextFollowing(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { + if (cur == (xmlNodePtr) ctxt->context->doc) + return(NULL); if (cur == NULL) return(ctxt->context->node->next);; /* !!!!!!!!! */ if (cur->childs != NULL) return(cur->childs); @@ -1274,6 +1372,8 @@ xmlXPathNextFollowing(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { */ xmlNodePtr xmlXPathNextPreceding(xmlXPathParserContextPtr ctxt, xmlNodePtr cur) { + if (cur == (xmlNodePtr) ctxt->context->doc) + return(NULL); if (cur == NULL) return(ctxt->context->node->prev); /* !!!!!!!!! */ if (cur->last != NULL) return(cur->last); @@ -1515,14 +1615,19 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt, int axis, TODO /* NS search */ break; case NODE_TEST_NAME: - if (!xmlStrcmp(name, cur->name) && - (((prefix == NULL) || - ((cur->ns != NULL) && - (!xmlStrcmp(prefix, cur->ns->href)))))) { + switch (cur->type) { + case XML_ELEMENT_NODE: + if (!xmlStrcmp(name, cur->name) && + (((prefix == NULL) || + ((cur->ns != NULL) && + (!xmlStrcmp(prefix, cur->ns->href)))))) { #ifdef DEBUG_STEP - n++; + n++; #endif - xmlXPathNodeSetAdd(ret, cur); + xmlXPathNodeSetAdd(ret, cur); + } + default: + break; } break; @@ -1553,8 +1658,8 @@ void xmlXPathRoot(xmlXPathParserContextPtr ctxt) { if (ctxt->context->nodelist != NULL) xmlXPathFreeNodeSet(ctxt->context->nodelist); - ctxt->context->node = ctxt->context->doc->root; - ctxt->context->nodelist = xmlXPathNodeSetCreate(ctxt->context->doc->root); + ctxt->context->node = (xmlNodePtr) ctxt->context->doc; + ctxt->context->nodelist = xmlXPathNodeSetCreate(ctxt->context->node); } /** @@ -3125,8 +3230,7 @@ xmlXPathEvalRelationalExpr(xmlXPathParserContextPtr ctxt) { (CUR == '>') || ((CUR == '<') && (NXT(1) == '=')) || ((CUR == '>') && (NXT(1) == '='))) { - xmlXPathObjectPtr arg1, arg2, res; - int inf, strict, equal; + int inf, strict; if (CUR == '<') inf = 1; else inf = 0; @@ -3136,13 +3240,7 @@ xmlXPathEvalRelationalExpr(xmlXPathParserContextPtr ctxt) { if (!strict) NEXT; xmlXPathEvalAdditiveExpr(ctxt); CHECK_ERROR; - arg2 = valuePop(ctxt); - arg1 = valuePop(ctxt); - equal = xmlXPathCompareValues(inf, strict, arg1, arg2); - res = xmlXPathNewBoolean(equal); - valuePush(ctxt, res); - xmlXPathFreeObject(arg1); - xmlXPathFreeObject(arg2); + xmlXPathCompareValues(inf, strict); } } @@ -3460,6 +3558,55 @@ xmlXPathEvalBasis(xmlXPathParserContextPtr ctxt) { if (name != NULL) free(name); name = xmlXPathParseQName(ctxt, &prefix); + if (name == NULL) { + ERROR(XPATH_EXPR_ERROR); + } + type = xmlXPathGetNameType(ctxt, name); + switch (type) { + /* + * Simple case: no axis seach all given node types. + */ + case NODE_TYPE_COMMENT: + if ((CUR != '(') || (NXT(1) != ')')) break; + SKIP(2); + nodetest = NODE_TEST_TYPE; + nodetype = XML_COMMENT_NODE; + goto search_nodes; + case NODE_TYPE_TEXT: + if ((CUR != '(') || (NXT(1) != ')')) break; + SKIP(2); + nodetest = NODE_TEST_TYPE; + nodetype = XML_TEXT_NODE; + goto search_nodes; + case NODE_TYPE_NODE: + if ((CUR != '(') || (NXT(1) != ')')) { + nodetest = NODE_TEST_NAME; + break; + } + SKIP(2); + nodetest = NODE_TEST_TYPE; + nodetype = XML_ELEMENT_NODE; + goto search_nodes; + case NODE_TYPE_PI: + if (CUR != '(') break; + if (NXT(1) != ')') { + /* + * Specific case: search a PI by name. + */ + SKIP(2); + nodetest = NODE_TEST_PI; + xmlXPathEvalLiteral(ctxt); + CHECK_ERROR; + if (CUR != ')') + ERROR(XPATH_UNCLOSED_ERROR); + xmlXPathSearchPI(ctxt, 0); + return; + } + SKIP(2); + nodetest = NODE_TEST_TYPE; + nodetype = XML_PI_NODE; + goto search_nodes; + } nodetest = NODE_TEST_NAME; } } else if ((CUR == ':') && (nodetest == NODE_TEST_NAME)) { @@ -3618,7 +3765,8 @@ xmlXPathEvalLocationPath(xmlXPathParserContextPtr ctxt) { } else if (CUR == '/') { NEXT; xmlXPathRoot(ctxt); - xmlXPathEvalRelativeLocationPath(ctxt); + if (CUR != 0) + xmlXPathEvalRelativeLocationPath(ctxt); } else { xmlXPathEvalRelativeLocationPath(ctxt); }