Hi everyone,

I'm currently on a placement and doing some other work on the side and I was hoping someone can help me...

I've started playing around with xerces-c in work on redhat to read in small xml config files - I also have some applications I was working on at home in c++ and I was hoping to do the same with them (rather than having to enter tons of command line args)

Problem is - how the hell do you get xerces-c to work with Ubuntu :S ? I've been trying to install it for ages and compile but getting no where - considering for redhat all I had to do was download the source tar, rpmbuild an rpm from it, install and it (taken from this tutorial http://www.yolinux.com/TUTORIALS/XML-Xerces-C.html)worked this is a bit of a nightmare!!

Any help would be much appreciated :)!

As far as I'm aware libxerces is the same as pretty much any other library in Debian based systems. It should be available in the repositories (the exact version will depend on which version of Ubuntu you're running).

You can use apt-get to install the packages for the library and the dev files.
Then to use them in your C/C++ programs you simply #include the appropriate headers and link with the library when compiling/linking.

So perhaps try:

sudo apt-get update
apt-cache search libxerces

This will update the list of available packages and will display any xerces packages available.
Then to install the relevant packages use:

sudo apt-get install libxercesXXX libxercesXXX-dev

Where XXX is any version information you saw listed in the apt-cache search command you ran previously.

Once you have the files installed, you're ready to use xerces in your program.
Note: To link your program with libxerces you need to use the switch -lxerces-c in your build scripts or in the gcc/g++ command line.

Still having no luck... I've used the apt-get install to install it as well as downloading the source/binary dist and installing them myself, the files are definately there but I can't get anything to compile or work with it... strange because using redhat all I ahd to do was build the rpm, install it and add the parameters to the compiler and it worked no problem !

So, did you install the libxerces development package? Without that, you won't get the headers you need to build c-xerces code. The basic package will only have the shared libraries and dependencies needed to run existing applications that rely upon it.

Yeah they were all definately installed, in both /usr/local/lib & /usr/local/include and /usr/lib & /usr/include,

I managed to get it working there by doing the configure command, then make, then copying the files over to /usr/lib etc.. myself, dunno why it never compiled before but :S

Sometimes when playing Whack-a-Mole, you do get the right mole! :-) Anyway, I'm glad you sorted this out on your Ubuntu system. Myself, I stopped using Ubuntu after they stopped supporting 9.04 - IMO the last REALLY great Ubuntu distribution! Now I am using RHEL 6.1 and clones (Scientific Linux) mostly.

Yeah, have to agree I'm not to fond of the new ubuntu myself, although at the minute it seesm to be working so won't be chucking it out... yet ;)

Well, as the saying goes, if it ain't broke, don't fix it!

I suppose no one would know a good way in c++ to read the results from the XML file? For example, I have the following in an xml file

<ExpectedFiles>
    <File>
        <Name>TAQ_OUT*</Name>
    </File>
    <File>
        <Name>TAQ_STR*</Name>
    </File>
    <File>
        <Name>TAQ_TRD*</Name>
    </File>
</ExpectedFiles>
<ValidProducts>
    <Product>
        <Family>taq</Family>
        <Name>xdpliffeeuro</Name>
    </Product>
</ValidProducts>

I can read in the values from the XML file and print them out, but it's all in one go - is there a way say to return each value as it is read in, or too only read in one at a time maybe? Or would I be better making my functions accept some sort of vector or array that stores the results then returns that to the user?

This all depends upon what you need. There is the DOM approach - read the entire thing and return a composite structure with all the data. Then there is the SAX approach where you set up callbacks to deal with each element type in the document. This may be a better method for you if you need to react in some manner as each element is read. I have written other XML parsers myself in the past in order to minimize memory usage and improve read performance. It's been awhile (about 5 years), but I think that xerces will allow you to use either approach. Here is a page from the saxproject that explains the differences: http://www.saxproject.org/event.html - and after research, yes xerces will provide the ability to deal with either approach.

Yeah I had a look at SAX and figured DOM would be easier lol plus it would be smallish XML files so memory usage wouldn't be a problem, I suppose making the functions take a vector as a parameter and using that vector to store the results shouldn't be a problem - what I'm aimming to do is make it where -

start of appl, pass in path of xml config, and command line arguments
- for each parameter search the xml file and the command line arguemtns for it
- if it finds it, depending on what the user prefers, return either the xml or cmd line argument
- do this until no more arguemnts are needed

sadly, easier said than done lol :)

Yes, the problems always arise when the "rubber meets the road"! That's why I have, in the past, written my own parsers, simply because that was the least painful way to get what I wanted out of the situation.

Yeah I think I'm aimming a bit too high at the minute, trying to write one parser that will fit any application, gonna try and get one to suit the application I'm doing at the min then work on the bigger one maybe if I get some free time, or if its even needed!

Well, the ultimate question is "Is it fast enough?", and the ultimate answer is "Sometimes!"... :-)

If it's not fast enough at reading in all the configs, just start the program earlier ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.