create xml in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

Re: create xml in php

Post by bouncer »

i've do what you tell in the above thread with no progress. :(

regards
User avatar
hannnndy
Forum Contributor
Posts: 131
Joined: Sat Jan 12, 2008 2:09 am
Location: Iran>Tehran
Contact:

Re: create xml in php

Post by hannnndy »

have you read the xml using php code ?

do not forget opening with text editors will cause some problems

use this:

Code: Select all

 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
    $doc = new DOMDocument();
    $doc->load($fileUrl);
    $nodeName = $doc->getElementsByTagName(node name");
    $returnValue[0] = $address->item(0)->nodeValue;
    return $returnValue;
?>
 
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

Re: create xml in php

Post by bouncer »

no i'm creating the xml file only.~

Code: Select all

 
<?php
$filename = 'out.xml';
$doc = new DOMDocument('1.0', 'Windows-1252');
$doc->formatOutput = true;
$r = $doc->createElement( "AuditFile" );
$doc->appendChild( $r );
$MasterFiles = $doc->createElement( "MasterFiles" );
 
/* Customer */
$Customer = $doc->createElement( "Customer" );
 
$customerDB = dbase_open('C:\root\ing\inc_mes.dbf', 0) or die (error());
if ( $customerDB ) {
    //$record_numbers = dbase_numrecords( $customerDB );
    $record_numbers = 20;
 
    for ($i = 1; $i <= $record_numbers; $i++) {
        $row = dbase_get_record_with_names($customerDB, $i);
        
        $CustomerID = $doc->createElement( "CustomerID" );
        $CustomerID->appendChild( $doc->createTextNode( $row['CNUM'] ) );
        $Customer->appendChild( $CustomerID );
        
        $CustomerTaxID = $doc->createElement( "CustomerTaxID" );
        $CustomerTaxID->appendChild( $doc->createTextNode( $row['CCON'] ) );
        $Customer->appendChild( $CustomerTaxID );
                
        $CompanyName = $doc->createElement( "CompanyName" );
        $CompanyName->appendChild( $doc->createTextNode( $row['CNOM'] ) );
        $Customer->appendChild( $CompanyName );
    }
}
dbase_close( $customerDB );
$MasterFiles->appendChild( $Customer );
$r->appendChild( $MasterFiles );
$doc->save( $filename );
?>
 
i have a .bat to run this script, and then it generates the out.xml file
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

Re: create xml in php

Post by bouncer »

i manage to solve my problems, thanks to you and the other. :wink:
i create a new file using the script in the thread above, and then i edit the generated xml file, with notepad, and save it as UTF-8 and that works like you said :D . but one more question, my final one, do i have to do the same process every time i create a xml file with that script, there's no other way to solve this issue, maybe using another function instead of DOMDocument->save () ?

thanks in advance
User avatar
hannnndy
Forum Contributor
Posts: 131
Joined: Sat Jan 12, 2008 2:09 am
Location: Iran>Tehran
Contact:

Re: create xml in php

Post by hannnndy »

i did not use anything else maybe the som guys in forum do :)
User avatar
hannnndy
Forum Contributor
Posts: 131
Joined: Sat Jan 12, 2008 2:09 am
Location: Iran>Tehran
Contact:

Re: create xml in php

Post by hannnndy »

i did not use anything else maybe the some guys in forum do :)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: create xml in php

Post by Chris Corbyn »

Code: Select all

$doc = new DOMDocument('1.0', 'Windows-1252');
Shouldn't this be:

Code: Select all

$doc = new DOMDocument('1.0', 'UTF-8');
?
Post Reply