⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlparser.cc

📁 XMDS is a code generator that integrates equations. You write them down in human readable form in a
💻 CC
📖 第 1 页 / 共 5 页
字号:
  // store last position in this and all parent streams  storeStreamPos(lastXMLEntityStreamStack,lastStreamsPosition);  // need to get length and expand general entity  // and character references as we go  long length=sweepContent(0);  // now restore last position for this and all parent streams  restoreStreamPos(lastXMLEntityStreamStack,lastStreamsPosition);  if(length==0) {    return 0;  }  char* s=new char[length+1];  sweepContent(s);  XMLString CharData=s;  delete s;  Node* newTextNode = theDocument->createTextNode(CharData);  containingElement->appendChild(newTextNode);  if(DEBUGXMLPARSER) {    printf("CharData = '%s'\n",CharData.c_str());  }  return 1;};// ******************************************************************************bool XMLParser::matchProduction15Comment(					 Element* containingElement) {  // this production is optional  if(DEBUGXMLPARSER) {    printf("XMLParser::matchProduction15Comment\n");  }  if(!matchProductionFixedString((*XMLEntityStreamStack.begin()),"<!--")) {    return 0;  }  StreamPositionStruct lastStreamPos = (*XMLEntityStreamStack.begin())->streamPos;  XMLString Comment;  long length = howFarTo("--");  (*XMLEntityStreamStack.begin())->streamPos = lastStreamPos;  loadNChar((*XMLEntityStreamStack.begin()),Comment,length);  if(!matchProductionFixedString((*XMLEntityStreamStack.begin()),"-->")) {    // comment incorrectly terminated    throw XMLParserException(&XMLEntityStreamStack,"'-->' expected",XMLParserException::BAD_XML_ERR);  }  if(!(containingElement==0)) {    Node* newCommentNode = theDocument->createComment(Comment);    containingElement->appendChild(newCommentNode);  }  if(DEBUGXMLPARSER) {    printf("Comment = '%s'\n",Comment.c_str());  }  return 1;};// ******************************************************************************bool XMLParser::matchProduction16PI(				    Element* containingElement) {  // this production is optional  if(DEBUGXMLPARSER) {    printf("XMLParser::matchProduction16PI\n");  }  if(!matchProductionFixedString((*XMLEntityStreamStack.begin()),"<?")) {    return 0;  }  XMLString PITarget;  XMLString PIString;  matchProduction17PITarget(PITarget);  if(PITarget.eqxml()) {    (*XMLEntityStreamStack.begin())->streamPos.columnNumber -= PITarget.length();    throw XMLParserException(&XMLEntityStreamStack,			     "illegal processing instruction target name",			     XMLParserException::BAD_XML_ERR);  }  StreamPositionStruct lastStreamPos1 = (*XMLEntityStreamStack.begin())->streamPos;  long whiteSpace=matchProduction03S((*XMLEntityStreamStack.begin()),0);  StreamPositionStruct lastStreamPos2 = (*XMLEntityStreamStack.begin())->streamPos;  long length = howFarTo("?>");  if((length>0)&(whiteSpace==0)) {    (*XMLEntityStreamStack.begin())->streamPos = lastStreamPos1;    throw XMLParserException(&XMLEntityStreamStack,"white space expected",XMLParserException::BAD_XML_ERR);  }  (*XMLEntityStreamStack.begin())->streamPos = lastStreamPos2;  loadNChar((*XMLEntityStreamStack.begin()),PIString,length);  if(!(containingElement==0)) {    Node* newProcessingInstructionNode =      theDocument->createProcessingInstruction(PITarget,PIString);    containingElement->appendChild(newProcessingInstructionNode);  }  if(DEBUGXMLPARSER) {    printf("PITarget = '%s'\n",PITarget.c_str());    printf("PIString = '%s'\n",PIString.c_str());  }  // skip the '?>'  (*XMLEntityStreamStack.begin())->streamPos.count += 2;  (*XMLEntityStreamStack.begin())->streamPos.columnNumber += 2;  return 1;};// ******************************************************************************void XMLParser::matchProduction17PITarget(					  XMLString& PITarget) {  // this production is required  if(DEBUGXMLPARSER) {    printf("XMLParser::matchProduction17PITarget\n");  }  matchProduction05Name((*XMLEntityStreamStack.begin()),PITarget);};// ******************************************************************************bool XMLParser::matchProduction18CDSect(					Element* containingElement) {  // this production is optional  if(DEBUGXMLPARSER) {    printf("XMLParser::matchProduction18CDSect\n");  }  if(!matchProduction19CDStart()) {    return 0;  }  // critical point  XMLString CData;  matchProduction20CData(CData);  matchProduction21CDEnd();  Node* newCDATASectionNode = theDocument->createCDATASection(CData);  containingElement->appendChild(newCDATASectionNode);  return 1;};// ******************************************************************************bool XMLParser::matchProduction19CDStart() {  // this production is optional  if(DEBUGXMLPARSER) {    printf("XMLParser::matchProduction19CDStart\n");  }  return(matchProductionFixedString((*XMLEntityStreamStack.begin()),"<![CDATA["));};// ******************************************************************************bool XMLParser::matchProduction20CData(				       XMLString& CData) {  // this production is required  if(DEBUGXMLPARSER) {    printf("XMLParser::matchProduction20CData\n");  }  StreamPositionStruct lastStreamPos = (*XMLEntityStreamStack.begin())->streamPos;  long length = howFarTo("]]>");  (*XMLEntityStreamStack.begin())->streamPos = lastStreamPos;  loadNChar((*XMLEntityStreamStack.begin()),CData,length);  if(DEBUGXMLPARSER) {    printf("CData = '%s'\n",CData.c_str());  }  return 1;};// ******************************************************************************bool XMLParser::matchProduction21CDEnd() {  // this production is required  if(DEBUGXMLPARSER) {    printf("XMLParser::matchProduction21CDEnd\n");  }  return(matchProductionFixedString((*XMLEntityStreamStack.begin()),"]]>"));};// ******************************************************************************void XMLParser::matchProduction22Prolog() {  // this production is required  // note, however, that all of its sub-productions are optional  if(DEBUGXMLPARSER) {    printf("XMLParser::matchProduction22Prolog\n");  }  matchProduction23XMLDecl();  while(matchProduction27Misc(0)); // again, what is this doing?? PTC  matchProduction28doctypedecl();  if(!(theDocumentType==0)) {    while(matchProduction27Misc(0)); // and again... PTC  }};// ******************************************************************************bool XMLParser::matchProduction23XMLDecl() {  // this production is optional  if(DEBUGXMLPARSER) {    printf("XMLParser::matchProduction23XMLDecl\n");  }  StreamPositionStruct lastStreamPos = (*XMLEntityStreamStack.begin())->streamPos;  if(!matchProductionFixedString((*XMLEntityStreamStack.begin()),"<?xml")) {    return 0;  }  if(matchProduction03S((*XMLEntityStreamStack.begin()),0)==0) {    // no following white space => not an XMLDecl => back out    (*XMLEntityStreamStack.begin())->streamPos = lastStreamPos;    return 0;  }  // critical point  XMLString tempString;  if(matchProduction24VersionInfo((*XMLEntityStreamStack.begin()),tempString)) {    rootVersionNum=tempString;  }  { if(matchProduction80EncodingDecl((*XMLEntityStreamStack.begin()),tempString))    rootEncName=tempString;  }  matchProduction32SDDecl();  matchProduction03S((*XMLEntityStreamStack.begin()),0);  if(!matchProductionFixedString((*XMLEntityStreamStack.begin()),"?>")) {    // XMLDecl incorrectly terminated    throw XMLParserException(&XMLEntityStreamStack,"'?>' expected",XMLParserException::BAD_XML_ERR);  }  return 0;};// ******************************************************************************bool XMLParser::matchProduction24VersionInfo(					     XMLEntityStream *const thisStream,					     XMLString& VersionNum) {  // this production is required  if(DEBUGXMLPARSER) {    printf("XMLParser::matchProduction24VersionInfo\n");  }  if(!matchProductionFixedString(thisStream,"version")) {    throw XMLParserException(&XMLEntityStreamStack,"'version' expected",XMLParserException::BAD_XML_ERR);  }  matchProduction25Eq(thisStream);  matchProductionQuotedString(thisStream,VersionNum);  if(!VersionNum.isVersionNum()) {    // isn't a VersionNum    thisStream->streamPos.columnNumber -= VersionNum.length() + 1;    throw XMLParserException(&XMLEntityStreamStack,"not a valid Version number",XMLParserException::BAD_XML_ERR);  }  if(DEBUGXMLPARSER) {    printf("VersionNum = '%s'\n",VersionNum.c_str());  }  return 1;};// ******************************************************************************void XMLParser::matchProduction25Eq(				    XMLEntityStream *const thisStream) {  // this production is required  if(DEBUGXMLPARSER) {    printf("XMLParser::matchProduction25Eq\n");  }  matchProduction03S(thisStream,0);  if(!matchProductionFixedString(thisStream,"=")) {    throw XMLParserException(&XMLEntityStreamStack,"'=' expected",XMLParserException::BAD_XML_ERR);  }  matchProduction03S(thisStream,0);};// ******************************************************************************bool XMLParser::matchProduction27Misc(				      Element* containingElement) {  // this production is optional  if(DEBUGXMLPARSER) {    printf("XMLParser::matchProduction27Misc\n");  }  if(matchProduction03SDeep(0)>0) {    return 1;  }  if(matchProduction15Comment(containingElement)) {    return 1;  }  if(matchProduction16PI(containingElement)) {    return 1;  }  return 0;};// ******************************************************************************bool XMLParser::matchProduction28aDeclSep() {  // this production is optional  if(DEBUGXMLPARSER) {    printf("XMLParser::matchProduction28aDeclSep\n");  }  if(matchProduction03SDeep(0)>0) {    return 1;  }  XMLString refName;  unsigned long refLength;  XMLEntityStream* refStream;  refLength=matchProduction69PEReference((*XMLEntityStreamStack.begin()),refName);  if(refLength==0) {    return 0;  }  // we have found a PEReference, now need to find its stream and descend  // into it  refStream =     (*XMLEntityStreamStack.begin())->getXMLEntityStream(refName,XMLEntityStream::PARAMETER_ENTITY);  if(refStream==0) {    (*XMLEntityStreamStack.begin())->streamPos.count -= refLength;    (*XMLEntityStreamStack.begin())->streamPos.columnNumber -= refLength;    sprintf(errormessage,"Parameter Entity '%s' unknown",refName.c_str());    throw XMLParserException(&XMLEntityStreamStack,errormessage,XMLParserException::BAD_XML_ERR);  }  XMLEntityStreamStack.push_front(refStream);  return 1;};// ******************************************************************************bool XMLParser::matchProduction28doctypedecl() {  // this production is optional  if(DEBUGXMLPARSER) {    printf("XMLParser::matchProduction28doctypedecl\n");  }  StreamPositionStruct lastStreamPos = (*XMLEntityStreamStack.begin())->streamPos;  if(!matchProductionFixedString((*XMLEntityStreamStack.begin()),"<!DOCTYPE")) {    return 0;	// back out  }  if(matchProduction03S((*XMLEntityStreamStack.begin()),0)==0) {    // no white space following    // therefore not an doctypedecl

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -