Aug 21, 2014 at 3:32am UTC
hello I am trying to read this xml file
this readFile function does not give me right values. Only to use cstring..no pointers or other libs such as xml libs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
void readFile(char file[], ifstream& read){
char line[chr_len];
read.open(file, ios::in);
if (read.fail())
cout<<"Sorry could not read" ;
else {
while (read.good()){
read.getline(line, '\n' );
cout<<line<<endl;
}
}
read.close();
}
here is my file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
<?xml version=”1.0”?>
<address_book>
<contact>
<name>Hoo Zheng Qi</name>
<street>10 Jalan SS15</street>
<city>Subang Jaya</city>
<state>Selangor</state>
<postcode>41500</postcode>
</contact>
<contact>
<name>Lai Yik Sheng</name>
<street>9 Jalan Sentosa 2</street>
<city>Shah Alam</city>
<state>Selangor</state>
<postcode>47400</postcode>
</contact>
<contact>
<name>Sanjeet Singh</name>
<street>5 Penang Road</street>
<city>Georgetown</city>
<state>Pulau Pinang</state>
<postcode>32800</postcode>
</contact>
<contact>
<name>Jeremiah Htet Thu Htwe</name>
<street>98 Lorong Gugusan Alam</street>
<city>Petaling Jaya</city>
<state>Selangor</state>
<postcode>48000</postcode>
</contact>
</address_book>
Also how can i only read the values..not the tags?
Last edited on Aug 21, 2014 at 3:32am UTC
Aug 21, 2014 at 5:26am UTC
i m not supposed to used xml libraries
Aug 21, 2014 at 9:22am UTC
So "<?xml ver" is all that is printed? Is chr_len big enough?
Note that XML files does not necessary have one tag per line. Newlines are just another whitespace character, like space and tab.
Aug 21, 2014 at 10:12am UTC
yes chr size is 30..also how to ignore the tags..only values I want to read in struct
Last edited on Aug 21, 2014 at 10:14am UTC
Aug 21, 2014 at 4:39pm UTC
I need to write function which take chracter city name and displays the contacts living in that city..how should I do this? do i write all records in a struct first? or do i do this while reading from file?
Aug 22, 2014 at 12:13am UTC
Pls tell me what to do in taglessline function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
void readFile(char file[], fstream& read){
char line[1000];
char word;
read.open(file);
unsigned short int i=0;
if (read.fail())
cout<<"Sorry could not read" ;
else {
//read.ignore(41);
while (read.good()){
read.getline(line,1000);
cout<<line<<endl;
//taglessLine(line);
}
}
read.close();
}
void taglessLine(char line[]){
int len=strlen(line);
char tagl[30];
for (int i=0; i<len;i++){
}
}
Last edited on Aug 22, 2014 at 4:01am UTC