473,654 Members | 3,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

New to Expat - Help Required

HI All,

Currently writing a small program and here is my xml file and program.

---------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8" standalone="yes "?>
<abc>
<featureKey id="F1/1">
<description>La wful interception</description>
<start>2000-01-01</start>
<noStop/>
</featureKey>
<featureKey id="F2/2">
<description>SS 7 Signaling Over IP</description>
<start>2000-01-01</start>
<stop>2000-01-01</stop>
</featureKey>
</abc>
---------------------------------------------------------------------------------
Here is my program
---------------------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
#include "expat.h"
#define XMLFILENAME "l.xml"
/*
<featureKey id="F1/1">
<description>La wful interception</description>
<start>2000-01-01</start>
<noStop/>
</featureKey>
*/
typedef struct
{
int found;
char elementName[10];
char attrElementName[3][10];
char attrData[3][20];
char elementDesc[30];
int numberAttr;
} FEATUREKEY,*FEA TUREKEY_INFO;
static void XMLCALL startElement(vo id *userData, const char *name,
const char **atts)
{
int word = 0;
FEATUREKEY_INFO F = userData;
FEATUREKEY_INFO C = userData;
if (strcmp(name, "featureKey ") == 0)
{
F->found = 1;
strcpy(F->elementName, name);
while(*atts) /* element */
{
sprintf(F->attrElementNam e[word],"%s",
*atts++);
sprintf(F->attrData[word],"%s", *atts++);
if (strcmp(name, "descriptio n") == 0)
sprintf(F->elementDesc,"% s", *atts++);
word++;
}
F->numberAttr = word;
}
if (strcmp(name, "descriptio n") == 0)
word=0;
if (strcmp(name, "capacityKe y") == 0)
{
C->found = 1;
strcpy(C->elementName, name);
while(*atts) /* element */
{
sprintf(C->attrElementNam e[word],"%s",
*atts++);
sprintf(C->attrData[word],"%s", *atts++);
word++;
}
C->numberAttr = word;
}
}
static void XMLCALL endElement(void *userData, const char *name)
{
}
static void XMLCALL charHandler(voi d *userData, const XML_Char *s, int
len)
{
int i;
int currentAttr;
FEATUREKEY_INFO pMy = userData;
if (pMy->found == 1)
{
printf("\n\nele mentName: %s", pMy->elementName) ;
for (i = 0; i < len; i++)
{
printf("%c", s[i]);
}
printf("NumberA TTR: %d \n", pMy->numberAttr);
for (currentAttr = 0; currentAttr < pMy->numberAttr;
currentAttr++)
{
printf("attrEle mentName %d: %s", currentAttr,
pMy->attrElementNam e[currentAttr]);
printf("\nattrD ata %d: %s\n", currentAttr,
pMy->attrData[currentAttr]);
printf("\neleme ntDesc %d: %s\n", currentAttr,
pMy->elementDesc) ;
}
pMy->found = 0;
}
}
int main(int argc, char *argv[])
{
FILE *xmlfile;
char buf[BUFSIZ];
FEATUREKEY_INFO pMyData;
XML_Parser parser = XML_ParserCreat e(NULL);
int done;
pMyData = malloc(sizeof(F EATUREKEY));
pMyData->found = 0;
pMyData->numberAttr = 0;
XML_SetUserData (parser, pMyData);
XML_SetElementH andler(parser, startElement, endElement);
XML_SetCharacte rDataHandler(pa rser, charHandler);
printf("Opening File\n");
if ((xmlfile = fopen (XMLFILENAME, "r")) == NULL)
{
printf("Error opening XML file\n");
return -1;
}

do
{
size_t len = fread(buf, 1, sizeof(buf), xmlfile);
done = len < sizeof(buf);
if (XML_Parse(pars er, buf, len, done) ==
XML_STATUS_ERRO R)
{
printf("%s at line %d\n",
XML_ErrorString (XML_GetErrorCo de(parser)), XML_GetCurrentL ineNum
ber(parser));
return 1;
}
} while (!done);
XML_ParserFree( parser);
fclose(xmlfile) ;
free(pMyData);
return 0;
}
-------------------------------------------------------------------

Here I am able to print and grab information of featureKey ids but not
able to get attached attributes of featurekey ids. Please let me know
how to do it.

Thanks and Regards,
Sridhar
ms****@yahoo.co m

Jul 20 '05 #1
4 1876
Sridhar wrote:
HI All,

Currently writing a small program and here is my xml file and program.

---------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8" standalone="yes "?>
<abc>
<featureKey id="F1/1">
<description>La wful interception</description>
<start>2000-01-01</start>
<noStop/>
</featureKey>
<featureKey id="F2/2">
<description>SS 7 Signaling Over IP</description>
<start>2000-01-01</start>
<stop>2000-01-01</stop>
</featureKey>
</abc>
--------------------------------------------------------------------------------- <snip>
Here I am able to print and grab information of featureKey ids but not
able to get attached attributes of featurekey ids. Please let me know
how to do it.


I don't understand your question.
The only attributes in your XML file are named "id".

Karl
Jul 20 '05 #2
On Wed, 05 Jan 2005 04:39:42 -0800, Sridhar wrote:
typedef struct
{
int found;
char elementName[10];
char attrElementName[3][10];
char attrData[3][20];
char elementDesc[30];
int numberAttr;
} FEATUREKEY,*FEA TUREKEY_INFO; sprintf(F->attrElementNam e[word],"%s", *atts++);
I hope you won't do something quite so dangerous in any kind of serious
program. ;-)
Here I am able to print and grab information of featureKey ids but not
able to get attached attributes of featurekey ids. Please let me know
how to do it.


