homer.favenir Posted April 29, 2009 Share Posted April 29, 2009 hi, can anyone please help i have a scrip and its working <?php echo "<pre>"; $myFile = "Y-GSPR09.ref"; //$myFile = fopen($myFile, 'r') or die("can't open file"); //generate xml $dom = new DomDocument('1.0'); $records = $dom->appendChild($dom->createElement('Records')); $myFile = file($myFile); foreach($myFile as $lines){ $count = 0; $columns = explode(",",$lines); $countColumns = count($columns); echo $columns[18]; echo "<br>"; echo "-----"; echo "<br>"; $record = $records->appendChild($dom->createElement('Record')); //add <Records> element to <Record> $listingType = $record->appendChild($dom->createElement('listingType')); $BusinessName = $record->appendChild($dom->createElement('BusinessName')); $SortName = $record->appendChild($dom->createElement('SortName')); $null1 = $record->appendChild($dom->createElement('null')); $null2 = $record->appendChild($dom->createElement('null')); $null3 = $record->appendChild($dom->createElement('null')); $Address = $record->appendChild($dom->createElement('Address')); $City = $record->appendChild($dom->createElement('City')); $State = $record->appendChild($dom->createElement('State')); $AreaCode = $record->appendChild($dom->createElement('AreaCode')); $Phone = $record->appendChild($dom->createElement('Phone')); $InfoText = $record->appendChild($dom->createElement('InfoText')); $IndentLevel = $record->appendChild($dom->createElement('IndentLevel')); $HeadingNumber = $record->appendChild($dom->createElement('HeadingNumber')); $Udac = $record->appendChild($dom->createElement('Udac')); $UdacRate = $record->appendChild($dom->createElement('UdacRate')); $Page = $record->appendChild($dom->createElement('Page')); $zipCode = $record->appendChild($dom->createElement('zipCode')); //add data to node $listingType->appendChild($dom->createTextNode($columns[$count])); $BusinessName->appendChild($dom->createTextNode($columns[$count+1])); $SortName->appendChild($dom->createTextNode($columns[$count+2])); $null1->appendChild($dom->createTextNode($columns[$count+3])); $null2->appendChild($dom->createTextNode($columns[$count+4])); $null3->appendChild($dom->createTextNode($columns[$count+5])); $Address->appendChild($dom->createTextNode($columns[$count+6])); $City->appendChild($dom->createTextNode($columns[$count+7])); $State->appendChild($dom->createTextNode($columns[$count+8])); $AreaCode->appendChild($dom->createTextNode($columns[$count+9])); $Phone->appendChild($dom->createTextNode($columns[$count+10])); $InfoText->appendChild($dom->createTextNode($columns[$count+11])); $IndentLevel->appendChild($dom->createTextNode($columns[$count+12])); $HeadingNumber->appendChild($dom->createTextNode($columns[$count+13])); $Udac->appendChild($dom->createTextNode($columns[$count+14])); $UdacRate->appendChild($dom->createTextNode($columns[$count+15])); $Page->appendChild($dom->createTextNode($columns[$count+16])); $zipCode->appendChild($dom->createTextNode($columns[$count+17])); //generate xml $dom->formatOutput = true; // set the formatOutput attribute of // domDocument to true // save XML as string or file $test1 = $dom->saveXML(); // put string in test1 $dom->save('ogdenXml.xml'); // save as file } $count++; echo "</pre>"; ?> and the result xml is <?xml version="1.0"?> <Records> <Record> <listingType>"B"</listingType> <BusinessName>"Toledo Womens Center"</BusinessName> <SortName>"TOLEDO WOMENS CENTER"</SortName> <null>""</null> <null>""</null> <null>""</null> <Address>"1160 W Sylvania Av"</Address> <City>"Toledo"</City> <State>""</State> <AreaCode>""</AreaCode> <Phone>""</Phone> <InfoText>""</InfoText> <IndentLevel>""</IndentLevel> <HeadingNumber>"000240"</HeadingNumber> <Udac>"BL"</Udac> <UdacRate>"210.00"</UdacRate> <Page>"1"</Page> <zipCode>""
 </zipCode> </Record> </Records> question: in the last element of xml there is an error <zipCode>""
 how can i fix this? thanks Quote Link to comment Share on other sites More sharing options...
timt Posted April 30, 2009 Share Posted April 30, 2009 The is a carriage return character expressed in html hex which was picked up at the end of the line you read. It marks the end of the line. Search for it and strip it off. Quote Link to comment Share on other sites More sharing options...
timt Posted April 30, 2009 Share Posted April 30, 2009 OOPS. The code was eaten by this browser. The code starts with &#x which means here comes a character in hex, the value is D (or 13 decimal) which is carrage return and it ends with ; Quote Link to comment Share on other sites More sharing options...
homer.favenir Posted April 30, 2009 Author Share Posted April 30, 2009 how can i search it? the should be </zipCode> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.