ive got a xml file like this:

<?xml version="1.0"?> 
<orders>

<customer>
      <order_num>6656</order_num>
      <name>jon doe</name>
      <street>123 fake st</street> 
      <city>Beverly Hills</city> 
      <state>CA</state> 
      <zip>90210</zip> 
   </customer>
   
   <customer>
      <order_num>1337</order_num>
      <name>bob johnson</name>
      <street>1232 something ave</street> 
      <city>Petaluma</city> 
      <state>CA</state> 
      <zip>94952</zip> 
   </customer>
   
<customer>
      <order_num>5643</order_num>
      <name>bill story</name>
      <street>1st ave</street> 
      <city>Beverly Hills</city> 
      <state>CA</state> 
      <zip>90212</zip> 
   </customer>
   
   <customer>
      <order_num>4533</order_num>
      <name>tom hutchinson</name>
      <street>214 5th st</street> 
      <city>San Francisco</city> 
      <state>CA</state> 
      <zip>94109</zip> 
   </customer>
   
</orders>

i need to make a program that lists customers and there info:
1)from a specific city
2) customers in a range of zip[ codes
questions like that
all without posting the xml tags
im at a loss on the easiest way to do this.
im assuming no one will do it for me
(if thats not the case please pm me any code you think can help :))
but if you could point me in the right direction on how to acomplish it that would be great

one person i talked to mentioned read the file as strings and tokenize the data is this a good way to do it? or is there some better way i should reasearch?

thanks

its a weekend assignment
im suppose to be learning
or else i would use one of the many xml libraries around
thats also what makes researching it difficult cause most real word problems people solve using already exiting libraries
but if i get pointed in the right direction hopefully i can cobble something together

thanks though

>>one person i talked to mentioned read the file as strings and tokenize the data is this a good way to do it?

If the file is ordered as posted it wouldn't be that hard to create a class modeled around the information for each customer and to create a file reader to extract each line from the file as a string, modify it if needed (for example, convert the string extracted to a numerical value where desired) and place it in an appropriate member variable, storing each object as extracted in a container that could then be searched using specific criteria such as a specific city or in a range of specific zip codes, etc.

If the file is ordered as posted it wouldn't be that hard to create a class modeled around the information for each customer and to create a file reader to extract each line from the file as a string, modify it if needed (for example, convert the string extracted to a numerical value where desired) and place it in an appropriate member variable, storing each object as extracted in a container that could then be searched using specific criteria such as a specific city or in a range of specific zip codes, etc.

can anyone give me some hints on this im having issues

thanks

if you load the file #include <fstream> read in the file using std::ifstream("folder\\file.txt" now two options load into a single string or line by line.
Single std::string will be easiest

there are google articles on how to do this

The next thing is

std::string data;
//load data

//this is like an int showing current loc in string
std::string::size_type pos(0);
std::string::size_type cur_pos = data.find('<', pos);
if(cur_pos != std::string::npos)
{
//found the start of tag
//advance to first letter
+cur_pos
//now find end
 pos = data.find('>', cur_pos);
std::string tag = data.substr(cur_pos, pos - cur_pos); 
//check is closing tag
if(tag.size() > 0 && tag[0] = '/')
{
   tag = tag.substr(1);
   //are we inside or not
}
else
{
  //new tag
}

what else you have to do is add
a tag to an open std::vector<std::string> and if it closes it should be the last tag on the list
you have to store the strings between tags as parameters

now I have left a fair bit for you to do yourself here.

But if you assume no errors in xml and no self closing tags the
above methods should suffive

can anyone give me some hints on this im having issues

thanks

Use getline() and a loop.
After that, look up the various methods in std::string.

can anyone give me some hints on this im having issues

thanks

Biggest issue is not reading the rules and posting any information at all about what those issues are. We can answer specific questions, but if all you're going to do is talk in generalities, the only help we can give is writing it for you.

so ive parsed my file
and put it into a vector so each item from the xml is a element but i cant seem to get a find function to work
i know most of you dont like to do code for people but its due at midnight(an all or nothing situation) and i dont want to get a zero after all the effort i put in
so if you want to help i need to print all the contacts from a specific city and all from a zipcode range


il keep trying top get this but i hope someone helps

So why have you waited until now to say "due at midnight!"?

It's been 3 DAYS since your last post. If you'd bothered to post your latest effort on a daily basis, we could have helped you easily.

But no, it's "an emergency" and you haven't even shown us what you've been doing.

never mind
:)

the reason i asked was a premtive strike if i couldnt figure it out or a alternative by then someone could have posted a answer that could make me unstuck
anyway,

i ended up scrapping the vector idea and i think il be able to finish
i still got some time because he wont collect it till morning cause i doubt he will be in the school till then
regardless
i dont like posting code cause i dont know if asking for help online is really allowed i would hate for him to say i plagiarized cause its the same as "insert forum here"
also im new at this so most of the time my code contains double the code commented out as i try and decide how to do things
until i clean it up after the fact its embarasing and hard to follow

im also learn by example kind of person
which forums dont tend to like
someone can tell me what code does and i may or may not understand it and probably wont
but if i see code i can modify it and when test time comes its a memorization thing

thanks anyway
and thanks to tetron cause i ended up going with a similar find idea

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.