ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm writing a client / server application in C, and want to send a string containing XML style tags. When the string is recieved by the server, i need to strip the string of those tags so we can use the value within.
So far i've tried reversing the string and dropping the last n number of chars from the array, as well as attempting to take out the value using the strtok() function. I've looked through a list of the functions outlined in string.h, but there doesnt seem to be anything that does what i want straight off the bat.
The application has to be written in pure C, is there any existing function I can use to retrieve the content between two string tags? Or if any of you have another idea which may be better, feel free to jump right in.
Here's what i'm trying to achieve:
Code:
char *theString = "<tag>Hello</tag>";
char *theTag = "<tag>";
/*
Do something to get rid of the two tags
Resulting in "Hello"
*/
If you just want simple xml parsing you can try the function below.
Might have bug I dont' know.
It dont' support attribute. (ie. <person born="1978.9.9"></person>)
and DTD and other things.
======================================================
example:
<? version ?>
<tag1>
<innertag1>content1 </innertag1>
<innertag2>content2</innertag2>
</tag1>
<tag2> content2 </tag2>
Basically i took blackzone's code, and hacked it up till it worked. Still doesnt parse attributes, but i dont need it to do that right now.
All i need to remember now is that two little ++'s in the wrong spot can cause disaster. Be careful.
Methinks a bit more learning is required on my behalf
The purpose i need it for is to parse a predefined set of XML, so i'm always going to know how big the actual
XML string is... its not actually ever parsing a file, just a string i send and recieve in a client / server type app.
So for what i need it for, it'll do the task
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.