Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
Actually i want to do few changes in code. i read input sample.xml file.

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>


& parsed data is placed in parsed.txt


VB
234243242
004342
844463541
DZ12
234235
234235



this data is then merged with barcode.txt

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


But while merging the data it is merged irrespective of the tag name that is included in xml & barcode file.

e.g
if i put [QUANTY] at the position of [PRTNUM] it will place the same data 234243242 (which actually for [PRTNUM]).
How to make it possible that my program will read the data inside [...] from barcode.txt file & then place the corresponding data from parsed file at that position.

my c code xmldpl.txt

C#
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<DIR.h>
#include<string.h>

int main()
{

  clrscr();
  char 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();
}
Posted
Comments
Sergey Alexandrovich Kryukov 21-Jul-15 2:05am    
The whole idea to parse XML and put data in a text file is wrong. Why having XML then?
—SA
Superdude Rahul 21-Jul-15 4:16am    
by having this you can print barcode file using just xml . Refer http://printronix.com/wp-content/uploads/manuals/PTX_QSG_XML_179943D.pdf
Sergey Alexandrovich Kryukov 21-Jul-15 7:24am    
Well, if this text form is required by some API which you cannot change, I agree, thank you for the explanation.
—SA

Have you really to perform such a task using C 'to the metal' (that is without using libraries)?
You know using, for instance, C++ and a XML parsing library would make your life easier.
That said you need to store the parsed XML variables in a container equivalent to the C++ standard library container map<string,> (or map<string,> - you could also use an unordered_map -).
Then, on parsing the barcode file you could add the required info by looking up the value in such map.

If, for instance, using C# is an option, the your task might becoma almost trivial.
 
Share this answer
 
Comments
Superdude Rahul 21-Jul-15 4:19am    
@CPallini I know its kinda hard to build xml parser using C but I have to do it using c libraries do you have any suggestion?
CPallini 21-Jul-15 4:28am    
There are many free XML parsers available, Google is your friend:
https://www.google.co.uk/#q=free+XML+C+library
Superdude Rahul 21-Jul-15 6:41am    
see i want to make parser for barcode printing purpose you know about DTD?
I wanna make DTD which will have details about barcode & other font types.

hey is anyone out there who can help me?

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900