Jump to content

help generate xml


homer.favenir

Recommended Posts

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>""&#xD;
</zipCode>
  </Record>
</Records>

 

question: in the last element of xml there is an error <zipCode>""&#xD;

how can i fix this?

 

thanks

 

 

Link to comment
Share on other sites

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 ;

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.