You are thoroughly confused about elements, attributes, and "ids", so your
description of your problem makes no sense. You should read the XML spec
to learn the difference between elements and attributes.

You can gain further insight by studying the output of these handlers in
place of yours:

static void XMLCALL charHandler(voi d *userData, const XML_Char *s, int
len)
{
printf( "DATA passed to charHandler (%d characters):\n" , len ) ;
printf( "==>%*s", len, s ) ;
printf( "\nEND OF DATA (%d characters)\n", len ) ;
}

static void XMLCALL startElement(vo id *userData, const char *name,
const char **atts)
{
const char *np ;
const char *vp ;

puts( "ENTERING startElement() handler!!!" ) ;
printf( "\tELEMENT at this point is: [%s]\n", name ) ;
printf( "\tAND ATTRIBUTES of [%s] are:\n" ) ;
while ( *atts ) {
np = *atts++ ;
vp = *atts ;
if ( vp ) {
printf( "\t\t[%s] ==> [%s]\n", np, vp ) ;
atts++ ;
}
}
puts( "RETURNING from startElement() handler!!!" ) ;
}

static void XMLCALL endElement(void *userData, const char *name)
{
printf( "End of ELEMENT [%s] reported by parser!!!\n", name ) ;
}

In particular, observe *how many times* startElement() and endElement()
are called, and at what points in relation to your XML input file.

Jul 20 '05 #3
On Thu, 06 Jan 2005 01:34:02 +0000, Arjun Ray wrote:
printf( "\tAND ATTRIBUTES of [%s] are:\n" ) ;


That should be

printf( "\tAND ATTRIBUTES of [%s] are:\n", name ) ;

Sorry about that.

Jul 20 '05 #4
HI,

I am sorry to confused a lot, but I am new to these environments (XML
and Expat). Acutally I need to extract information in <featureKey> &
</featureKey>
tags (HTML Word) put in a data structure. In this case 2 records of
information one for each <featureKey> & </featureKey> set. Please let
me know how to do this using Expat.

<featureKey id="F1/1">
<description>La wful interception</description>
<start>2000-01-01</start>
<noStop/>
</featureKey>
<featureKey id="F2/2">
<description>SS 7 Signaling Over IP</description>
<start>2000-01-01</start>
<stop>2000-01-01</stop>
</featureKey>

I hope now clearly explained the problem.
Thanks and Regards,
Sridhar
ms****@yahoo.co m

Jul 20 '05 #5

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

Similar topics

1
1704
by: Mike Brown | last post by:
Python 2.3 comes with its own version of Expat. setup.py says it is Expat 1.95.2, but the code in Modules/expat seems to actually be Expat 1.95.6. It's really 1.95.6, right? -- Mike
1
1550
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 /usr/local/bin to another machine running solaris 7 and all should be fine. Machine 1 acts as a hub for...
1
1610
by: Ingo Blank | last post by:
Hi, while 95% of my 'psycoed' applications run fine, it throws SIGSEGVs in conjunction with expat. Anybody noticed the same ? Python 2.3.2 (#4, Nov 13 2003, 02:10:49) on linux2 $ uname -a Linux euler 2.4.20-8 #1 Thu Mar 13 17:18:24 EST 2003 i686 athlon i386
2
3930
by: Thomas Guettler | last post by:
Hi! What are the difference between xml.parsers.expat and xml.sax? Up to now I used xml.sax.make_parser and subclass from ContentHandler. I think xml.sax.make_parser uses expat as default. Why should I want to use xml.parsers.expat?
4
3727
by: alainpoint | last post by:
Hello, I use Elementtree to parse an elementary SVG file (in fact, it is one of the examples in the "SVG essentials" book). More precisely, it is the fig0201.svg file in the second chapter. The contents of the file are as follows (i hope it will be rendered correctly): <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> <svg width="200" height="200">
1
2506
by: David Madore | last post by:
Hi! Anyone in for a Byzantine discussion on XML well-formedness? Here's the situation: test.xml contains --- test.xml: cut after --- <?xml version="1.0" encoding="us-ascii"?> <!DOCTYPE foobar > <foobar />
1
2368
by: B Mahoney | last post by:
I have a simple Kid template document: <?xml version='1.0' encoding='utf-8'?> <?python import time title = "A Kid &anything; Template" ?> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#" >
2
3732
by: dwelch91 | last post by:
Hi, c.l.p.'ers- I am having a problem with the import of xml.parsers.expat that has gotten me completely stumped. I have two programs, one a PyQt program and one a command line (text) program that both eventually call the same code that imports xml.parsers.expat. Both give me different results... The code that gets called is (print statements have been added for debugging):
1
1878
by: vadlapatlahari | last post by:
Hi, I get the following error with Expat while configuring my application server. Can anyone suggest a solution? When i do an ldd, i get the following : $ldd Expat.so Expat.so needs: /usr/lib/libc.a(shr.o) Cannot find /unix --- Is there a problem here? /usr/lib/libcrypt.a(shr.o)
0
8285
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8814
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8706
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8475
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7304
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5621
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2709
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
1915
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.