我有一个XML文件
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE labels SYSTEM "label.dtd">
<labels _FORMAT ="BARCODE" _QUANTITY="1" _PRINTERNAME="P1">
<label>
<variable name= "PRTNUM">234243242</variable>
<variable name= "QUANTY">004342</variable>
<variable name= "PONUMB">844463541</variable>
<variable name= "SERIAL">DZ12</variable>
<variable name= "REV">234235</variable>
<variable name= "UNITS">234235</variable>
</label>
</labels>
我已解析的,即&lt;&gt; ......标签之间的包含 例如。 004342仅读取004342数据&amp;其他人被忽视了。 因此整个解析后的数据已经保存到另一个文件名parsed.txt中,看起来像
234243242
004342
844463541
DZ12
234235
234235
这个解析后的数据我必须与其他文件(barcode.dpl)合并
c0001
f260
L
D11
H30
R0000
C0040
1X1100000100010B300300003003
181100202900027Part No
181100202900097[PRTNUM]
1e5504002400030B
1X1100002300010L300003
191100202000030Quantity
191100202000080[QUANTY]
1e5504001500040B
1X1100001400010L300003
1X1100001400150L003090
191100202000170P.O.No
191100202000220[PONUMB]
1e5504001500180B
191100201200030Supplier
1e3304000700030B
1X1100000600010L300003
181100200300030Serial
181100200300090[SERIAL]
171100300900190Rev
171100300300190[REV]
171100300900240Units
171100300300240[UNITS]
1X1100000100180L003130
Q0001
E
解析后的数据将放在[PRTNUM],[QUANTY],[PONUMB]等处。 &安培;该文件看起来像....
c0001
f260
L
D11
H30
R0000
C0040
1X1100000100010B300300003003
181100202900027Part No
181100202900097234243242
1e5504002400030B
1X1100002300010L300003
191100202000030Quantity
191100202000080004342
1e5504001500040B
1X1100001400010L300003
1X1100001400150L003090
191100202000170P.O.No
191100202000220844463541
1e5504001500180B
191100201200030Supplier
1e3304000700030B
1X1100000600010L300003
181100200300030Serial
181100200300090DZ12
171100300900190Rev
171100300300190234235
171100300900240Units
171100300300240234235
1X1100000100180L003130
Q0001
E
所以实际上我的问题是当它从条形码文件中检测到[....]时解析数据位置,而不管xml&amp;中给出的标记名称是什么。条形码文件...如果我将[QUANTY]放在[PRTNUM]的位置,它将放置相同的数据234243242(实际上为[PRTNUM])。 如何使我的程序能够从barcode.txt文件中读取[...]内的数据。然后将解析文件中的相应数据放在该位置。
我的c代码是......
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<DIR.h>
#include<string.h>
int main()
{
clrscr();
int a[1];
char cBuffer[50] = {0};
char ch, cSkipdata;
FILE* fPtr;
FILE* fPparse;
FILE* fPin;
FILE* fPout;
char* Ptr;
getcwd(cBuffer, 100);
printf("The current directory is %s\n\n",cBuffer);
fPtr = fopen("sample.xml", "r"); /* Open XML file*/
fPparse = fopen("parse.txt","w");
if(fPtr)
{
printf("The file is\n\n");
scanf("%c",&a[1]);
// look for test between > and <
cSkipdata=1;
while ((ch = getc(fPtr)) != EOF) /* read character */
{
if(ch == '<')
cSkipdata=1;
if(!cSkipdata && ch != ' ')
{
putchar(ch);
// fputc(ch ,stdout);
fputc(ch, fPparse);
}
/* write character */
if(ch == '>')
cSkipdata=0;
}
fclose(fPtr);
fclose(fPparse);
}
else
{
printf("file can not open\n");
}
fPin = fopen("barcode.txt", "r"); /* Open DPL file*/
fPout = fopen("final.txt", "w"); /* Open the output final to save changea*/
fPparse = fopen("parse.txt","r");
scanf("%c",&a[1]);
printf("\n\nfinal.txt is \n");
cSkipdata = 0;
while((ch = getc(fPin)) != EOF)
{
if(ch == '[') /* Skip the data if condition is true*/
{
int iLine=0;
cSkipdata = 1;
while ( (ch = getc(fPparse)) != EOF) //f read a character
{
//if newline and we have output data break
if((ch=='\n') && (iLine>0) )
break; // end of line
//if not space output character
if(ch > ' ')
{
// valid character output
iLine++;
putchar(ch);
fputc(ch, fPout);
}
}
}
if(cSkipdata)
{
if(ch == ']')
cSkipdata = 0;
}
else
{
putchar(ch);
fputc(ch ,fPout);
}
}
fclose(fPin);
fclose(fPout);
fclose(fPparse);
getch();
}