473,385 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

A c program which printing the tag value of a xml file using expat parser in linux environment

like for a example xml program
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

out put should be :
Tove
Jani
Reminder
Don't forget me this weekend!
i want the c program for that in linux environments

Oct 25 '07 #1
2 2821
sharan wrote:
like for a example xml program
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

out put should be :
Tove
Jani
Reminder
Don't forget me this weekend!
i want the c program for that in linux environments
If you need a C application, take Expat and write your
own application around it. Should be about 200 lines.

http://expat.sourceforge.net/

If you are free to use a scripting language, you might try this one:

http://home.vrweb.de/~juergen.kahrs/...character-sets

The script for XMLgawk might look like this:

@load xml
XMLCHARDATA { printf $0 }

Oct 25 '07 #2

Juergen Kahrs <Ju*********************@vr-web.dewrote in
<5o************@mid.individual.net>:
sharan wrote:
><?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

i want the c program for that in linux environments

If you need a C application, take Expat and write your
own application around it. Should be about 200 lines.
About 80, and that's with a good bit of perverse logic
thrown in:

#include <assert.h>
#include <expat.h>
#include <string.h>
#include <stdio.h>

const char * chk_str (const char * str) {
for (; * str ; ++ str)
switch (* str) {
case ' ' : case '\t' : case '\r' : case '\n' :
break ;
default : return str ;
}
return str ;
}

#define C_BUF_CHUNK 8

char * c_buf = NULL ;
size_t c_buf_size = 0 ;
size_t c_buf_ptr = 0 ;

void c_buf_init () {
assert (c_buf = malloc (c_buf_size = C_BUF_CHUNK)) ;
c_buf [0] = '\n' ; c_buf [1] = '\0' ;
}

void c_buf_gulp () {
assert (
c_buf = realloc (c_buf , c_buf_size += C_BUF_CHUNK)
) ;
}

void c_buf_free () {
free (c_buf) ;
}

void c_buf_push (char c) {
if (c_buf_ptr == c_buf_size) c_buf_gulp () ;
c_buf [c_buf_ptr ++] = c ;
}

const char * c_buf_get () {
c_buf_push ('\0') ; c_buf_ptr = 0 ;
return c_buf ;
}

void c_buf_flush () {
const char * str = c_buf_get () ;
printf ("%s" , chk_str (str)) ;
if (strlen (str) && '\n' != str [strlen (str) - 1])
printf ("\n") ;
}

void elt_st (
void * usr_d ,
const XML_Char * name , const XML_Char ** attr
) {
c_buf_flush () ;
}

void elt_end (void * usr_d , const XML_Char * name) {
c_buf_flush () ;
}

void node_txt
(void * usr_d , const XML_Char * txt , int len) {
int i ;
for (i = 0 ; i != len ; ++ i) c_buf_push (txt [i]) ;
}

int main () {
char buf ;
XML_Parser prsr = XML_ParserCreate (NULL) ;
c_buf_init () ;
XML_SetElementHandler (prsr , &elt_st , &elt_end) ;
XML_SetCharacterDataHandler (prsr , &node_txt) ;
while (EOF != (buf = getchar ()))
XML_Parse (prsr , &buf , 1 , 0) ;
c_buf_free () ;
return 0;
}

Simply dumping text node content would likely fit in one
screen.

Note that I do not endorse the development process and
coding style (or lack thereof) prominently displayed in
this code snippet.

--
It is rare to find learned men who are clean, do not stink,
and have a sense of humour. -- Liselotte in a letter to
Sophie, 30 Jul 1705
Oct 25 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Doug | last post by:
I am running solaris 7 on two machines. I compiled python 2.2.1 with expat parser on one machine. The python binary is located in /usr/local/bin and the libraries are located in /usr/local/lib. ...
0
by: sprotty | last post by:
Hi Im porting a class library from Windows to linux. It needs to be posible for other developers to make use of the resulting library. So I need to take the 'standard' approach to the UNICODE...
3
by: yaffa | last post by:
does anyone have sample code for parsting an html file to get contents of a td field to write to a mysql db? even if you have everything but the mysql db part ill take it. thanks yaffa
2
by: sherihan2007 | last post by:
Hi while am running perl script which parses an XML file in AIX following error is getting:(i have given use XML::parser in the script) Can't load...
6
by: rellaboyina | last post by:
Dear All, I am having some data which will be stored in XML format and this needs to be parsed using the parser module XML::Parser and XML::Parser::Expat. This data consists of some special...
1
by: sharan | last post by:
Using the expat parser (http://expat.sourceforge.net/) i have to parse the following xml file and print it on the screen in tabular format. Want a c program on that in Linux environment....
1
by: sharan | last post by:
Using the expat parser (http://expat.sourceforge.net/) i have to parse the following xml file and print it on the screen in tabular format using C language. i am getting ouput serially but not in...
18
by: Brett | last post by:
I have an ASP.NET page that displays work orders in a GridView. In that GridView is a checkbox column. When the user clicks a "Print" button, I create a report, using the .NET Framework printing...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.