473,388 Members | 906 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,388 software developers and data experts.

expat GetAttribute help cpp

I'm trying to parse an xml file and am a bit confused. I have created my
class XmlParser.
Also I have 3 other questions.
1-How to the GetAttribute to search for the value of a specific pattern ?
I want to get the value of the Count tag.

2- My file does not contain the standalone header ? How can I deal with
3- In terms of memory handling is it righ to use the ParserFile method or
should i use another one ?
Too many questions I know,

thanks fo any help,
<?xml version="1.0"?>
<!DOCTYPE eSearchResult PUBLIC "-//NLM//DTD eSearchResult, 11 May 2002//EN"
<WebEnv>0qq2WLXpVUiIFEtvIrTlducz5uJT8c0vroAyBVMqIo qZjrVInjNh</WebEnv>
<To>(%22rna,+small+nucleolar%22%5BMeSH+Terms%5D+OR +snorna%5BText+Word
<Term>"rna, small nucleolar"[MeSH Terms]</Term>
<Field>MeSH Terms</Field>
<Term>snorna[Text Word]</Term>
<Field>Text Word</Field>

#include <iostream>
#include "XmlParser.h"
using namespace std;

int main (int argc, char **argv)
FILE* xmlFile;
XmlParser parser;

xmlFile = fopen(argv[1], "r");
if (!parser.parseFile(xmlFile)) {
"%s at line %d\n",
return 1;
char *test = "count";

while (!feof (xmlFile))
return 0;
void XmlParser::startElement(const XML_Char* name, const XML_Char** atts)

cout <<"Attribut:"<<name <<" Depth:"<< mDepth <<endl;
void XmlParser::endElement(const XML_Char*)
void XmlParser::charData(const XML_Char *s, int len)
const int leadingSpace = skipWhiteSpace(s);
if (len==0 || len==leadingSpace)
return; // called with whitespace between elements
cout <<" Value:";
fwrite(s, len, 1, stdout);
cout<<" Depth:"<< (mDepth-1) <<endl;

const XML_Char* XmlParser::getAttribute(const XML_Char *matchingName)

cout << "Match:" << matchingName << endl;

Jul 20 '05 #1
1 1802
In article <br**********@newshispeed.ch>, David <no****@home.com> wrote:

% 1-How to the GetAttribute to search for the value of a specific pattern ?
% I want to get the value of the Count tag.

Count is an element, not an attribute. in fact, your example contains
no attributes, only elements. If you're using expat, the parser doesn't
save anything for you -- you're expected to build whatever data structures
you need in your startElement method. You need to either save anything
you want to be able to query as the parse goes on, (i.e., stick the
element name and character value in a list), or you want to store the
names that you're interested in before the parse, then set a flag
when the appropriate elements come up, and print the character data
when the flag is set.

% 2- My file does not contain the standalone header ? How can I deal with
% that.

Most files don't have the standalone header. The example file doesn't
need anything from the DTD (unless there are default attribute values),
so you could simply not worry about it, but I think expat can read
external DTDs, so you could just let it read the DTD.


Patrick TJ McPhee
East York Canada
Jul 20 '05 #2

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

Similar topics

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
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. ...
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...
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....
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...
by: Fabian Kr?ger | last post by:
Hello, I got a weird problem and need your help and ideas... Ive written an php application which imports data in XML format and writes this data to a MySQL database to have a faster access....
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...
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:...
by: RobG | last post by:
I have always accessed attributes such as disabled using the DOM element property, however I was wondering about implementing a more generic function to get the values of attributes - which of...
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,...
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...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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: 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...
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...

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.