473,587 Members | 2,489 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>Remind er</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 2833
sharan wrote:
like for a example xml program
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Remind er</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>Remin der</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_ParserCreat e (NULL) ;
c_buf_init () ;
XML_SetElementH andler (prsr , &elt_st , &elt_end) ;
XML_SetCharacte rDataHandler (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
1548
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. I was told that if I would tar up the /usr/local/lib/python2.2 directory from the one machine. I could transfer that and the binaries from...
0
1091
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 aspects of the conversion. Internally i'm using the Expat XML parser, which only seems to work correctly when you pass it unicode strings that are...
3
1839
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
9746
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 '/usr/opt/perl5/lib/site_perl/5.8.2/aix-thread-multi/auto/XML/Parser/Expat/Expat.so' for module XML::Parser::Expat: 05 09-022 Cannot load module...
6
4416
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 characters like "ø, á, í, é, È, ž, ù, ý". But when I try to parse the particular record with these special characters using the method parse(), I...
1
2636
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. xml file is: <?xml version="1.0"?> <users> <user id="1"> <nameHari Oum </name> <age24 </age> <departmentProduct Development </department>
1
3099
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 tabular xml file is: <?xml version="1.0"?> <users> <user id="1"> <nameHari Oum </name> <age24 </age>
18
11273
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 classes, for each of the checked rows in the GridView. This works fine in the Visual Studio 2005 development environment on localhost. But, when I...
0
7923
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7852
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5719
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.