?? xmlwf.c
字號:
xml_char = GetChar();
}
if(((PXML_Parser)parser)->commentHandler != NULL)
((PXML_Parser)parser)->commentHandler(pComment->data);
FreeXML_String(pComment);
SkipSpace();
}
void XML_Element(Pxml_parser parser, int* depth, const PXML_String pUpElementName)
{
PXML_String pElementName = CreateXML_String();
PXML_String pDataChar = CreateXML_String();
PXML_String pForCmp = CreateXML_String();
PAttributes pAttri = AtrributesCreate();
PAttriPairs pattriPairs = NULL;
XML_Char currentChar;
_BOOL isCdata = FALSE;
int depthOfThisElement = *depth;
XML_ASSERT_VOID(pAttri);
XML_ASSERT_VOID(pForCmp);
XML_ASSERT_VOID(pDataChar);
XML_ASSERT_VOID(pElementName);
com3:SkipSpace();
currentChar = GetChar();
if(currentChar == '<' ){
currentChar = GetChar();
if(currentChar == '/'){
if(*depth == 0){
ErrorHappen(parser, "Error in syntax of start of element: \"</element_name>\" can not be the start of element.");
return;
}
/**
XML_ClearStr(pElementName);
XML_StrStrCat(pElementName, pUpElementName);
goto EndOfElement;
*/
GoBack(2);
*depth = *depth - 1;
return;
}else{
if(currentChar == '!'){
currentChar = GetChar();
if(currentChar == '-'){
currentChar = GetChar();
if(currentChar == '-'){
ProcessCommentInElement(parser);
goto com3;
}else{
ErrorHappen(parser, "Error in syntax of element:Invalid /'!/' appears after \'<\'.");
return;
}
}else{
ErrorHappen(parser, "Error in syntax of element:Invalid /'!/' appears after \'<\'.");
return;
}
}
GoBack(2);
}
}else{
GoBack(1);
}
SkipSpace();
currentChar = GetChar();
if(currentChar != '<'){
ErrorHappen(parser, "Error in syntax:Invalid in start of the element, \"< element_name>\" expected.");
return;
}
proper_name(parser, pElementName);
SkipSpace();
currentChar=GetChar();
while(currentChar != '/' && currentChar != '>'){
GoBack(1);
pattriPairs = Proper_token( parser);
XML_ASSERT_VOID(pattriPairs);
addAttribute(pAttri, pattriPairs);
SkipSpace();
currentChar = GetChar();
}
if(currentChar == '/'){
currentChar = GetChar();
if(currentChar != '>'){
ErrorHappen(parser, "Error in element syntax:Invalid end string of element, no \" />\" exists.");
return;
}
*depth = *depth + 1;
if(((PXML_Parser)parser)->startElementHandler != NULL)
((PXML_Parser)parser)->startElementHandler( ((PXML_Parser)parser)->userData, pElementName->data, pAttri);
*depth = *depth - 1;
if(((PXML_Parser)parser)->endElementHandler != NULL){
((PXML_Parser)parser)->endElementHandler(((PXML_Parser)parser)->userData, pElementName->data, pAttri);
}
return;
}else{
if(currentChar != '>'){
ErrorHappen(parser, "Error in element syntax:Invalid string of element, \">\" expected.");
return;
}
}
*depth = *depth + 1;
if(((PXML_Parser)parser)->startElementHandler != NULL)
((PXML_Parser)parser)->startElementHandler( ((PXML_Parser)parser)->userData, pElementName->data, pAttri);
SkipSpace();
com1: currentChar = GetChar();
if(currentChar == '<'){
currentChar = GetChar();
if(currentChar == '/'){
goto EndOfElement;
}else if(currentChar == '!'){
currentChar = GetChar();
if(currentChar == '-'){
currentChar = GetChar();
if(currentChar == '-'){
ProcessCommentInElement( parser);
SkipSpace();
goto com1;
}else{
ErrorHappen(parser, "Error in syntax of comment in element:\'-\' should not appear after \'<\'.");
return;
}
}else{
if(currentChar != '['){
ErrorHappen(parser, "Error in syntax of :\'-\' or \'[\' should not appear after \'<\'.");
return;
}
}
XML_ClearStr(pForCmp);
GetXMLCharUntil('[', parser, pForCmp);
if(!XML_StrPCharCmp(pForCmp, JTEXT("cdata")) || !XML_StrPCharCmp(pForCmp, JTEXT("CDATA"))) isCdata = TRUE;
else{
ErrorHappen(parser, "Error in element syntax:Invalid string of element, \"![cdata\" expected.");
return;
}
}else{
GoBack(2);
}
}else{
GoBack(1);
}
XML_ElementText(parser, pDataChar, isCdata);
/**
printf("[%d]\n",pDataChar->length);
if(pDataChar->length) printf(pDataChar->data);
*/
if(((PXML_Parser)parser)->characterDataHandler != NULL)
((PXML_Parser)parser)->characterDataHandler( ((PXML_Parser)parser)->userData, pDataChar->data, pDataChar->length, isCdata);
SkipSpace();
if(isCdata){
XML_ClearStr(pForCmp);
GetXMLCharUntil('>', parser, pForCmp);
if(XML_StrPCharCmp(pForCmp, JTEXT("]]"))){
ErrorHappen(parser, "Error in element syntax:Invalid end string of element, \"[[>\" expected.");
return;
}
}
com2: SkipSpace();
currentChar = GetChar();
if(currentChar == '<' ){
currentChar = GetChar();
if(currentChar == '/') goto EndOfElement;
else{
if(currentChar == '!'){
currentChar = GetChar();
if(currentChar == '-'){
currentChar = GetChar();
if(currentChar == '-'){
ProcessCommentInElement( parser);
goto com2;
}else{
ErrorHappen(parser, "Error in syntax of element:Invalid /'!/' appears after \'<\'.");
return;
}
}else{
ErrorHappen(parser, "Error in syntax of element:Invalid /'!/' appears after \'<\'.");
return;
}
}
GoBack(2);
}
}else{
GoBack(1);
}
while(depthOfThisElement < *depth){
// printf("\n%d\n", *depth);
XML_Element(parser, depth, pElementName);
}
*depth = *depth + 1;
/*
SkipSpace();
currentChar = GetChar();
*/
////////////////
com4: SkipSpace();
currentChar = GetChar();
if(currentChar == '<' ){
currentChar = GetChar();
if(currentChar == '/') goto EndOfElement;
else{
if(currentChar == '!'){
currentChar = GetChar();
if(currentChar == '-'){
currentChar = GetChar();
if(currentChar == '-'){
ProcessCommentInElement( parser);
goto com4;
}else{
ErrorHappen(parser, "Error in syntax of element:Invalid /'!/' appears after \'<\'.");
return;
}
}else{
ErrorHappen(parser, "Error in syntax of element:Invalid /'!/' appears after \'<\'.");
return;
}
}
ErrorHappen(parser, "Error in element syntax:Invalid end string of element, \"</+elementName>\" expected.");
return;
}
}else{
ErrorHappen(parser, "Error in element syntax:Invalid end string of element, \"</-elementName>\" expected.");
return;
}
///////////////////
/*
if(currentChar != '<'){
ErrorHappen(parser, "Error in element syntax:Invalid end string of element, \"</ elementName>\" expected.");
return;
}
currentChar = GetChar();
// putchar(currentChar);
if(currentChar != '/'){
ErrorHappen(parser, "Error in element syntax:Invalid end string of element, \"</ elementName>\" expected.");
return;
}
*/
EndOfElement:
SkipSpace();
XML_ClearStr(pForCmp);
proper_name(parser, pForCmp);
SkipSpace();
currentChar = GetChar();
if(XML_StrCmp(pElementName,pForCmp)){
/*
putchar('\n');
printf(pForCmp->data);
printf("[%d]", pForCmp->length);
putchar('\n');
printf("[%d]", STRLEN(pForCmp->data));
putchar('\n');
printf("[%d]", strcmp(pForCmp->data,pElementName->data));
putchar('\n');
printf(pElementName->data);
printf("[%d]", STRLEN(pElementName->data));
putchar('\n');
printf(pUpElementName->data);
printf("[%d]", STRLEN(pUpElementName->data));
putchar('\n');
for(; i < pForCmp->length ; i++){
printf("%c, ", pForCmp->data[i]);
}
*/
ErrorHappen(parser, "Error in element syntax:Invalid end string of element, \"</elementName>\" expected.");
return;
}
*depth = *depth - 1;
if(((PXML_Parser)parser)->endElementHandler != NULL)
((PXML_Parser)parser)->endElementHandler(((PXML_Parser)parser)->userData, pElementName->data, pAttri);
// }
FreeXML_String(pElementName);
FreeXML_String(pDataChar);
FreeXML_String(pForCmp);
AttributesFree(pAttri);
}
//End: Element process function series
//Start: Document process function series
void XML_Document(Pxml_parser parser)
{
XML_Char xml_char;
_BOOL goOut = FALSE;
int depthOfElement = 0;
XML_Header(parser);
while(!goOut){
SkipSpace();
xml_char = GetChar();
if(xml_char != '<'){
ErrorHappen(parser, "Error in syntax:Invalid character before element or instruction...");
return;
}
xml_char = GetChar();
if(xml_char == '!'){
xml_char = GetChar();
if(xml_char == '-'){
xml_char = GetChar();
if(xml_char != '-'){
ErrorHappen(parser, "Error in syntax:Invalid start string of comment.");
return;
}
XML_Comments(parser);
}else{
GoBack(1);
XML_Declare(parser);
}
}else if(xml_char=='?'){
XML_Instruct(parser);
}else{
GoBack(2);
XML_Element(parser, &depthOfElement, NULL);
goOut = TRUE;
}
}
if(((PXML_Parser)parser)->endDocumentHandler)
((PXML_Parser)parser)->endDocumentHandler(((PXML_Parser)parser)->userData );
}
//End: Document process function series
// End the functions to process the recusion down analysis.
/**
The function to parse a xml file inputed in streamMode.
*/
int XML_doParse(Pxml_parser parser)
{
struct tm* ptime;
time_t nowTime;
FILE* log = fopen("c:\\XMLParser.log", "a+");
if(!parser)
if(log){
if(parser == NULL){
fputs("The pointer to XML_Parser passed by reference is invalid!\n", log);
fclose(log);
return 0;
}
}else{
return 0;
}
time(&nowTime);
ptime = localtime(&nowTime);
if( log != NULL)
fprintf(log, "-------------------%d-%d-%d %d:%d:%d--------------------\n",
ptime->tm_mon+1, ptime->tm_mday, ptime->tm_year+1900, ptime->tm_hour, ptime->tm_min, ptime->tm_sec);
fclose(log);
row = 1;
col = 1;
XML_Document(parser);
return 1;
}
void test()
{
/*printf("%d\n", STRLEN(ascii2));
if(IsMemberOf(250, ascii2, STRLEN(ascii2))) printf("IsmemberOf function is right.");
*/
XML_Char c = GetChar();
while(c != EOF){
//putchar(GetChar());
GetChar();
};
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -